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

📄 basetreesetimpl.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: BaseTreeSetImpl.java,v 1.10.2.1 2004/01/11 20:42:22 per_nyfelt Exp $ * This file is based on TreeSet.java from GNU Classpath. Quote:TreeSet.java -- a class providing a TreeMap-backed SortedSetCopyright (C) 1999, 2000, 2001 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.io.Serializable;import java.util.Collection;import java.util.Comparator;import java.util.Iterator;import java.util.Set;import java.util.SortedMap;import java.util.SortedSet;import java.util.TreeMap;import java.util.TreeSet;/** * This class provides a TreeMap-backed implementation of the SortedSet * interface. The elements will be sorted according to their <i>natural * order</i>, or according to the provided <code>Comparator</code>.<p> * * Most operations are O(log n), but there is so much overhead that this * makes small sets expensive. Note that the ordering must be <i>consistent * with equals</i> to correctly implement the Set interface. If this * condition is violated, the set is still well-behaved, but you may have * suprising results when comparing it to other sets.<p> * * This implementation is not synchronized. If you need to share this between * multiple threads, do something like:<br> * <code>SortedSet s *       = Collections.synchronizedSortedSet(new TreeSet(...));</code><p> * * The iterators are <i>fail-fast</i>, meaning that any structural * modification, except for <code>remove()</code> called on the iterator * itself, cause the iterator to throw a * <code>ConcurrentModificationException</code> rather than exhibit * non-deterministic behavior. * * @author Jon Zeppieri * @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 Collection * @see Set * @see java.util.HashSet * @see java.util.LinkedHashSet * @see Comparable * @see Comparator * @see java.util.Collections#synchronizedSortedSet(SortedSet) * @see TreeMap * @since 1.2 * status updated to 1.4 */// public class TreeSet extends AbstractSet implements SortedSet, Cloneable, Serializablepublic abstract class BaseTreeSetImpl extends AbstractOzoneSet implements BaseTreeSet, Cloneable, Serializable {    private static final long serialVersionUID = 1L;    /**     * The SortedMap which backs this Set.     */    // Not final because of readObject. This will always be one of TreeMap or    // TreeMap.SubMap, which both extend AbstractMap.    protected SortedMap map;    private transient Object ctorParam;    /**     * Construct a new TreeSet whose backing TreeMap using the "natural"     * ordering of keys. Elements that are not mutually comparable will cause     * ClassCastExceptions down the road.     *     * @see Comparable     */    public BaseTreeSetImpl() {        ctorParam = null;    }    /** Basically a hack to prevent creationg of yet another map which backs     * this BaseTreeSet but will be overwritten almost immediately by ctor     * FullTreeSetImpl(SortedMap backingMap, DoNotUse_SeeJavadoc x)     */    protected BaseTreeSetImpl(int ctorWithoutCreatingNewBackingMap) {        // does not match _any_ of the classes in onCreate()        ctorParam = System.out;    }    /**     * Construct a new TreeSet whose backing TreeMap uses the supplied     * Comparator. Elements that are not mutually comparable will cause     * ClassCastExceptions down the road.     *     * @param comparator the Comparator this Set will use     */    public BaseTreeSetImpl(Comparator comparator) {        ctorParam = comparator;    }    /**     * Construct a new TreeSet whose backing TreeMap uses the "natural"     * orering of the keys and which contains all of the elements in the     * supplied Collection. This runs in n*log(n) time.     *     * @param collection the new Set will be initialized with all     *        of the elements in this Collection     * @throws ClassCastException if the elements of the collection are not     *         comparable     * @throws NullPointerException if the collection is null     * @see Comparable     */    public BaseTreeSetImpl(Collection collection) {        ctorParam = collection;    }    /**     * Construct a new TreeSet, using the same key ordering as the supplied     * SortedSet and containing all of the elements in the supplied SortedSet.     * This constructor runs in linear time.     *     * @param sortedSet the new TreeSet will use this SortedSet's comparator     *        and will initialize itself with all its elements     * @throws NullPointerException if sortedSet is null     */    public BaseTreeSetImpl(SortedSet sortedSet) {        ctorParam = sortedSet;    }    public void onCreate() {        if (ctorParam == null) {            map = newBackingMap();        } else if (ctorParam instanceof Comparator) {            map = newBackingMap((Comparator) ctorParam);        } else if (ctorParam instanceof OzoneSortedSet) {            OzoneSortedSet sortedSet = (OzoneSortedSet) ctorParam;            map = newBackingMap(sortedSet.comparator());            Iterator i = sortedSet._org_ozoneDB_internalIterator();            ((BaseTreeMap) map)._org_ozoneDB_putKeysLinear(i, sortedSet.size());        } else if (ctorParam instanceof SortedSet) {            SortedSet sortedSet = (SortedSet) ctorParam;            map = newBackingMap(sortedSet.comparator());            Iterator i = sortedSet.iterator();            ((BaseTreeMap) map)._org_ozoneDB_putKeysLinear(i, sortedSet.size());        } else if (ctorParam instanceof Collection) {            map = newBackingMap();            addAll((Collection) ctorParam);        }                // make sure the key set exists as an ozone object, so that it does        // not have to be created anymore        map.keySet();    }    /**     * Adds the spplied Object to the Set if it is not already in the Set;     * returns true if the element is added, false otherwise.     *     * @param obj the Object to be added to this Set     * @throws ClassCastException if the element cannot be compared with objects     *         already in the set     */    public boolean add(Object obj) {        return map.put(obj, "") == null;    }    /**     * Adds all of the elements in the supplied Collection to this TreeSet.     *     * @param c The collection to add     * @return true if the Set is altered, false otherwise     * @throws NullPointerException if c is null     * @throws ClassCastException if an element in c cannot be compared with     *         objects already in the set     */    public boolean addAll(Collection c) {        boolean result = false;        int pos = c.size();        Iterator itr;        if (c instanceof OzoneCollection) {            itr = ((OzoneCollection) c)._org_ozoneDB_internalIterator();        } else {            itr = c.iterator();        }        while (--pos >= 0) {            result |= (map.put(itr.next(), "") == null);

⌨️ 快捷键说明

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