List of usage examples for com.google.common.base Optional equals
@Override public abstract boolean equals(@Nullable Object object);
From source file:com.google.devtools.build.xcode.util.Equaling.java
public static <T> boolean of(Optional<T> a, Optional<T> b) { checkNotNull(b);/*from ww w. java 2s . c om*/ return a.equals(b); }
From source file:org.opendaylight.controller.netconf.impl.SubtreeFilter.java
/** * Shallow compare src node to filter: tag name and namespace must match. * If filter node has no children and has text content, it also must match. */// w w w. j a va 2 s . co m private static MatchingResult matches(XmlElement src, XmlElement filter) throws NetconfDocumentedException { boolean tagMatch = src.getName().equals(filter.getName()) && src.getNamespaceOptionally().equals(filter.getNamespaceOptionally()); MatchingResult result = null; if (tagMatch) { // match text content Optional<String> maybeText = filter.getOnlyTextContentOptionally(); if (maybeText.isPresent()) { if (maybeText.equals(src.getOnlyTextContentOptionally()) || prefixedContentMatches(filter, src)) { result = MatchingResult.CONTENT_MATCH; } else { result = MatchingResult.CONTENT_MISMATCH; } } // match attributes, combination of content and tag is not supported if (result == null) { for (Attr attr : filter.getAttributes().values()) { // ignore namespace declarations if (XmlUtil.XMLNS_URI.equals(attr.getNamespaceURI()) == false) { // find attr with matching localName(), namespaceURI(), == value() in src String found = src.getAttribute(attr.getLocalName(), attr.getNamespaceURI()); if (attr.getValue().equals(found) && result != MatchingResult.NO_MATCH) { result = MatchingResult.TAG_MATCH; } else { result = MatchingResult.NO_MATCH; } } } } if (result == null) { result = MatchingResult.TAG_MATCH; } } if (result == null) { result = MatchingResult.NO_MATCH; } LOG.debug("Matching {} to {} resulted in {}", src, filter, result); return result; }
From source file:org.opendaylight.netconf.impl.SubtreeFilter.java
/** * Shallow compare src node to filter: tag name and namespace must match. * If filter node has no children and has text content, it also must match. *///from www . j a v a 2 s . c o m private static MatchingResult matches(XmlElement src, XmlElement filter) throws DocumentedException { boolean tagMatch = src.getName().equals(filter.getName()) && src.getNamespaceOptionally().equals(filter.getNamespaceOptionally()); MatchingResult result = null; if (tagMatch) { // match text content Optional<String> maybeText = filter.getOnlyTextContentOptionally(); if (maybeText.isPresent()) { if (maybeText.equals(src.getOnlyTextContentOptionally()) || prefixedContentMatches(filter, src)) { result = MatchingResult.CONTENT_MATCH; } else { result = MatchingResult.CONTENT_MISMATCH; } } // match attributes, combination of content and tag is not supported if (result == null) { for (Attr attr : filter.getAttributes().values()) { // ignore namespace declarations if (XmlUtil.XMLNS_URI.equals(attr.getNamespaceURI()) == false) { // find attr with matching localName(), namespaceURI(), == value() in src String found = src.getAttribute(attr.getLocalName(), attr.getNamespaceURI()); if (attr.getValue().equals(found) && result != MatchingResult.NO_MATCH) { result = MatchingResult.TAG_MATCH; } else { result = MatchingResult.NO_MATCH; } } } } if (result == null) { result = MatchingResult.TAG_MATCH; } } if (result == null) { result = MatchingResult.NO_MATCH; } LOG.debug("Matching {} to {} resulted in {}", src, filter, result); return result; }
From source file:org.sosy_lab.cpachecker.cpa.value.symbolic.util.SymbolicValues.java
/** * Returns whether the given constraints represent the same C code (string wise). * This is the case if two constraints are completely equal after replacing symbolic expressions * with the program variables they represent. * * <p>Example: <code>s1 < 5</code> is equal to <code>s2 + 2 < 5</code> in respect to its meaning * with <code>s1</code> and <code>s2</code> being symbolic identifiers, if both constraints * represent <code>a < 5</code> with <code>a</code> being a program variable.</p> * * @param pValue1 the first symbolic value * @param pValue2 the second symbolic value * @return <code>true</code> if both symbolic values represent the same C code *//*from w w w . j av a2 s. com*/ public static boolean representSameCCodeExpression(final SymbolicValue pValue1, final SymbolicValue pValue2) { if (!pValue1.getClass().equals(pValue2.getClass())) { final Optional<MemoryLocation> val1RepLoc = pValue1.getRepresentedLocation(); final Optional<MemoryLocation> val2RepLoc = pValue2.getRepresentedLocation(); return (val1RepLoc.isPresent() || val2RepLoc.isPresent()) && val1RepLoc.equals(val2RepLoc); } final Optional<MemoryLocation> maybeRepLocVal1 = pValue1.getRepresentedLocation(); final Optional<MemoryLocation> maybeRepLocVal2 = pValue2.getRepresentedLocation(); if (maybeRepLocVal1.isPresent() || maybeRepLocVal2.isPresent()) { return maybeRepLocVal1.equals(maybeRepLocVal2); } assert maybeRepLocVal1.equals(maybeRepLocVal2); if (pValue1 instanceof SymbolicIdentifier || pValue1 instanceof ConstantSymbolicExpression) { assert pValue2 instanceof SymbolicIdentifier || pValue2 instanceof ConstantSymbolicExpression; return maybeRepLocVal1.equals(maybeRepLocVal2); } else if (pValue1 instanceof UnarySymbolicExpression) { assert pValue2 instanceof UnarySymbolicExpression; final SymbolicValue val1Op = ((UnarySymbolicExpression) pValue1).getOperand(); final SymbolicValue val2Op = ((UnarySymbolicExpression) pValue2).getOperand(); return representSameCCodeExpression(val1Op, val2Op); } else if (pValue1 instanceof BinarySymbolicExpression) { assert pValue2 instanceof BinarySymbolicExpression; final SymbolicValue val1Op1 = ((BinarySymbolicExpression) pValue1).getOperand1(); final SymbolicValue val1Op2 = ((BinarySymbolicExpression) pValue1).getOperand2(); final SymbolicValue val2Op1 = ((BinarySymbolicExpression) pValue2).getOperand1(); final SymbolicValue val2Op2 = ((BinarySymbolicExpression) pValue2).getOperand2(); return representSameCCodeExpression(val1Op1, val2Op1) && representSameCCodeExpression(val1Op2, val2Op2); } else { throw new AssertionError("Unhandled symbolic value type " + pValue1.getClass()); } }
From source file:org.locationtech.geogig.api.plumbing.diff.DefaultGeometryDiffImpl.java
public boolean canBeAppliedOn(Optional<Geometry> obj) { return obj.equals(oldGeom); }
From source file:org.apache.aurora.scheduler.storage.db.DbAttributeStore.java
@Timed("attribute_store_save") @Override/*from ww w . jav a2 s.c om*/ public boolean saveHostAttributes(IHostAttributes hostAttributes) { checkNotBlank(hostAttributes.getHost()); checkArgument(hostAttributes.isSetMode()); if (Iterables.any(hostAttributes.getAttributes(), EMPTY_VALUES)) { throw new IllegalArgumentException("Host attributes contains empty values: " + hostAttributes); } Optional<IHostAttributes> existing = getHostAttributes(hostAttributes.getHost()); if (existing.equals(Optional.of(hostAttributes))) { return false; } else if (existing.isPresent()) { mapper.updateHostModeAndSlaveId(hostAttributes.getHost(), hostAttributes.getMode(), hostAttributes.getSlaveId()); } else { mapper.insert(hostAttributes); } mapper.deleteAttributeValues(hostAttributes.getHost()); if (!hostAttributes.getAttributes().isEmpty()) { mapper.insertAttributeValues(hostAttributes); } return true; }
From source file:org.geogit.api.plumbing.merge.MergeFeaturesOp.java
private Feature merge(RevFeature featureA, RevFeature featureB, RevFeature ancestor, RevFeatureType featureType) {/*from w ww . j a v a 2 s . c o m*/ SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) featureType.type()); ImmutableList<Optional<Object>> valuesA = featureA.getValues(); ImmutableList<Optional<Object>> valuesB = featureB.getValues(); ImmutableList<Optional<Object>> valuesAncestor = ancestor.getValues(); ImmutableList<PropertyDescriptor> descriptors = featureType.sortedDescriptors(); for (int i = 0; i < descriptors.size(); i++) { Name name = descriptors.get(i).getName(); Optional<Object> valueAncestor = valuesAncestor.get(i); Optional<Object> valueA = valuesA.get(i); if (!valueA.equals(valueAncestor)) { featureBuilder.set(name, valueA.orNull()); } else { Optional<Object> valueB = valuesB.get(i); if (!valueB.equals(valueAncestor)) { featureBuilder.set(name, valueB.orNull()); } else { featureBuilder.set(name, valueAncestor.orNull()); } } } return featureBuilder.buildFeature(nodeRefA.name()); }
From source file:org.geogit.api.plumbing.diff.GenericAttributeDiffImpl.java
@Override public boolean canBeAppliedOn(Optional<?> obj) { if (obj == null) { return oldValue == null; }//from ww w .j a va2 s. c o m return obj.equals(oldValue) || obj.equals(newValue); }
From source file:org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl.java
@Override public boolean canBeAppliedOn(Optional<?> obj) { if (obj == null) { obj = Optional.absent();//from ww w . java 2 s . com } return obj.equals(oldValue) || obj.equals(newValue); }
From source file:com.google.devtools.build.android.xml.PublicXmlResourceValue.java
@Override public XmlResourceValue combineWith(XmlResourceValue value) { if (!(value instanceof PublicXmlResourceValue)) { throw new IllegalArgumentException(value + "is not combinable with " + this); }// w w w . ja v a2 s . com PublicXmlResourceValue other = (PublicXmlResourceValue) value; Map<ResourceType, Optional<Integer>> combined = new EnumMap<>(ResourceType.class); combined.putAll(typeToId); for (Entry<ResourceType, Optional<Integer>> entry : other.typeToId.entrySet()) { Optional<Integer> existing = combined.get(entry.getKey()); if (existing != null && !existing.equals(entry.getValue())) { throw new IllegalArgumentException( String.format("Public resource of type %s assigned two different id values 0x%x and 0x%x", entry.getKey(), existing.orNull(), entry.getValue().orNull())); } combined.put(entry.getKey(), entry.getValue()); } return of(combined); }