Java Code Examples for com.google.common.base.Equivalence#equivalent()

The following examples show how to use com.google.common.base.Equivalence#equivalent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static <K, V> void doDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right, Equivalence<? super V> valueEquivalence, Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, MapDifference.ValueDifference<V>> differences) {
  for (Entry<? extends K, ? extends V> entry : left.entrySet()) {
    K leftKey = entry.getKey();
    V leftValue = entry.getValue();
    if (right.containsKey(leftKey)) {
      V rightValue = onlyOnRight.remove(leftKey);
      if (valueEquivalence.equivalent(leftValue, rightValue)) {
        onBoth.put(leftKey, leftValue);
      } else {
        differences.put(leftKey, ValueDifferenceImpl.create(leftValue, rightValue));
      }
    } else {
      onlyOnLeft.put(leftKey, leftValue);
    }
  }
}
 
Example 2
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static <K, V> void doDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right, Equivalence<? super V> valueEquivalence, Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, MapDifference.ValueDifference<V>> differences) {
  for (Entry<? extends K, ? extends V> entry : left.entrySet()) {
    K leftKey = entry.getKey();
    V leftValue = entry.getValue();
    if (right.containsKey(leftKey)) {
      V rightValue = onlyOnRight.remove(leftKey);
      if (valueEquivalence.equivalent(leftValue, rightValue)) {
        onBoth.put(leftKey, leftValue);
      } else {
        differences.put(leftKey, ValueDifferenceImpl.create(leftValue, rightValue));
      }
    } else {
      onlyOnLeft.put(leftKey, leftValue);
    }
  }
}
 
Example 3
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static <K, V> void doDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right, Equivalence<? super V> valueEquivalence, Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, MapDifference.ValueDifference<V>> differences) {
  for (Entry<? extends K, ? extends V> entry : left.entrySet()) {
    K leftKey = entry.getKey();
    V leftValue = entry.getValue();
    if (right.containsKey(leftKey)) {
      V rightValue = onlyOnRight.remove(leftKey);
      if (valueEquivalence.equivalent(leftValue, rightValue)) {
        onBoth.put(leftKey, leftValue);
      } else {
        differences.put(leftKey, ValueDifferenceImpl.create(leftValue, rightValue));
      }
    } else {
      onlyOnLeft.put(leftKey, leftValue);
    }
  }
}
 
Example 4
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static <K, V> void doDifference(Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right, Equivalence<? super V> valueEquivalence, Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, MapDifference.ValueDifference<V>> differences) {
  for (Entry<? extends K, ? extends V> entry : left.entrySet()) {
    K leftKey = entry.getKey();
    V leftValue = entry.getValue();
    if (right.containsKey(leftKey)) {
      V rightValue = onlyOnRight.remove(leftKey);
      if (valueEquivalence.equivalent(leftValue, rightValue)) {
        onBoth.put(leftKey, leftValue);
      } else {
        differences.put(leftKey, ValueDifferenceImpl.create(leftValue, rightValue));
      }
    } else {
      onlyOnLeft.put(leftKey, leftValue);
    }
  }
}
 
Example 5
Source File: Maps.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static <K, V> void doDifference(
    Map<? extends K, ? extends V> left,
    Map<? extends K, ? extends V> right,
    Equivalence<? super V> valueEquivalence,
    Map<K, V> onlyOnLeft,
    Map<K, V> onlyOnRight,
    Map<K, V> onBoth,
    Map<K, MapDifference.ValueDifference<V>> differences) {
  for (Entry<? extends K, ? extends V> entry : left.entrySet()) {
    K leftKey = entry.getKey();
    V leftValue = entry.getValue();
    if (right.containsKey(leftKey)) {
      V rightValue = onlyOnRight.remove(leftKey);
      if (valueEquivalence.equivalent(leftValue, rightValue)) {
        onBoth.put(leftKey, leftValue);
      } else {
        differences.put(leftKey, ValueDifferenceImpl.create(leftValue, rightValue));
      }
    } else {
      onlyOnLeft.put(leftKey, leftValue);
    }
  }
}
 
Example 6
Source File: VariablePredicate.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean predicateBindingsEquivalent(VariablePredicate 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)
    );
}
 
Example 7
Source File: AttributeAtom.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean isBaseEquivalent(Object obj, Equivalence<Atomic> equivalence){
    if (obj == null || this.getClass() != obj.getClass()) return false;
    if (obj == this) return true;
    AttributeAtom that = (AttributeAtom) obj;
    return equivalence.equivalent(this.attributeIsa(), that.attributeIsa())
            && equivalence.equivalent(this.ownerIsa(), that.ownerIsa());
}