/** * Returns the value of this variable. */ public T get(Channel channel) { if (channel == null) { throw new NullPointerException("channel"); } T value = map.get(channel); if (value == null) { value = initialValue(channel); if (value != null) { T oldValue = setIfAbsent(channel, value); if (oldValue != null) { value = oldValue; } } } return value; }
/** * Removes the variable and returns the removed value. If no value was set, * this method returns the return value of {@link #initialValue(Channel)}, * which is {@code null} by default. * * @return the removed value. * {@linkplain #initialValue(Channel) an initial value} (by default * {@code null}) if no value was set. */ public T remove(Channel channel) { if (channel == null) { throw new NullPointerException("channel"); } T removed = map.remove(channel); if (removed == null) { return initialValue(channel); } else { if (removeOnClose) { channel.getCloseFuture().removeListener(remover); } return removed; } }