@Test public void testExistsIn() { Element element = createElement(); Element other = anotherElement(); assertTrue(element.existsIn(Arrays.asList(element))); assertFalse(element.existsIn(Arrays.asList(other))); }
public boolean existsIn(Collection<? extends Element> elements) { final List<Field> fields = keyFields(getClass()); if (fields.isEmpty()) { fields.addAll(fields(getClass())); } return elements.stream() .anyMatch(element -> valuesOf(fields).compare(element, this) == 0); }
Element implements Comparable<Element> { public boolean existsIn(Collection<? extends Element> elements) { final List<Field> fields = keyFields(getClass()); if (fields.isEmpty()) { fields.addAll(fields(getClass())); } return elements.stream() .anyMatch(element -> valuesOf(fields).compare(element, this) == 0); } }
Element implements Comparable<Element> { public boolean existsIn(Collection<? extends Element> elements) { final List<Field> fields = keyFields(getClass()); if (fields.isEmpty()) { fields.addAll(fields(getClass())); } return elements.stream() .anyMatch(element -> valuesOf(fields).compare(element, this) == 0); } Element(Element other); }
Element implements Comparable<Element> { public boolean existsIn(Collection<? extends Element> elements) { final List<Field> fields = keyFields(getClass()); if (fields.isEmpty()) { fields.addAll(fields(getClass())); } return elements.stream() .anyMatch(element -> valuesOf(fields).compare(element, this) == 0); } Element(Element other); final String label(); @SuppressWarnings({"PMD.ShortMethodName"}) final Object id(); @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName"}) ElementTo.Element s(String key); void validate(); static void cache(long numberOfElements); @Override boolean equals(Object other); @Override @SneakyThrows int hashCode(); @Override int compareTo(Element that); boolean existsIn(Collection<? extends Element> elements); @SuppressWarnings("unchecked") static final Comparator<Element> valuesOf(List<Field> fields); }
Element implements Comparable<Element> { public boolean existsIn(Collection<? extends Element> elements) { final List<Field> fields = keyFields(getClass()); if (fields.isEmpty()) { fields.addAll(fields(getClass())); } return elements.stream() .anyMatch(element -> valuesOf(fields).compare(element, this) == 0); } Element(Element other); final String label(); @SuppressWarnings({"PMD.ShortMethodName"}) final Object id(); @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName"}) ElementTo.Element s(String key); void validate(); static void cache(long numberOfElements); @Override boolean equals(Object other); @Override @SneakyThrows int hashCode(); @Override int compareTo(Element that); boolean existsIn(Collection<? extends Element> elements); @SuppressWarnings("unchecked") static final Comparator<Element> valuesOf(List<Field> fields); static final long serialVersionUID; final ElementTo.Element withLabel; final ElementTo.Element withId; }