List of usage examples for java.lang Object hashCode
@HotSpotIntrinsicCandidate public native int hashCode();
From source file:org.largecollections.CacheSet.java
public boolean contains(Object key) { if (bloomFilter.mightContain(key.hashCode())) { List<K> vals = getListByHashCode(key.hashCode()); if (vals != null && vals.size() > 0) { for (Object v : vals) { if (v.equals(key)) { return true; }/*from w w w .j a va2s. co m*/ } } else { return false; } } return false; }
From source file:CompactHashMap.java
private final int findKeyIndex(Object k) { if (k == null) k = nullObject;/*from w ww.ja va2s . c o m*/ int hash = k.hashCode(); int index = (hash & 0x7FFFFFFF) % keys.length; int offset = 1; // search for the key (continue while !null and !this key) while (keys[index] != null && !(keys[index].hashCode() == hash && keys[index].equals(k))) { index = ((index + offset) & 0x7FFFFFFF) % keys.length; offset = offset * 2 + 1; if (offset == -1) offset = 2; } return index; }
From source file:ObjectIntMap.java
/** * Returns the value that is mapped to a given 'key'. Returns * false if this key has never been mapped. * * @param key mapping key [may not be null] * @param out holder for the found value [must be at least of size 1] * * @return 'true' if this key was mapped to an existing value */// w w w . ja v a 2 s .c o m public boolean get(final Object key, final int[] out) { // index into the corresponding hash bucket: final Entry[] buckets = m_buckets; final int keyHash = key.hashCode(); final int bucketIndex = (keyHash & 0x7FFFFFFF) % buckets.length; // traverse the singly-linked list of entries in the bucket: for (Entry entry = buckets[bucketIndex]; entry != null; entry = entry.m_next) { if ((keyHash == entry.m_key.hashCode()) || entry.m_key.equals(key)) { out[0] = entry.m_value; return true; } } return false; }
From source file:com.jcraft.weirdx.res.XResource.java
public boolean equals(Object o) { //System.out.println("Key: equals "+o); if (o == null) return false; return id == o.hashCode(); }
From source file:com.twelvemonkeys.util.ObjectAbstractTestCase.java
public void testObjectHashCodeEqualsContract() { Object obj1 = makeObject(); if (obj1.equals(obj1)) { assertEquals("[1] When two objects are equal, their hashCodes should be also.", obj1.hashCode(), obj1.hashCode());/*from w w w. ja v a2s . c om*/ } Object obj2 = makeObject(); if (obj1.equals(obj2)) { assertEquals("[2] When two objects are equal, their hashCodes should be also.", obj1.hashCode(), obj2.hashCode()); assertTrue("When obj1.equals(obj2) is true, then obj2.equals(obj1) should also be true", obj2.equals(obj1)); } }
From source file:org.projectforge.framework.xstream.XmlObjectWriter.java
private void registerElement(final Object obj, final Element element) { writtenObjects.put(obj.getClass().getName() + ":" + obj.hashCode(), element); }
From source file:org.largecollections.CacheSet.java
public boolean remove(Object e) { List<K> vals = getListByHashCode(e.hashCode()); if (vals == null) { return false; //nothing to do } else {//from www. j a v a2 s. c o m boolean found = false; for (K v : vals) { if (v.equals(e)) { found = true; break; } } if (found) { vals.remove(e); this.size--; if (vals.size() == 0) { this.db.delete(serdeUtils.serializeKey(e.hashCode())); } else { db.put(serdeUtils.serializeKey(e.hashCode()), serdeUtils.serializeValue(vals)); } } return found; } }
From source file:cloudnet.util.Dumper.java
private static String dumpValue(Object value, DumpContext ctx) { if (value == null) { return "<null>"; }//from ww w . ja va2 s .c o m if (value.getClass().isPrimitive() || value.getClass() == java.lang.Short.class || value.getClass() == java.lang.Long.class || value.getClass() == java.lang.String.class || value.getClass() == java.lang.Integer.class || value.getClass() == java.lang.Float.class || value.getClass() == java.lang.Byte.class || value.getClass() == java.lang.Character.class || value.getClass() == java.lang.Double.class || value.getClass() == java.lang.Boolean.class || value.getClass() == java.util.Date.class || value.getClass().isEnum()) { return value.toString(); } else { Integer visitedIndex = ctx.visited.get(value); if (visitedIndex == null) { ctx.visited.put(value, ctx.callCount); if (ctx.maxDepth == 0 || ctx.callCount < ctx.maxDepth) { return dump(value, ctx); } else { return "<Reached max recursion depth>"; } } else { return "<Previously visited - see hashCode " + value.hashCode() + ">"; } } }
From source file:org.jasig.jpa.CacheKey.java
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; if (hashCode() != obj.hashCode()) return false; CacheKey other = (CacheKey) obj;/* w w w .j av a 2s. c o m*/ if (!Arrays.deepEquals(key, other.key)) return false; if (source == null) { if (other.source != null) return false; } else if (!source.equals(other.source)) return false; return true; }
From source file:org.springjutsu.validation.ValidationEvaluationContext.java
/** * Marks the given bean as having already been validated, * to avoid infinite recursion during recursive sub bean validation. * @param bean the bean to mark validated *///from w w w . j av a 2 s . c o m protected void markValidated(Object bean) { checkedModelHashes.peek().add(bean.hashCode()); }