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

📄 abstractozonemap.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * imply that the mapping was created.     *     * @param key the key to map     * @param value the value to be mapped     * @return the previous value of the key, or null if there was no mapping     * @throws UnsupportedOperationException if the operation is not supported     * @throws ClassCastException if the key or value is of the wrong type     * @throws IllegalArgumentException if something about this key or value     *         prevents it from existing in this map     * @throws NullPointerException if the map forbids null keys or values     * @see #containsKey(Object)     */    public Object put(Object key, Object value) {        throw new UnsupportedOperationException();    }    /**     * Copies all entries of the given map to this one (optional operation). If     * the map already contains a key, its value is replaced. This implementation     * simply iterates over the map's entrySet(), calling <code>put</code>,     * so it is not supported if puts are not.     *     * @param m the mapping to load into this map     * @throws UnsupportedOperationException if the operation is not supported     * @throws ClassCastException if a key or value is of the wrong type     * @throws IllegalArgumentException if something about a key or value     *         prevents it from existing in this map     * @throws NullPointerException if the map forbids null keys or values, or     *         if <code>m</code> is null.     * @see #put(Object, Object)     */    public void putAll(Map m) {        Iterator entries;        if (m instanceof OzoneMap) {            entries = ((OzoneSet) entrySet())._org_ozoneDB_internalIterator();        } else {            entries = m.entrySet().iterator();        }        int pos = m.size();        while (--pos >= 0) {            Map.Entry entry = (Map.Entry) entries.next();            put(entry.getKey(), entry.getValue());        }    }    /**     * Removes the mapping for this key if present (optional operation). This     * implementation iterates over the entrySet searching for a matching     * key, at which point it calls the iterator's <code>remove</code> method.     * It returns the result of <code>getValue()</code> on the entry, if found,     * or null if no entry is found. Note that maps which permit null values     * may also return null if the key was removed.  If the entrySet does not     * support removal, this will also fail. This is O(n), so many     * implementations override it for efficiency.     *     * @param key the key to remove     * @return the value the key mapped to, or null if not present     * @throws UnsupportedOperationException if deletion is unsupported     * @see Iterator#remove()     */    public Object remove(Object key) {        Iterator entries = ((OzoneSet) entrySet())._org_ozoneDB_internalIterator();        int pos = size();        while (--pos >= 0) {            Map.Entry entry = (Map.Entry) entries.next();            if (equals(key, entry.getKey())) {                // Must get the value before we remove it from iterator.                Object r = entry.getValue();                entries.remove();                return r;            }        }        return null;    }    /**     * Returns the number of key-value mappings in the map. If there are more     * than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE. This is     * implemented as <code>entrySet().size()</code>.     *     * @return the number of mappings     * @see Set#size()     */    public int size() {        return entrySet().size();    }    /**     * Returns a String representation of this map. This is a listing of the     * map entries (which are specified in Map.Entry as being     * <code>getKey() + "=" + getValue()</code>), separated by a comma and     * space (", "), and surrounded by braces ('{' and '}'). This implementation     * uses a StringBuffer and iterates over the entrySet to build the String.     * Note that this can fail with an exception if underlying keys or     * values complete abruptly in toString().     *     * @return a String representation     * @see java.util.Map.Entry     * @see Object#toString()     */    public String toString() {        Iterator entries = ((OzoneSet) entrySet())._org_ozoneDB_internalIterator();        StringBuffer r = new StringBuffer("{");        for (int pos = size(); pos > 0; pos--) {            Map.Entry entry = (Map.Entry) entries.next();            r.append(entry.getKey());            r.append('=');            r.append(entry.getValue());            if (pos > 1)                r.append(", ");        }        r.append("}");        return r.toString();    }    /**     * Returns a collection or bag view of this map's values. The collection     * is backed by the map, so changes in one show up in the other.     * Modifications while an iteration is in progress produce undefined     * behavior. The collection supports removal if entrySet() does, but     * does not support element addition.     * <p>     *     * This implementation creates an AbstractCollection, where the iterator     * wraps the entrySet iterator, size defers to the Map's size, and contains     * defers to the Map's containsValue. The collection is created on first     * use, and returned on subsequent uses, although since no synchronization     * occurs, there is a slight possibility of creating two collections.     *     * @return a Collection view of the values     * @see Collection#iterator()     * @see #size()     * @see #containsValue(Object)     * @see #keySet()     */    public Collection values() {        if (values == null) {// code moved to AbstractOzoneMap_KeySetImpl.java and AbstractOzoneMap_KeySetImpl_IteratorImpl.java// TODO: when FakeFactoryGenerator is finished replace with//            keys = AbstractDbSetImplFactory.getDefault.create(self());            values = (Collection) database().createObject(                    _AbstractOzoneMap_values.class,                    new Class[] {OzoneMap.class},                    new Object[] {self()}            );        }        return values;    }    /**     * Compare two objects according to Collection semantics.     *     * @param o1 the first object     * @param o2 the second object     * @return o1 == null ? o2 == null : o2 == null ? false : o1.equals(o2);     */    // Package visible for use throughout java.util.    // It may be inlined since it is final.    static final boolean equals(Object o1, Object o2) {        return o1 == null ? o2 == null : o2 == null ? false : o1.equals(o2);    }    /**     * Hash an object according to Collection semantics.     *     * @param o the object to hash     * @return o1 == null ? 0 : o1.hashCode()     */    // Package visible for use throughout java.util.    // It may be inlined since it is final.    static final int hashCode(Object o) {        return o == null ? 0 : o.hashCode();    }    public OzoneCollection ozoneValues() {        return (OzoneCollection) values();    }        public OzoneSet ozoneKeySet() {        return (OzoneSet) keySet();    }        public OzoneSet ozoneEntrySet() {        return (OzoneSet) entrySet();    }        interface Node extends OzoneMap.Node {    }    class AbstractNode implements Node {        private Object key;        private Object value;        /**         * Basic constructor initializes the fields.         * @param newKey the key         * @param newValue the value         */        public AbstractNode(Object newKey, Object newValue) {            key = newKey;            value = newValue;        }        /**         * Compares the specified object with this entry. Returns true only if         * the object is a mapping of identical key and value.         *         * @param o the object to compare         *         * @return <code>true</code> if it is equal         */        public final boolean equals(Object o) {            boolean result;            if (! (o instanceof Map.Entry)) {                result = false;            // Optimize for our own entries.            } else if (o instanceof AbstractNode) {                AbstractNode e = (AbstractNode) o;                result = (AbstractOzoneMap.equals(key, e.key) && AbstractOzoneMap.equals(value, e.value));            } else {                Map.Entry e = (Map.Entry) o;                result = (AbstractOzoneMap.equals(key, e.getKey()) && AbstractOzoneMap.equals(value, e.getValue()));            }            return result;        }        /**         * Get the key corresponding to this entry.         *         * @return the key         */        public final Object getKey() {            return key;        }        /**         * Get the value corresponding to this entry. If you already called         * Iterator.remove(), the behavior undefined, but in this case it works.         *         * @return the value         */        public final Object getValue() {            return value;        }        /**         * Returns the hash code of the entry.  This is defined as the exclusive-or         * of the hashcodes of the key and value (using 0 for null). In other         * words, this must be:         *    <pre>(getKey() == null ? 0 : getKey().hashCode())    ^ (getValue() == null ? 0 : getValue().hashCode())</pre>         *         * @return the hash code         */        public final int hashCode() {            return (AbstractOzoneMap.hashCode(key) ^ AbstractOzoneMap.hashCode(value));        }        /**         * Replaces the value with the specified object. This writes through         * to the map, unless you have already called Iterator.remove(). It         * may be overridden to restrict a null value.         *         * @param newVal the new value to store         * @return the old value         * @throws NullPointerException if the map forbids null values         */        public Object setValue(Object newVal) {            Object r = value;            value = newVal;            return r;        }        /**         * This provides a string representation of the entry. It is of the form         * "key=value", where string concatenation is used on key and value.         *         * @return the string representation         */        public final String toString() {            return key + "=" + value;        }        public void setKey(Object key) {            this.key = key;        }    }}

⌨️ 快捷键说明

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