/** * Returns a supplier which caches the instance retrieved during the first * call to {@code get()} and returns that value on subsequent calls to * {@code get()}. See: * <a href="http://en.wikipedia.org/wiki/Memoization">memoization</a> * * <p>The returned supplier is thread-safe. The delegate's {@code get()} * method will be invoked at most once. The supplier's serialized form does * not contain the cached value, which will be recalculated when {@code get()} * is called on the reserialized instance. * * <p>If {@code delegate} is an instance created by an earlier call to {@code * memoize}, it is returned directly. */ public static <T> Supplier<T> memoize(Supplier<T> delegate) { return (delegate instanceof MemoizingSupplier) ? delegate : new MemoizingSupplier<T>(checkNotNull(delegate)); }
Preconditions.checkNotNull(ip); if (ip instanceof Inet4Address) { Preconditions.checkArgument(ip instanceof Inet6Address); byte[] bytes = ip.getAddress(); int[] hextets = new int[IPV6_PART_COUNT];
public ConcurrentLongHashSet(int expectedItems, final int numSections) { checkArgument(numSections > 0); if (expectedItems < numSections) { expectedItems = numSections; } int perSectionExpectedItems = expectedItems / numSections; int perSectionCapacity = (int) (perSectionExpectedItems / SetFillFactor); this.sections = new Section[numSections]; for (int i = 0; i < numSections; i++) { sections[i] = new Section(perSectionCapacity); } }
public ConcurrentLongHashMap(int expectedItems, int numSections) { checkArgument(numSections > 0); if (expectedItems < numSections) { expectedItems = numSections; } int perSectionExpectedItems = expectedItems / numSections; int perSectionCapacity = (int) (perSectionExpectedItems / MapFillFactor); this.sections = (Section<V>[]) new Section[numSections]; for (int i = 0; i < numSections; i++) { sections[i] = new Section<>(perSectionCapacity); } }
public boolean remove(long key, Object value) { checkNotNull(value); long h = hash(key); return getSection(h).remove(key, value, (int) h) != null; }
Preconditions.checkNotNull(ip); if (ip instanceof Inet4Address) { Preconditions.checkArgument(ip instanceof Inet6Address); byte[] bytes = ip.getAddress(); int[] hextets = new int[IPV6_PART_COUNT];
/** * Returns an {@link Inet4Address}, given a byte array representation of the IPv4 address. * * @param bytes byte array representing an IPv4 address (should be of length 4) * @return {@link Inet4Address} corresponding to the supplied byte array * @throws IllegalArgumentException if a valid {@link Inet4Address} can not be created */ private static Inet4Address getInet4Address(byte[] bytes) { Preconditions.checkArgument(bytes.length == 4, "Byte array has invalid length for an IPv4 address: %s != 4.", bytes.length); // Given a 4-byte array, this cast should always succeed. return (Inet4Address) bytesToInetAddress(bytes); }
public V putIfAbsent(long key, V value) { checkNotNull(value); long h = hash(key); return getSection(h).put(key, value, (int) h, true, null); }
Preconditions.checkNotNull(ip); if (ip instanceof Inet4Address) { Preconditions.checkArgument(ip instanceof Inet6Address); byte[] bytes = ip.getAddress(); int[] hextets = new int[IPV6_PART_COUNT];
/** * Returns the IPv4 address embedded in an IPv4 compatible address. * * @param ip {@link Inet6Address} to be examined for an embedded IPv4 address * @return {@link Inet4Address} of the embedded IPv4 address * @throws IllegalArgumentException if the argument is not a valid IPv4 compatible address */ public static Inet4Address getCompatIPv4Address(Inet6Address ip) { Preconditions.checkArgument(isCompatIPv4Address(ip), "Address '%s' is not IPv4-compatible.", toAddrString(ip)); return getInet4Address(Arrays.copyOfRange(ip.getAddress(), 12, 16)); }
public V put(long key, V value) { checkNotNull(value); long h = hash(key); return getSection(h).put(key, value, (int) h, false, null); }
Preconditions.checkNotNull(ip); if (ip instanceof Inet4Address) { Preconditions.checkArgument(ip instanceof Inet6Address); byte[] bytes = ip.getAddress(); int[] hextets = new int[IPV6_PART_COUNT];
public ConcurrentLongHashMap(int expectedItems, int numSections) { checkArgument(numSections > 0); if (expectedItems < numSections) { expectedItems = numSections; } int perSectionExpectedItems = expectedItems / numSections; int perSectionCapacity = (int) (perSectionExpectedItems / MapFillFactor); this.sections = (Section<V>[]) new Section[numSections]; for (int i = 0; i < numSections; i++) { sections[i] = new Section<>(perSectionCapacity); } }
public V computeIfAbsent(long key, LongFunction<V> provider) { checkNotNull(provider); long h = hash(key); return getSection(h).put(key, null, (int) h, true, provider); }
Preconditions.checkNotNull(ip); if (ip instanceof Inet4Address) { Preconditions.checkArgument(ip instanceof Inet6Address); byte[] bytes = ip.getAddress(); int[] hextets = new int[IPV6_PART_COUNT];
public ConcurrentLongHashSet(int expectedItems, final int numSections) { checkArgument(numSections > 0); if (expectedItems < numSections) { expectedItems = numSections; } int perSectionExpectedItems = expectedItems / numSections; int perSectionCapacity = (int) (perSectionExpectedItems / SetFillFactor); this.sections = new Section[numSections]; for (int i = 0; i < numSections; i++) { sections[i] = new Section(perSectionCapacity); } }
Preconditions.checkNotNull(hostAddr);
Preconditions.checkNotNull(ip); if (ip instanceof Inet4Address) { Preconditions.checkArgument(ip instanceof Inet6Address); byte[] bytes = ip.getAddress(); int[] hextets = new int[IPV6_PART_COUNT];
public ConcurrentLongHashSet(int expectedItems, final int numSections) { checkArgument(numSections > 0); if (expectedItems < numSections) { expectedItems = numSections; } int perSectionExpectedItems = expectedItems / numSections; int perSectionCapacity = (int) (perSectionExpectedItems / SetFillFactor); this.sections = new Section[numSections]; for (int i = 0; i < numSections; i++) { sections[i] = new Section(perSectionCapacity); } }
public QueuePendingMessageMetrics(final Queue queue) { Preconditions.checkNotNull(queue); this.queue = queue; }