List of usage examples for com.google.common.base Equivalence equivalent
public final boolean equivalent(@Nullable T a, @Nullable T b)
From source file:org.apache.abdera2.common.misc.Comparisons.java
public static <R> Comparison<R> forEquivalence(final Equivalence<R> r) { return new Comparison<R>() { public boolean apply(R r1, R r2) { return r.equivalent(r1, r2); }/*from w ww.j a va 2 s .c o m*/ }; }
From source file:be.nbb.xdb.DbRawDataUtil.java
@Nonnull @SuppressWarnings("null") public static <C, T extends Throwable> CheckedIterator<Object[], T> distinct( @Nonnull CheckedIterator<Object[], T> rows, @Nonnull List<C> selectColumns, @Nonnull ToIntFunction<C> toIndex, @Nonnull Function<C, SuperDataType> toDataType, @Nonnull BiConsumer<Object[], Object[]> aggregator) throws T { TreeMap<Object[], Object[]> result = Maps.newTreeMap(newRowOrdering(selectColumns, toIndex, toDataType)); Equivalence<Object[]> equivalence = newRowEquivalence(selectColumns, toIndex); Object[] first = null;//from ww w .jav a 2 s.co m while (rows.hasNext()) { Object[] current = rows.next(); // pre-check to avoid using TreeMap#get(Object) if (!equivalence.equivalent(first, current)) { first = result.get(current); if (first == null) { result.put(current, current); first = current; } else { aggregator.accept(first, current); } } else { aggregator.accept(first, current); } } return new SizedCheckedIterator(result.keySet()); }
From source file:org.apache.marmotta.commons.sesame.model.StatementCommons.java
private static <E> Equality<E> equivalenceEquality(final Equivalence<E> equivalence) { return new Equality<E>() { private static final long serialVersionUID = 1L; @Override// w w w .java 2 s . c o m public int hashCodeOf(E object) { return equivalence.hash(object); } @Override public boolean areEqual(E left, E right) { return equivalence.equivalent(left, right); } @Override public int compare(E left, E right) { return equivalence.hash(left) - equivalence.hash(right); } @Override public int hashCode() { return equivalence.hashCode(); } @Override public boolean equals(Object obj) { return obj.hashCode() == hashCode(); } }; }
From source file:com.google.collide.shared.util.JsonCollections.java
/** * Check if two maps are equal. The maps are equal if they have exactly the * same set of keys value pairs. Checks the values using a custom * {@link Equivalence} check./*from www .j av a2 s. c om*/ * * @param equivalence if null {@link Objects#equal(Object, Object)} is used to * verify equivalence. * * @param <T> the data type of the arrays */ public static <T> boolean equals(final JsonStringMap<T> a, final JsonStringMap<T> b, @Nullable Equivalence<T> equivalence) { if (a == b) { // Same map or both null. return true; } else if (a == null || b == null) { // One map is null, the other is not. return false; } else { JsonArray<String> keys = a.getKeys(); if (!equals(keys, b.getKeys())) { return false; } for (int i = 0; i < keys.size(); i++) { String key = keys.get(i); T valueA = a.get(key); T valueB = b.get(key); boolean isNotEquivalent = (equivalence == null && !Objects.equal(valueA, valueB)) || (equivalence != null && !equivalence.equivalent(valueA, valueB)); if (isNotEquivalent) { return false; } } return true; } }
From source file:com.google.collide.shared.util.JsonCollections.java
/** * Check if two lists are equal. The lists are equal if they are both the same * size, and the items at every index are equal according to the provided * equator. Returns true if both lists are null. * * @param equivalence if null the {@link Object#equals(Object)} is used to * determine item equality.//from w w w .j av a 2 s .c o m * * @param <T> the data type of the arrays */ public static <T> boolean equals(JsonArray<T> a, JsonArray<T> b, @Nullable Equivalence<T> equivalence) { if (a == b) { // Same list or both null. return true; } else if (a == null || b == null) { // One list is null, the other is not. return false; } else if (a.size() != b.size()) { // Different sizes. return false; } else { // Check the elements in the array. for (int i = 0; i < a.size(); i++) { T itemA = a.get(i); T itemB = b.get(i); // if the equator is null we just the equals method and some null checking if (equivalence == null && !Objects.equal(itemA, itemB)) { return false; } else if (equivalence != null && !equivalence.equivalent(itemA, itemB)) { return false; } } return true; } }
From source file:org.gradle.api.internal.tasks.properties.AbstractPropertyNode.java
@Nullable protected AbstractPropertyNode<T> findNodeCreatingCycle(T childValue, Equivalence<? super T> nodeEquivalence) { if (nodeEquivalence.equivalent(getNodeValue(), childValue)) { return this; }/* w w w. ja v a 2 s. c o m*/ if (parentNode == null) { return null; } return parentNode.findNodeCreatingCycle(childValue, nodeEquivalence); }
From source file:grakn.core.graql.reasoner.atom.predicate.NeqPredicate.java
private boolean predicateBindingsEquivalent(NeqPredicate that, Equivalence<Atomic> equiv) { IdPredicate thisPredicate = this.getIdPredicate(this.getVarName()); IdPredicate thatPredicate = that.getIdPredicate(that.getVarName()); IdPredicate thisRefPredicate = this.getIdPredicate(this.getPredicate()); IdPredicate thatRefPredicate = that.getIdPredicate(that.getPredicate()); return ((thisPredicate == null) ? thisPredicate == thatPredicate : equiv.equivalent(thisPredicate, thatPredicate)) && ((thisRefPredicate == null) ? (thisRefPredicate == thatRefPredicate) : equiv.equivalent(thisRefPredicate, thatRefPredicate)); }
From source file:org.apache.abdera2.common.date.DateTimes.java
public static final boolean equivalent(DateTime d1, DateTime d2) { return Equivalence.equivalent(d1, d2); }