📄 nodetreesetimpl.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// This file is// Copyright (C) 2002-@year@ Leo Mekenkamp. All rights reserved.// $Id: NodeTreeSetImpl.java,v 1.6 2003/11/20 23:18:41 per_nyfelt Exp $package org.ozoneDB.collections;import java.util.Collection;import java.util.Comparator;import java.util.SortedMap;import java.util.SortedSet;/** * <p>Note that calling <code>iterator()</code> does NOT result in the creation * of an ozone object; this is opposite to behaviour of <code>FullTreeSetImpl</code>.</p> * * @author <a href="mailto:ozoneATmekenkampD0Tcom">Leo Mekenkamp (mind the anti-sp@m)</a> */public class NodeTreeSetImpl extends BaseTreeSetImpl implements NodeTreeSet { private static final long serialVersionUID = 1L; /** * 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 NodeTreeSetImpl() { } /** * 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 NodeTreeSetImpl(Comparator comparator) { super(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 NodeTreeSetImpl(Collection collection) { super(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 NodeTreeSetImpl(SortedSet sortedSet) { super(sortedSet); } /** * This constructor is used to implement the subSet() calls around * a backing TreeMap.SubMap. * * @param backingMap the submap */ NodeTreeSetImpl(SortedMap backingMap) { map = backingMap; } /** * Returns a shallow copy of this Set. The elements are not cloned. * * @return the cloned set */ public Object clone() { BaseTreeSet copy = null; try {// TODO: replace when FakeFactoryGenerator is ready// copy = NodeTreeSetImplFactory.getDefault().create(self()); copy = (BaseTreeSet) database().createObject( NodeTreeSetImpl.class, new Class[] {NodeTreeSetImpl.class}, new Object[] {self()}); } catch (Exception e) { throw new RuntimeException(e); } return copy; } /** * Returns a view of this Set including all elements less than * <code>to</code>. The returned set is backed by the original, so changes * in one appear in the other. The subset will throw an * {@link IllegalArgumentException} for any attempt to access or add an * element beyond the specified cutoff. The returned set does not include * the endpoint; if you want inclusion, pass the successor element. * * @param to the (exclusive) cutoff point * @return a view of the set less than the cutoff * @throws ClassCastException if <code>to</code> is not compatible with * the comparator (or is not Comparable, for natural ordering) * @throws NullPointerException if to is null, but the comparator does not * tolerate null elements */ public SortedSet headSet(Object to) {// TODO: replace when FakeFactoryGenerator is ready// return NodeTreeSetImplFactory.getDefault().create(map.headMap(to)); SortedMap headMap = map.headMap(to); return (NodeTreeSet) database().createObject( NodeTreeSetImpl.class, new Class[] {SortedMap.class}, new Object[] {headMap} ); } /** * Returns a view of this Set including all elements greater or equal to * <code>from</code> and less than <code>to</code> (a half-open interval). * The returned set is backed by the original, so changes in one appear in * the other. The subset will throw an {@link IllegalArgumentException} * for any attempt to access or add an element beyond the specified cutoffs. * The returned set includes the low endpoint but not the high; if you want * to reverse this behavior on either end, pass in the successor element. * * @param from the (inclusive) low cutoff point * @param to the (exclusive) high cutoff point * @return a view of the set between the cutoffs * @throws ClassCastException if either cutoff is not compatible with * the comparator (or is not Comparable, for natural ordering) * @throws NullPointerException if from or to is null, but the comparator * does not tolerate null elements * @throws IllegalArgumentException if from is greater than to */ public SortedSet subSet(Object from, Object to) {// TODO: replace when FakeFactoryGenerator is ready// return NodeTreeSetImplFactory.getDefault().create(map.subMap(from, to)); SortedMap subMap = map.subMap(from, to); return (NodeTreeSet) database().createObject( NodeTreeSetImpl.class, new Class[] {SortedMap.class}, new Object[] {subMap} ); } /** * Returns a view of this Set including all elements greater or equal to * <code>from</code>. The returned set is backed by the original, so * changes in one appear in the other. The subset will throw an * {@link IllegalArgumentException} for any attempt to access or add an * element beyond the specified cutoff. The returned set includes the * endpoint; if you want to exclude it, pass in the successor element. * * @param from the (inclusive) low cutoff point * @return a view of the set above the cutoff * @throws ClassCastException if <code>from</code> is not compatible with * the comparator (or is not Comparable, for natural ordering) * @throws NullPointerException if from is null, but the comparator * does not tolerate null elements */ public SortedSet tailSet(Object from) {// TODO: replace when FakeFactoryGenerator is ready// return NodeTreeSetImplFactory.getDefault().create(map.tailMap(from)); SortedMap tailMap = map.tailMap(from); return (NodeTreeSet) database().createObject( NodeTreeSetImpl.class, new Class[] {SortedMap.class}, new Object[] {tailMap} ); } protected SortedMap newBackingMap() {// TODO: replace when FakeFactoryGenerator is ready// map = NodeTreeMapImplFactory.getDefault.create(); return (NodeTreeMap) database().createObject(NodeTreeMapImpl.class.getName()); } protected SortedMap newBackingMap(Comparator comparator) {// TODO: replace when FakeFactoryGenerator is ready// return NodeTreeMapImplFactory.getDefault.create(comparator); return (NodeTreeMap) database().createObject(NodeTreeMapImpl.class.getName(), Comparator.class.getName(), new Object[] {comparator}); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -