@Test public void testMatches() { Match<String> m1 = Match.any(); assertTrue(m1.matches(null)); assertTrue(m1.matches("foo")); assertTrue(m1.matches("bar")); Match<String> m2 = Match.ifNull(); assertTrue(m2.matches(null)); assertFalse(m2.matches("foo")); Match<String> m3 = Match.ifValue("foo"); assertFalse(m3.matches(null)); assertFalse(m3.matches("bar")); assertTrue(m3.matches("foo")); }
public boolean matches(T other) { if (matchAny) { return true; } else if (other == null) { return negation ? value != null : value == null; } else { if (value instanceof byte[]) { boolean equal = Arrays.equals((byte[]) value, (byte[]) other); return negation ? !equal : equal; } return negation ? !Objects.equals(value, other) : Objects.equals(value, other); } }
Match { public boolean matches(T other) { if (matchAny) { return true; } else if (other == null) { return negation ? value != null : value == null; } else { if (value instanceof byte[]) { boolean equal = Arrays.equals((byte[]) value, (byte[]) other); return negation ? !equal : equal; } return negation ? !Objects.equals(value, other) : Objects.equals(value, other); } } }
Match { public boolean matches(T other) { if (matchAny) { return true; } else if (other == null) { return negation ? value != null : value == null; } else { if (value instanceof byte[]) { boolean equal = Arrays.equals((byte[]) value, (byte[]) other); return negation ? !equal : equal; } return negation ? !Objects.equals(value, other) : Objects.equals(value, other); } } private  Match(); private  Match(T value, boolean negation); }
Match { public boolean matches(T other) { if (matchAny) { return true; } else if (other == null) { return negation ? value != null : value == null; } else { if (value instanceof byte[]) { boolean equal = Arrays.equals((byte[]) value, (byte[]) other); return negation ? !equal : equal; } return negation ? !Objects.equals(value, other) : Objects.equals(value, other); } } private  Match(); private  Match(T value, boolean negation); static Match<T> any(); static Match<T> ifNull(); static Match<T> ifNotNull(); static Match<T> ifValue(T value); static Match<T> ifNotValue(T value); Match<V> map(Function<T, V> mapper); boolean matches(T other); @Override int hashCode(); @Override boolean equals(Object other); @Override String toString(); }
Match { public boolean matches(T other) { if (matchAny) { return true; } else if (other == null) { return negation ? value != null : value == null; } else { if (value instanceof byte[]) { boolean equal = Arrays.equals((byte[]) value, (byte[]) other); return negation ? !equal : equal; } return negation ? !Objects.equals(value, other) : Objects.equals(value, other); } } private  Match(); private  Match(T value, boolean negation); static Match<T> any(); static Match<T> ifNull(); static Match<T> ifNotNull(); static Match<T> ifValue(T value); static Match<T> ifNotValue(T value); Match<V> map(Function<T, V> mapper); boolean matches(T other); @Override int hashCode(); @Override boolean equals(Object other); @Override String toString(); static final Match ANY; static final Match NULL; static final Match NOT_NULL; }