/** * check a key and a value for validity (non-null and implements * Comparable) * * @param key the key to be checked * @param value the value to be checked * * @throws NullPointerException if key or value is null * @throws ClassCastException if key or value is not Comparable */ private static void checkKeyAndValue(final Object key, final Object value) { checkKey(key); checkValue(value); }
/** * Checks whether this map contains the a mapping for the specified key. * <p> * The key must implement <code>Comparable</code>. * * @param key key whose presence in this map is to be tested * @return true if this map contains a mapping for the specified key * @throws ClassCastException if the key is of an inappropriate type * @throws NullPointerException if the key is null */ @Override public boolean containsKey(final Object key) { checkKey(key); return lookupKey(key) != null; }
/** * Gets the value to which this map maps the specified key. * Returns null if the map contains no mapping for this key. * <p> * The key must implement <code>Comparable</code>. * * @param key key whose associated value is to be returned * @return the value to which this map maps the specified key, * or null if the map contains no mapping for this key * @throws ClassCastException if the key is of an inappropriate type * @throws NullPointerException if the key is null */ @Override public V get(final Object key) { checkKey(key); final Node<K, V> node = lookupKey(key); return node == null ? null : node.getValue(); }
/** * Gets the next key after the one specified. * <p> * The key must implement <code>Comparable</code>. * * @param key the key to search for next from * @return the next key, null if no match or at end */ @Override public K nextKey(final K key) { checkKey(key); final Node<K, V> node = nextGreater(lookupKey(key), KEY); return node == null ? null : node.getKey(); }
/** * Gets the previous key before the one specified. * <p> * The key must implement <code>Comparable</code>. * * @param key the key to search for previous from * @return the previous key, null if no match or at start */ @Override public K previousKey(final K key) { checkKey(key); final Node<K, V> node = nextSmaller(lookupKey(key), KEY); return node == null ? null : node.getKey(); }