@Test public void compareEmpty() { RequestConditionHolder empty = new RequestConditionHolder(null); RequestConditionHolder empty2 = new RequestConditionHolder(null); RequestConditionHolder notEmpty = new RequestConditionHolder(new ParamsRequestCondition("name")); assertEquals(0, empty.compareTo(empty2, this.exchange)); assertEquals(-1, notEmpty.compareTo(empty, this.exchange)); assertEquals(1, empty.compareTo(notEmpty, this.exchange)); }
/** * If one instance is empty, the other "wins". If both instances have * conditions, compare them in the order in which they were provided. */ @Override public int compareTo(CompositeRequestCondition other, ServerWebExchange exchange) { if (isEmpty() && other.isEmpty()) { return 0; } else if (isEmpty()) { return 1; } else if (other.isEmpty()) { return -1; } else { assertNumberOfConditions(other); for (int i = 0; i < getLength(); i++) { int result = this.requestConditions[i].compareTo(other.requestConditions[i], exchange); if (result != 0) { return result; } } return 0; } }
@Test public void compare() { RequestConditionHolder params11 = new RequestConditionHolder(new ParamsRequestCondition("1")); RequestConditionHolder params12 = new RequestConditionHolder(new ParamsRequestCondition("1", "2")); assertEquals(1, params11.compareTo(params12, this.exchange)); assertEquals(-1, params12.compareTo(params11, this.exchange)); }
@Test(expected = ClassCastException.class) public void compareIncompatible() { RequestConditionHolder params = new RequestConditionHolder(new ParamsRequestCondition("name")); RequestConditionHolder headers = new RequestConditionHolder(new HeadersRequestCondition("name")); params.compareTo(headers, this.exchange); }
return result; result = this.customConditionHolder.compareTo(other.customConditionHolder, exchange); if (result != 0) { return result;
/** * If one instance is empty, the other "wins". If both instances have * conditions, compare them in the order in which they were provided. */ @Override public int compareTo(CompositeRequestCondition other, ServerWebExchange exchange) { if (isEmpty() && other.isEmpty()) { return 0; } else if (isEmpty()) { return 1; } else if (other.isEmpty()) { return -1; } else { assertNumberOfConditions(other); for (int i = 0; i < getLength(); i++) { int result = this.requestConditions[i].compareTo(other.requestConditions[i], exchange); if (result != 0) { return result; } } return 0; } }
return result; result = this.customConditionHolder.compareTo(other.customConditionHolder, exchange); if (result != 0) { return result;