@Test public void combineEmpty() { RequestConditionHolder empty = new RequestConditionHolder(null); RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name")); assertSame(empty, empty.combine(empty)); assertSame(notEmpty, notEmpty.combine(empty)); assertSame(notEmpty, empty.combine(notEmpty)); }
/** * If one instance is empty, return the other. * If both instances have conditions, combine the individual conditions * after ensuring they are of the same type and number. */ @Override public CompositeRequestCondition combine(CompositeRequestCondition other) { if (isEmpty() && other.isEmpty()) { return this; } else if (other.isEmpty()) { return this; } else if (isEmpty()) { return other; } else { assertNumberOfConditions(other); RequestConditionHolder[] combinedConditions = new RequestConditionHolder[getLength()]; for (int i = 0; i < getLength(); i++) { combinedConditions[i] = this.requestConditions[i].combine(other.requestConditions[i]); } return new CompositeRequestCondition(combinedConditions); } }
/** * Combines "this" request mapping info (i.e. the current instance) with another request mapping info instance. * <p>Example: combine type- and method-level request mappings. * @return a new request mapping info instance; never {@code null} */ @Override public RequestMappingInfo combine(RequestMappingInfo other) { String name = combineNames(other); PatternsRequestCondition patterns = this.patternsCondition.combine(other.patternsCondition); RequestMethodsRequestCondition methods = this.methodsCondition.combine(other.methodsCondition); ParamsRequestCondition params = this.paramsCondition.combine(other.paramsCondition); HeadersRequestCondition headers = this.headersCondition.combine(other.headersCondition); ConsumesRequestCondition consumes = this.consumesCondition.combine(other.consumesCondition); ProducesRequestCondition produces = this.producesCondition.combine(other.producesCondition); RequestConditionHolder custom = this.customConditionHolder.combine(other.customConditionHolder); return new RequestMappingInfo(name, patterns, methods, params, headers, consumes, produces, custom.getCondition()); }
@Test(expected = ClassCastException.class) public void combineIncompatible() { RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name")); RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name")); params.combine(headers); }
@Test public void combine() { RequestConditionHolder params1 = new RequestConditionHolder(new ParamsRequestCondition("name1")); RequestConditionHolder params2 = new RequestConditionHolder(new ParamsRequestCondition("name2")); RequestConditionHolder expected = new RequestConditionHolder(new ParamsRequestCondition("name1", "name2")); assertEquals(expected, params1.combine(params2)); }
/** * If one instance is empty, return the other. * If both instances have conditions, combine the individual conditions * after ensuring they are of the same type and number. */ @Override public CompositeRequestCondition combine(CompositeRequestCondition other) { if (isEmpty() && other.isEmpty()) { return this; } else if (other.isEmpty()) { return this; } else if (isEmpty()) { return other; } else { assertNumberOfConditions(other); RequestConditionHolder[] combinedConditions = new RequestConditionHolder[getLength()]; for (int i = 0; i < getLength(); i++) { combinedConditions[i] = this.requestConditions[i].combine(other.requestConditions[i]); } return new CompositeRequestCondition(combinedConditions); } }
/** * Combines "this" request mapping info (i.e. the current instance) with another request mapping info instance. * <p>Example: combine type- and method-level request mappings. * @return a new request mapping info instance; never {@code null} */ @Override public RequestMappingInfo combine(RequestMappingInfo other) { String name = combineNames(other); PatternsRequestCondition patterns = this.patternsCondition.combine(other.patternsCondition); RequestMethodsRequestCondition methods = this.methodsCondition.combine(other.methodsCondition); ParamsRequestCondition params = this.paramsCondition.combine(other.paramsCondition); HeadersRequestCondition headers = this.headersCondition.combine(other.headersCondition); ConsumesRequestCondition consumes = this.consumesCondition.combine(other.consumesCondition); ProducesRequestCondition produces = this.producesCondition.combine(other.producesCondition); RequestConditionHolder custom = this.customConditionHolder.combine(other.customConditionHolder); return new RequestMappingInfo(name, patterns, methods, params, headers, consumes, produces, custom.getCondition()); }