@Override public V put(K key, V value) { if (backingStore == null) { backingStore = new SmallMap<>(); backingStore.put(key, value); return null; } else { if (backingStore instanceof SmallMap) { V result = backingStore.put(key, value); if (backingStore.size() > cutOff) { transferBackingStore(); } return result; } else { return backingStore.put(key, value); } } }
@Override public V put(K key, V value) { if (backingStore == null) { backingStore = new SmallMap<>(); backingStore.put(key, value); return null; } else { if (backingStore instanceof SmallMap) { V result = backingStore.put(key, value); if (backingStore.size() > cutOff) { transferBackingStore(); } return result; } else { return backingStore.put(key, value); } } }
@Override public V put(K key, V value) { if (backingStore == null) { backingStore = new SmallMap<>(); backingStore.put(key, value); return null; } else { if (backingStore instanceof SmallMap) { V result = backingStore.put(key, value); if (backingStore.size() > cutOff) { transferBackingStore(); } return result; } else { return backingStore.put(key, value); } } }
backingStore = HashMapFactory.make(); } else { backingStore = new SmallMap<>();
backingStore = HashMapFactory.make(); } else { backingStore = new SmallMap<>();
backingStore = HashMapFactory.make(); } else { backingStore = new SmallMap<>();
/** * set up the methodMap mapping */ protected void computeMethodMapIfNeeded() throws InvalidClassFileException { if (methodMap == null) { synchronized (this) { if (methodMap == null) { IMethod[] methods = computeDeclaredMethods(); final Map<Selector, IMethod> tmpMethodMap; if (methods.length > 5) { tmpMethodMap = HashMapFactory.make(methods.length); } else { tmpMethodMap= new SmallMap<>(); } for (IMethod m : methods) { tmpMethodMap.put(m.getReference().getSelector(), m); } methodMap = tmpMethodMap; } } } }
/** * set up the methodMap mapping */ protected void computeMethodMapIfNeeded() throws InvalidClassFileException { if (methodMap == null) { synchronized (this) { if (methodMap == null) { IMethod[] methods = computeDeclaredMethods(); final Map<Selector, IMethod> tmpMethodMap; if (methods.length > 5) { tmpMethodMap = HashMapFactory.make(methods.length); } else { tmpMethodMap= new SmallMap<>(); } for (IMethod m : methods) { tmpMethodMap.put(m.getReference().getSelector(), m); } methodMap = tmpMethodMap; } } } }
@Test public void testSmallMap() { SmallMap<Integer, Integer> M = new SmallMap<>(); Integer I1 = Integer.valueOf(1); Integer I2 = Integer.valueOf(2); Integer I3 = Integer.valueOf(3); M.put(I1, I1); M.put(I2, I2); M.put(I3, I3); Integer I = M.get(Integer.valueOf(2)); Assert.assertTrue(I != null); Assert.assertTrue(I.equals(I2)); I = M.get(Integer.valueOf(4)); Assert.assertTrue(I == null); I = M.put(Integer.valueOf(2), Integer.valueOf(3)); Assert.assertTrue(I.equals(I2)); I = M.get(I2); Assert.assertTrue(I.equals(I3)); }