⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basetreemapimpl.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @return true if the key has a mapping     * @throws ClassCastException if key is not comparable to map elements     * @throws NullPointerException if key is null and the comparator is not     *         tolerant of nulls     */    public boolean containsKey(Object key) {        return !_org_ozoneDB_getNode(key).isNil();    }    /**     * Returns true if the map contains at least one mapping to the given value.     * This requires linear time.     *     * @param value the value to look for     * @return true if the value appears in a mapping     */    public boolean containsValue(Object value) {        BaseTreeMap.Node node = _org_ozoneDB_firstNode();        while (!node.isNil()) {            if (equals(value, node.getValue())) {                return true;            }            node = _org_ozoneDB_successor(node);        }        return false;    }    /**     * Returns a "set view" of this TreeMap's entries. The set is backed by     * the TreeMap, so changes in one show up in the other.  The set supports     * element removal, but not element addition.<p>     *     * Note that the iterators for all three views, from keySet(), entrySet(),     * and values(), traverse the TreeMap in sorted sequence.     *     * @return a set view of the entries     * @see #keySet()     * @see #values()     * @see java.util.Map.Entry     */    public Set entrySet() {        if (entries == null) {            return ((BaseTreeMap) self())._org_ozoneDB_entrySet();        }        return entries;    }    public Set _org_ozoneDB_entrySet() {        if (entries == null) {// TODO: when FakeFactoryGenerator is finished replace with//            entries = BaseTreeMap_entrySetFactory.getDefault().create(self());            entries = (Set) database().createObject(                    _BaseTreeMap_entrySet.class,                    new Class[] {BaseTreeMap.class},                    new Object[] {self()}            );        }        return entries;    }    /**     * Returns the first (lowest) key in the map.     *     * @return the first key     * @throws NoSuchElementException if the map is empty     */    public Object firstKey() {        if (root.isNil()) {            throw new NoSuchElementException();        }        return _org_ozoneDB_firstNode().getKey();    }    /**     * Return the value in this TreeMap associated with the supplied key,     * or <code>null</code> if the key maps to nothing.  NOTE: Since the value     * could also be null, you must use containsKey to see if this key     * actually maps to something.     *     * @param key the key for which to fetch an associated value     * @return what the key maps to, if present     * @throws ClassCastException if key is not comparable to elements in the map     * @throws NullPointerException if key is null but the comparator does not     *         tolerate nulls     * @see #put(Object, Object)     * @see #containsKey(Object)     */    public Object get(Object key) {        // Exploit fact that nil.value == null.        return _org_ozoneDB_getNode(key).getValue();    }    /**     * Returns a view of this Map including all entries with keys less than     * <code>toKey</code>. The returned map is backed by the original, so changes     * in one appear in the other. The submap will throw an     * {@link IllegalArgumentException} for any attempt to access or add an     * element beyond the specified cutoff. The returned map does not include     * the endpoint; if you want inclusion, pass the successor element.     *     * @param toKey the (exclusive) cutoff point     * @return a view of the map less than the cutoff     * @throws ClassCastException if <code>toKey</code> is not compatible with     *         the comparator (or is not Comparable, for natural ordering)     * @throws NullPointerException if toKey is null, but the comparator does not     *         tolerate null elements     */    public SortedMap headMap(Object toKey) {// TODO: replace when FakeFactoryGenerator is ready//      BaseTreeMapImpl_SubMapFactory.getDefault.create(self(), nil, toKey);        return (SortedMap) database().createObject(                _BaseTreeMap_SubMapImpl.class,                new Class[] {BaseTreeMap.class, Object.class, Object.class},                new Object[] {self(), nilNode, toKey}        );    }    /**     * Returns a "set view" of this TreeMap's keys. The set is backed by the     * TreeMap, so changes in one show up in the other.  The set supports     * element removal, but not element addition.     *     * @return a set view of the keys     * @see #values()     * @see #entrySet()     */    public Set keySet() {        if (keys == null) {            // need to do this via a proxy, cause keySet() is not an update            // method, but _org_ozoneDB_keySet() is            return ((BaseTreeMap) self())._org_ozoneDB_keySet();        }        return keys;    }    public Set _org_ozoneDB_keySet() {        if (keys == null) {// TODO: replace when FakeFactoryGenerator is ready//        BaseTreeMapImpl_SubMapFactory.getDefault.create(self(), nil, toKey);            keys = (Set) database().createObject(                    _BaseTreeMap_keySet.class,                    new Class[] {BaseTreeMap.class},                    new Object[] {self()}            );        }        return keys;    }    /**     * Returns the last (highest) key in the map.     *     * @return the last key     * @throws NoSuchElementException if the map is empty     */    public Object lastKey() {        if (root.isNil()) {            throw new NoSuchElementException("empty");        }        return lastNode().getKey();    }    /**     * Puts the supplied value into the Map, mapped by the supplied key.     * The value may be retrieved by any object which <code>equals()</code>     * this key. NOTE: Since the prior value could also be null, you must     * first use containsKey if you want to see if you are replacing the     * key's mapping.     *     * @param key the key used to locate the value     * @param value the value to be stored in the HashMap     * @return the prior mapping of the key, or null if there was none     * @throws ClassCastException if key is not comparable to current map keys     * @throws NullPointerException if key is null, but the comparator does     *         not tolerate nulls     * @see #get(Object)     * @see Object#equals(Object)     */    public Object put(Object key, Object value) {        BaseTreeMap.Node current = root;        BaseTreeMap.Node parent = nilNode;        int comparison = 0;        // Find new node's parent.        while (!current.isNil()) {            parent = current;            comparison = _org_ozoneDB_compare(key, current.getKey());            if (comparison > 0) {                current = current.getRight();            } else if (comparison < 0) {                current = current.getLeft();            } else {// Key already in tree.                return current.setValue(value);            }        }        // Set up new node.        BaseTreeMap.Node n = newNode(key, value, BaseTreeMap.Node.RED);        n.setParent(parent);        // Insert node in tree.        modCount++;        size++;        if (parent.isNil()) {            // Special case inserting into an empty tree.            root = n;            return null;        }        if (comparison > 0) {            parent.setRight(n);        } else {            parent.setLeft(n);        }        // Rebalance after insert.        insertFixup(n);        return null;    }    /**     * Copies all elements of the given map into this hashtable.  If this table     * already has a mapping for a key, the new mapping replaces the current     * one.     *     * @param m the map to be hashed into this     * @throws ClassCastException if a key in m is not comparable with keys     *         in the map     * @throws NullPointerException if a key in m is null, and the comparator     *         does not tolerate nulls     */    public void putAll(Map m) {        Iterator itr = m.entrySet().iterator();        int pos = m.size();        while (--pos >= 0) {            Map.Entry e = (Map.Entry) itr.next();            put(e.getKey(), e.getValue());        }    }    /**     * Removes from the TreeMap and returns the value which is mapped by the     * supplied key. If the key maps to nothing, then the TreeMap remains     * unchanged, and <code>null</code> is returned. NOTE: Since the value     * could also be null, you must use containsKey to see if you are     * actually removing a mapping.     *     * @param key the key used to locate the value to remove     * @return whatever the key mapped to, if present     * @throws ClassCastException if key is not comparable to current map keys     * @throws NullPointerException if key is null, but the comparator does     *         not tolerate nulls     */    public Object remove(Object key) {        BaseTreeMap.Node n = _org_ozoneDB_getNode(key);        if (n.isNil()) {            return null;        }        // Note: removeNode can alter the contents of n, so save value now.        Object result = n.getValue();        _org_ozoneDB_removeNode(n);        return result;    }    /**     * Returns the number of key-value mappings currently in this Map.     *     * @return the size     */    public int size() {        return size;    }    /**     * Returns a view of this Map including all entries with keys greater or     * equal to <code>fromKey</code> and less than <code>toKey</code> (a     * half-open interval). The returned map is backed by the original, so     * changes in one appear in the other. The submap will throw an     * {@link IllegalArgumentException} for any attempt to access or add an     * element beyond the specified cutoffs. The returned map includes the low     * endpoint but not the high; if you want to reverse this behavior on     * either end, pass in the successor element.     *     * @param fromKey the (inclusive) low cutoff point     * @param toKey the (exclusive) high cutoff point     * @return a view of the map between the cutoffs     * @throws ClassCastException if either cutoff is not compatible with     *         the comparator (or is not Comparable, for natural ordering)     * @throws NullPointerException if fromKey or toKey is null, but the     *         comparator does not tolerate null elements     * @throws IllegalArgumentException if fromKey is greater than toKey     */    public SortedMap subMap(Object fromKey, Object toKey) {// TODO: replace when FakeFactoryGenerator is ready//        BaseTreeMapImpl_SubMapFactory.getDefault.create(self(), fromKey, toKey);        return (SortedMap) database().createObject(                _BaseTreeMap_SubMapImpl.class,                new Class[] {BaseTreeMap.class, Object.class, Object.class},                new Object[] {self(), fromKey, toKey}        );    }    /**     * Returns a view of this Map including all entries with keys greater or     * equal to <code>fromKey</code>. The returned map is backed by the     * original, so changes in one appear in the other. The submap will throw an     * {@link IllegalArgumentException} for any attempt to access or add an     * element beyond the specified cutoff. The returned map includes the     * endpoint; if you want to exclude it, pass in the successor element.     *     * @param fromKey the (inclusive) low cutoff point     * @return a view of the map above the cutoff     * @throws ClassCastException if <code>fromKey</code> is not compatible with     *         the comparator (or is not Comparable, for natural ordering)     * @throws NullPointerException if fromKey is null, but the comparator     *         does not tolerate null elements     */    public SortedMap tailMap(Object fromKey) {// TODO: replace when FakeFactoryGenerator is ready//        BaseTreeMapImpl_SubMapFactory.getDefault.create(self(), fromKey, nil);        return (SortedMap) database().createObject(                _BaseTreeMap_SubMapImpl.class,                new Class[] {BaseTreeMap.class, Object.class, Object.class},                new Object[] {self(), fromKey, nilNode}        );    }    /**     * Returns a "collection view" (or "bag view") of this TreeMap's values.     * The collection is backed by the TreeMap, so changes in one show up     * in the other.  The collection supports element removal, but not element     * addition.     *     * @return a bag view of the values     * @see #keySet()     * @see #entrySet()     */    public Collection values() {        if (values == null) {            return ((BaseTreeMap) self())._org_ozoneDB_values();        }        return values;    }    public Collection _org_ozoneDB_values() {        if (values == null) {// TODO: replace when FakeFactoryGenerator is ready

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -