/** * Tests if the specified object is a key in this table. * * @param key possible key * @return {@code true} if and only if the specified object * is a key in this table, as determined by the * {@code equals} method; {@code false} otherwise * @throws NullPointerException if the specified key is null */ public boolean containsKey(Object key) { return get(key) != null; }
/** * Returns the value to which the specified key is mapped, or the * given default value if this map contains no mapping for the * key. * * @param key the key whose associated value is to be returned * @param defaultValue the value to return if this map contains * no mapping for the given key * @return the mapping for the key, if present; else the default value * @throws NullPointerException if the specified key is null */ public V getOrDefault(Object key, V defaultValue) { V v; return (v = get(key)) == null ? defaultValue : v; }
public boolean contains(Object o) { Object k, v, r; Map.Entry<?,?> e; return ((o instanceof Map.Entry) && (k = (e = (Map.Entry<?,?>)o).getKey()) != null && (r = map.get(k)) != null && (v = e.getValue()) != null && (v == r || v.equals(r))); }
private boolean isTTLExpired(Channel channel, long now) { if (maxConnectionTTLDisabled) return false; ChannelCreation creation = channelId2Creation.get(channel.getId()); return creation != null && now - creation.creationTime >= maxConnectionTTL; }
@Override public void flushPartition(Object partitionKey) { flushPartition(partitionKey, partitions.get(partitionKey)); }
public Channel poll(Object partitionKey) { IdleChannel idleChannel = null; ConcurrentLinkedQueue<IdleChannel> partition = partitions.get(partitionKey); if (partition != null) { while (idleChannel == null) { idleChannel = partition.poll(); if (idleChannel == null) // pool is empty break; else if (!Channels.isChannelValid(idleChannel.channel)) { idleChannel = null; LOGGER.trace("Channel not connected or not opened, probably remotely closed!"); } } } return idleChannel != null ? idleChannel.channel : null; }
@Override public boolean removeAll(Channel channel) { ChannelCreation creation = channelId2Creation.remove(channel.getId()); return !isClosed.get() && creation != null && partitions.get(creation.partitionKey).remove(channel); }
@Override public boolean remove(Object o) { boolean removed = super.remove(o); if (removed) { if (maxTotalConnectionsEnabled) freeChannels.release(); if (maxConnectionsPerHostEnabled) { Object partitionKey = channelId2PartitionKey.remove(Channel.class.cast(o).getId()); if (partitionKey != null) { Semaphore freeChannelsForHost = freeChannelsPerHost.get(partitionKey); if (freeChannelsForHost != null) freeChannelsForHost.release(); } } } return removed; } };
if ((mk = e.getKey()) == null || (mv = e.getValue()) == null || (v = get(mk)) == null || (mv != v && !mv.equals(v))) return false;
public void replaceAll(BiFun<? super K, ? super V, ? extends V> function) { if (function == null) throw new NullPointerException(); Node<K,V>[] t; if ((t = table) != null) { Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length); for (Node<K,V> p; (p = it.advance()) != null; ) { V oldValue = p.val; for (K key = p.key;;) { V newValue = function.apply(key, oldValue); if (newValue == null) throw new NullPointerException(); if (replaceNode(key, newValue, oldValue) != null || (oldValue = get(key)) == null) break; } } } }
if (LOGGER.isDebugEnabled()) { for (Object key : partitions.keySet()) { LOGGER.debug("Entry count for : {} : {}", key, partitions.get(key).size());