org.infinispan.commons.util.Util.safeEquals()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中org.infinispan.commons.util.Util.safeEquals()方法的一些代码示例,展示了Util.safeEquals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.safeEquals()方法的具体详情如下:
包路径:org.infinispan.commons.util.Util
类名称:Util
方法名:safeEquals

Util.safeEquals介绍

[英]Null-safe equality test.
[中]

代码示例

代码示例来源:origin: org.infinispan/infinispan-tree

/**
* Returns true if obj is a Fqn with the same elements.
*/
@Override
public boolean equals(Object obj) {
 if (this == obj) {
   return true;
 }
 if (!(obj instanceof Fqn)) {
   return false;
 }
 Fqn other = (Fqn) obj;
 if (elements.length != other.elements.length) return false;
 for (int i = elements.length - 1; i >= 0; i--) {
   if (!Util.safeEquals(elements[i], other.elements[i])) return false;
 }
 return true;
}

代码示例来源:origin: org.infinispan/infinispan-tree

/**
* Returns true if this Fqn is equals or the child of parentFqn. Example usage:
* <pre>
* Fqn<String> f1 = Fqn.fromString("/a/b");
* Fqn<String> f2 = Fqn.fromString("/a/b/c");
* assertTrue(f1.isChildOrEquals(f2));
* assertTrue(f1.isChildOrEquals(f1));
* assertFalse(f2.isChildOrEquals(f1));
* </pre>
*
* @param parentFqn candidate parent to test against
* @return true if this Fqn is equals or the child of parentFqn.
*/
public boolean isChildOrEquals(Fqn parentFqn) {
 Object[] parentEl = parentFqn.elements;
 if (parentEl.length > elements.length) {
   return false;
 }
 for (int i = parentEl.length - 1; i >= 0; i--) {
   if (!Util.safeEquals(parentEl[i], elements[i])) return false;
 }
 return true;
}

代码示例来源:origin: org.infinispan/infinispan-tree

public boolean equals(Object o) {
 if (this == o) return true;
 if (o == null || getClass() != o.getClass()) return false;
 NodeKey key = (NodeKey) o;
 if (contents != key.contents) return false;
 if (!Util.safeEquals(fqn, key.fqn)) return false;
 return true;
}

代码示例来源:origin: org.infinispan/infinispan-tree

private boolean replace(AdvancedCache<?, ?> cache, K key, V oldValue, V newValue) {
 startAtomic();
 try {
   AtomicMap<K, V> data = getDataInternal(cache);
   V old = data.get(key);
   if (Util.safeEquals(oldValue, old)) {
    data.put(key, newValue);
    return true;
   }
   return false;
 }
 finally {
   endAtomic();
 }
}

代码示例来源:origin: org.infinispan/infinispan-adaptor52x

private void assertCacheEntry(Cache cache, String key, String value, long lifespanMillis, long maxIdleMillis) {
 DataContainer dc = cache.getAdvancedCache().getDataContainer();
 InternalCacheEntry ice = dc.get(key);
 assert ice != null : "No such entry for key " + key;
 assert Util.safeEquals(ice.getValue(), value) : ice.getValue() + " is not the same as " + value;
 assert ice.getLifespan() == lifespanMillis : "Lifespan " + ice.getLifespan() + " not the same as " + lifespanMillis;
 assert ice.getMaxIdle() == maxIdleMillis : "MaxIdle " + ice.getMaxIdle() + " not the same as " + maxIdleMillis;
 if (lifespanMillis > -1) assert ice.getCreated() > -1 : "Lifespan is set but created time is not";
 if (maxIdleMillis > -1) assert ice.getLastUsed() > -1 : "Max idle is set but last used is not";
}

相关文章