/** * Equivalent to <code>removeOverflow(false)</code>. */ protected void removeOverflow() { removeOverflow(false); }
/** * @param size the maximum size of this map. If additional elements are * put into the map, overflow will be removed via calls to * {@link #overflowRemoved}. * @param load the load factor for the underlying map * @param concurrencyLevel the concurrency level for the underlying map * * @see ConcurrentHashMap */ public SizedConcurrentHashMap(int size, float load, int concurrencyLevel) { super(size, load, concurrencyLevel); setMaxSize(size); }
public boolean isFull() { return size() >= maxSize; }
/** * Removes overflow. If <code>forPut</code> is <code>true</code>, then * this uses <code>size() + 1</code> when computing size. */ protected void removeOverflow(boolean forPut) { int sizeToCompareTo = forPut ? maxSize - 1 : maxSize; while (size() > sizeToCompareTo) { Entry entry = removeRandom(); // if removeRandom() returns null, break out of the loop. Of course, // since we're not locking, the size might not actually be null // when we do this. But this prevents weird race conditions from // putting this thread into more loops. if (entry == null) break; overflowRemoved(entry.getKey(), entry.getValue()); } }
/** * Removes overflow. If <code>forPut</code> is <code>true</code>, then * this uses <code>size() + 1</code> when computing size. */ protected void removeOverflow(boolean forPut) { int sizeToCompareTo = forPut ? maxSize - 1 : maxSize; while (size() > sizeToCompareTo) { Entry entry = removeRandom(); // if removeRandom() returns null, break out of the loop. Of course, // since we're not locking, the size might not actually be null // when we do this. But this prevents weird race conditions from // putting this thread into more loops. if (entry == null) break; overflowRemoved(entry.getKey(), entry.getValue()); } }
/** * Equivalent to <code>removeOverflow(false)</code>. */ protected void removeOverflow() { removeOverflow(false); }
/** * @param size the maximum size of this map. If additional elements are * put into the map, overflow will be removed via calls to * {@link #overflowRemoved}. * @param load the load factor for the underlying map * @param concurrencyLevel the concurrency level for the underlying map * * @see ConcurrentHashMap */ public SizedConcurrentHashMap(int size, float load, int concurrencyLevel) { super(size, load, concurrencyLevel); setMaxSize(size); }
public boolean isFull() { return size() >= maxSize; }
public void setMaxSize(int max) { if (max < 0) throw new IllegalArgumentException(String.valueOf(max)); maxSize = max; removeOverflow(false); }
public void setMaxSize(int max) { if (max < 0) throw new IllegalArgumentException(String.valueOf(max)); maxSize = max; removeOverflow(false); }
@Override public Object put(Object key, Object value) { if (maxSize != Integer.MAX_VALUE) removeOverflow(true); return super.put(key, value); }
@Override public Object put(Object key, Object value) { if (maxSize != Integer.MAX_VALUE) removeOverflow(true); return super.put(key, value); }
@Override public Object putIfAbsent(Object key, Object value) { if (maxSize != Integer.MAX_VALUE) removeOverflow(true); return super.putIfAbsent(key, value); }
@Override public Object putIfAbsent(Object key, Object value) { if (maxSize != Integer.MAX_VALUE) removeOverflow(true); return super.putIfAbsent(key, value); }