/** * {@inheritDoc} */ public boolean isEmpty() { return size() == 0; }
/** * {@inheritDoc} */ public void clear() { if (size() > 0) { Arrays.fill(values, MISSING_VALUE); sizeOfArrayValues = 0; containsMissingValue = false; } }
/** * {@inheritDoc} */ public Object[] toArray() { final Object[] arrayCopy = new Object[size()]; copyValues(arrayCopy); return arrayCopy; }
private void clearNotOwnedInodeCacheIfTooLarge() { if(socketInodesNotOwnedByThisProcess.size() >= MAX_NOT_OWNED_INODE_CACHE_SIZE) { socketInodesNotOwnedByThisProcess.clear(); } } }
private void clearNotOwnedInodeCacheIfTooLarge() { if(socketInodesNotOwnedByThisProcess.size() >= MAX_NOT_OWNED_INODE_CACHE_SIZE) { socketInodesNotOwnedByThisProcess.clear(); } } }
private void increaseCapacity() { @DoNotSub final int newCapacity = values.length * 2; if (newCapacity < 0) { throw new IllegalStateException("max capacity reached at size=" + size()); } rehash(newCapacity); }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public <T> T[] toArray(final T[] longo) { final Class<?> componentType = longo.getClass().getComponentType(); if (!componentType.isAssignableFrom(Long.class)) { throw new ArrayStoreException("cannot store Longs in array of type " + componentType); } @DoNotSub final int size = size(); final T[] arrayCopy = longo.length >= size ? longo : (T[])Array.newInstance(componentType, size); copyValues(arrayCopy); return arrayCopy; }
/** * Compact the backing arrays by rehashing with a capacity just larger than current size * and giving consideration to the load factor. */ public void compact() { @DoNotSub final int idealCapacity = (int)Math.round(size() * (1.0 / loadFactor)); rehash(findNextPositivePowerOfTwo(Math.max(DEFAULT_INITIAL_CAPACITY, idealCapacity))); }
/** * Compact the backing arrays by rehashing with a capacity just larger than current size * and giving consideration to the load factor. */ public void compact() { @DoNotSub final int idealCapacity = (int)Math.round(size() * (1.0 / loadFactor)); rehash(BitUtil.findNextPositivePowerOfTwo(idealCapacity)); }
LongIterator reset() { this.remaining = size(); final long[] values = LongHashSet.this.values; @DoNotSub final int length = values.length; @DoNotSub int i = length; if (values[length - 1] != LongHashSet.MISSING_VALUE) { for (i = 0; i < length; i++) { if (values[i] == LongHashSet.MISSING_VALUE) { break; } } } stopCounter = i; positionCounter = i + length; isPositionValid = false; return this; }
if (c.size() != size())
@Test public void shouldFindMultipleSocketInodeValues() throws Exception { try(final DatagramChannel channel1 = DatagramChannel.open().bind(new InetSocketAddress(55555)); final DatagramChannel channel2 = DatagramChannel.open().bind(new InetSocketAddress(44444))) { final LongHashSet target = new LongHashSet(4); retriever.accept(target); assertThat(target.size(), is(atLeast(2))); } }
@Test public void shouldFindSocketInodeValue() throws Exception { try(final DatagramChannel channel = DatagramChannel.open().bind(new InetSocketAddress(55555))) { final LongHashSet target = new LongHashSet(4); retriever.accept(target); assertThat(target.size(), is(atLeast(1))); } }