Skip to content

Commit 92323ac

Browse files
committed
Merge branch 'AssertComparable' into 'master'
CompareCondition#assertComparable reduces code duplication See merge request exedio/cope!1798
2 parents ff8a3e9 + 75dc400 commit 92323ac

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

runtime/src/com/exedio/cope/CompareCondition.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public CompareCondition(
6464
this.left = requireNonNull(left, "left");
6565
this.right = requireNonNull(right, "right");
6666

67+
assertComparable(left, right);
68+
}
69+
70+
static <E> void assertComparable(final Function<E> left, final E right)
71+
{
6772
if(!isComparable(left.getValueClass(), right.getClass(), right))
6873
{
6974
final StringBuilder sb = new StringBuilder();
@@ -78,7 +83,7 @@ public CompareCondition(
7883
}
7984

8085
@SuppressWarnings("RedundantIfStatement")
81-
static boolean isComparable(
86+
private static boolean isComparable(
8287
final Class<?> left,
8388
final Class<?> right,
8489
final Object rightValue)

runtime/src/com/exedio/cope/InCondition.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.exedio.cope;
22

3-
import static com.exedio.cope.CompareCondition.isComparable;
3+
import static com.exedio.cope.CompareCondition.assertComparable;
44
import static com.exedio.cope.CompareCondition.toStringForValue;
55
import static java.util.Objects.requireNonNull;
66

@@ -33,19 +33,7 @@ public final class InCondition<E> extends Condition
3333

3434

3535
for (final E element : allowedValues)
36-
{
37-
if(! isComparable(function.getValueClass(), element.getClass(), element))
38-
{
39-
final StringBuilder sb = new StringBuilder();
40-
sb.append(function).
41-
append(" not comparable to '");
42-
toStringForValue(sb, element, false);
43-
sb.append("' (").
44-
append(element.getClass().getName()).
45-
append(')');
46-
throw new IllegalArgumentException(sb.toString());
47-
}
48-
}
36+
assertComparable(function, element);
4937
}
5038

5139
@Override

0 commit comments

Comments
 (0)