public <E> Predicate byEntitySelectors( Root<E> root, CriteriaBuilder builder, SearchParameters sp) { List<EntitySelector<?, ?, ?>> selectors = sp.getEntities(); List<Predicate> predicates = newArrayList(); for (EntitySelector<?, ?, ?> s : selectors) { @SuppressWarnings("unchecked") EntitySelector<? super E, ? extends Identifiable<?>, ?> selector = (EntitySelector<? super E, ? extends Identifiable<?>, ?>) s; if (selector.isNotEmpty()) { List<Predicate> selectorPredicates = newArrayList(); for (Identifiable<?> selection : selector.getSelected()) { selectorPredicates.add(builder.equal(getExpression(root, selector), selection.getId())); } if (TRUE == selector.getIncludeNull()) { selectorPredicates.add(builder.or(builder.isNull(getExpression(root, selector)))); } predicates.add(JpaUtil.orPredicate(builder, selectorPredicates)); } else if (selector.isIncludeNullSet()) { if (selector.getIncludeNull()) { predicates.add(builder.isNull(getExpression(root, selector))); } else { predicates.add(builder.isNotNull(getExpression(root, selector))); } } } return JpaUtil.concatPredicate(sp, builder, predicates); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((owner == null) ? 0 : owner.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; Ownership other = (Ownership) obj; if (owner == null) { if (other.owner != null) return false; } else if (!owner.equals(other.owner)) return false; return true; }
@Override public int compareTo(Identifiable i) { if (i instanceof Group) { Group j = (Group) i; if (this.getID().compareTo(j.getID()) < 0) { return -1; } else if (this.getID().compareTo(j.getID()) > 0) { return 1; } else { return 0; } } else { return (this.getID().compareTo(i.getID())); } }
/** * @param identifiables * @return the string representations of the wrapped identifiers */ public static Collection<String> toString( final Collection<? extends Identifiable<?>> identifiables) { final Collection<String> result = new ArrayList<String>(); for (Identifiable<?> identifier : identifiables) result.add(identifier.getID().toString()); return result; }
public static BigInteger calculateDistance(Identifiable x, Identifiable y) { return calculateDistance(x.getIdentifier(), y.getIdentifier()); }