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

📄 abstractozonemap.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * AbstractOzoneMap.java * $Id: AbstractOzoneMap.java,v 1.6.2.1 2004/01/11 20:42:22 per_nyfelt Exp $ * This file is based on AbstractMap.java from GNU Classpath. Quote:AbstractMap.java -- Abstract implementation of most of MapCopyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. * end quote. * * This file is licenced under the same conditions as its original (GPL + * "special exception"). */package org.ozoneDB.collections;import java.util.Collection;import java.util.Iterator;import java.util.Map;import java.util.Set;import org.ozoneDB.OzoneObject;/** * An abstract implementation of Map to make it easier to create your own * implementations. In order to create an unmodifiable Map, subclass * AbstractMap and implement the <code>entrySet</code> (usually via an * AbstractSet).  To make it modifiable, also implement <code>put</code>, * and have <code>entrySet().iterator()</code> support <code>remove</code>. * <p> * * It is recommended that classes which extend this support at least the * no-argument constructor, and a constructor which accepts another Map. * Further methods in this class may be overridden if you have a more * efficient implementation. * * @author Original author unknown * @author Bryce McKinlay * @author Eric Blake <ebb9@email.byu.edu> * @author <a href="mailto:ozoneATmekenkampD0Tcom">Leo Mekenkamp (mind the anti-sp@m)</a> (adaptation for ozone) * @see java.util.AbstractMap */public abstract class AbstractOzoneMap extends OzoneObject implements OzoneMap {    private static final long serialVersionUID = 1L;    /** An "enum" of iterator types. */    // Package visible for use by subclasses.    /** the keys type */    static final int KEYS = 0;    /** the values type */    static final int VALUES = 1;    /** the entries type */    static final int ENTRIES = 2;    /**     * property for {@link #keySet()}.     */    protected Set keys;    /**     * property for {@link #values()}.     */    protected Collection values;    /**     * The main constructor, for use by subclasses.     */    protected AbstractOzoneMap() {    }    /**     * Remove all entries from this Map (optional operation). This default     * implementation calls entrySet().clear(). NOTE: If the entry set does     * not permit clearing, then this will fail, too. Subclasses often     * override this for efficiency.  Your implementation of entrySet() should     * not call <code>AbstractMap.clear</code> unless you want an infinite loop.     *     * @throws UnsupportedOperationException if <code>entrySet().clear()</code>     *         does not support clearing.     * @see Set#clear()     */    public void clear() {        entrySet().clear();    }    /**     * Create a shallow copy of this Map, no keys or values are copied. The     * default implementation simply calls <code>super.clone()</code>.     *     * @return the shallow clone     * @throws CloneNotSupportedException if a subclass is not Cloneable     * @see Cloneable     * @see Object#clone()     */    protected Object clone() throws CloneNotSupportedException {//        AbstractMap copy = (AbstractMap) super.clone();        AbstractOzoneMap copy = (AbstractOzoneMap) super.clone();        // Clear out the caches; they are stale.        copy.keys = null;        copy.values = null;        return copy;    }    /**     * Returns true if this contains a mapping for the given key. This     * implementation does a linear search, O(n), over the     * <code>entrySet()</code>, returning <code>true</code> if a match     * is found, <code>false</code> if the iteration ends. Many subclasses     * can implement this more efficiently.     *     * @param key the key to search for     * @return true if the map contains the key     * @throws NullPointerException if key is <code>null</code> but the map     *         does not permit null keys     * @see #containsValue(Object)     */    public boolean containsKey(Object key) {        Iterator entries = ((OzoneSet) entrySet())._org_ozoneDB_internalIterator();        int pos = size();        while (--pos >= 0)            if (equals(key, ((Map.Entry) entries.next()).getKey()))                return true;        return false;    }    /**     * Returns true if this contains at least one mapping with the given value.     * This implementation does a linear search, O(n), over the     * <code>entrySet()</code>, returning <code>true</code> if a match     * is found, <code>false</code> if the iteration ends. A match is     * defined as <code>(value == null ? v == null : value.equals(v))</code>     * Subclasses are unlikely to implement this more efficiently.     *     * @param value the value to search for     * @return true if the map contains the value     * @see #containsKey(Object)     */    public boolean containsValue(Object value) {        Iterator entries = ((OzoneSet) entrySet())._org_ozoneDB_internalIterator();        int pos = size();        while (--pos >= 0)            if (equals(value, ((Map.Entry) entries.next()).getValue()))                return true;        return false;    }    /**     * Returns a set view of the mappings in this Map.  Each element in the     * set must be an implementation of Map.Entry.  The set is backed by     * the map, so that changes in one show up in the other.  Modifications     * made while an iterator is in progress cause undefined behavior.  If     * the set supports removal, these methods must be valid:     * <code>Iterator.remove</code>, <code>Set.remove</code>,     * <code>removeAll</code>, <code>retainAll</code>, and <code>clear</code>.     * Element addition is not supported via this set.     *     * @return the entry set     * @see java.util.Map.Entry     */    public abstract Set entrySet();    /**     * Compares the specified object with this map for equality. Returns     * <code>true</code> if the other object is a Map with the same mappings,     * that is,<br>     * <code>o instanceof Map && entrySet().equals(((Map) o).entrySet();</code>     *     * @param o the object to be compared     * @return true if the object equals this map     * @see Set#equals(Object)     */    public boolean equals(Object o) {        return super.equals(o) || (o instanceof Map && entrySet().equals(((Map) o).entrySet()));    }    /**     * Returns the value mapped by the given key. Returns <code>null</code> if     * there is no mapping.  However, in Maps that accept null values, you     * must rely on <code>containsKey</code> to determine if a mapping exists.     * This iteration takes linear time, searching entrySet().iterator() of     * the key.  Many implementations override this method.     *     * @param key the key to look up     * @return the value associated with the key, or null if key not in map     * @throws NullPointerException if this map does not accept null keys     * @see #containsKey(Object)     */    public Object get(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()))                return entry.getValue();        }        return null;    }    /**     * Returns the hash code for this map. As defined in Map, this is the sum     * of all hashcodes for each Map.Entry object in entrySet, or basically     * entrySet().hashCode().     *     * @return the hash code     * @see java.util.Map.Entry#hashCode()     * @see Set#hashCode()     */    public int hashCode() {        return entrySet().hashCode();    }    /**     * Returns true if the map contains no mappings. This is implemented by     * <code>size() == 0</code>.     *     * @return true if the map is empty     * @see #size()     */    public boolean isEmpty() {        return size() == 0;    }    /**     * Returns a set view of this map's keys. The set 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 set supports removal     * if entrySet() does, but does not support element addition.     * <p>     *     * This implementation creates an AbstractSet, where the iterator wraps     * the entrySet iterator, size defers to the Map's size, and contains     * defers to the Map's containsKey. The set is created on first use, and     * returned on subsequent uses, although since no synchronization occurs,     * there is a slight possibility of creating two sets.     *     * @return a Set view of the keys     * @see Set#iterator()     * @see #size()     * @see #containsKey(Object)     * @see #values()     */    public Set keySet() {        if (keys == null) {// ozone// code moved to AbstractOzoneMap_KeySetImpl.java and AbstractOzoneMap_KeySetImpl_IteratorImpl.java// TODO: when FakeFactoryGenerator is finished replace with//            keys = AbstractDbSetImplFactory.getDefault.create(self());            keys = (Set) database().createObject(_AbstractOzoneMap_keySet.class,                            new Class[] {OzoneMap.class},                            new Object[] {self()}            );        }// ~ozone        return keys;    }    /**     * Associates the given key to the given value (optional operation). If the     * map already contains the key, its value is replaced. This implementation     * simply throws an UnsupportedOperationException. Be aware that in a map     * that permits <code>null</code> values, a null return does not always

⌨️ 快捷键说明

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