/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2000,2007 Oracle. All rights reserved. * * $Id: StoredSortedValueSet.java,v 12.7 2007/05/04 00:28:25 mark Exp $ */ package com.sleepycat.collections; import java.util.Comparator; import java.util.SortedSet; import com.sleepycat.bind.EntityBinding; import com.sleepycat.db.Database; /** * The SortedSet returned by Map.values() and which can also be constructed * directly if a Map is not needed. * Although this collection is a set it may contain duplicate values. Only if * an entity value binding is used are all elements guaranteed to be unique. * *
In addition to the standard SortedSet methods, this class provides the * following methods for stored sorted value sets only. Note that the use of * these methods is not compatible with the standard Java collections * interface.
*Note that the return value is a StoredCollection and must be treated * as such; for example, its iterators must be explicitly closed.
* * @param toValue the upper bound. * * @return the subset. * * @throws RuntimeExceptionWrapper if a {@link * com.sleepycat.db.DatabaseException} is thrown. */ public SortedSet headSet(Object toValue) { return subSet(null, false, toValue, false); } /** * Returns a view of the portion of this sorted set whose elements are * strictly less than toValue, optionally including toValue. * This method does not exist in the standard {@link SortedSet} interface. * *Note that the return value is a StoredCollection and must be treated * as such; for example, its iterators must be explicitly closed.
* * @param toValue is the upper bound. * * @param toInclusive is true to include toValue. * * @return the subset. * * @throws RuntimeExceptionWrapper if a {@link * com.sleepycat.db.DatabaseException} is thrown. */ public SortedSet headSet(Object toValue, boolean toInclusive) { return subSet(null, false, toValue, toInclusive); } /** * Returns a view of the portion of this sorted set whose elements are * greater than or equal to fromValue. * This method conforms to the {@link SortedSet#tailSet} interface. * *Note that the return value is a StoredCollection and must be treated * as such; for example, its iterators must be explicitly closed.
* * @param fromValue is the lower bound. * * @return the subset. * * @throws RuntimeExceptionWrapper if a {@link * com.sleepycat.db.DatabaseException} is thrown. */ public SortedSet tailSet(Object fromValue) { return subSet(fromValue, true, null, false); } /** * Returns a view of the portion of this sorted set whose elements are * strictly greater than fromValue, optionally including fromValue. * This method does not exist in the standard {@link SortedSet} interface. * *Note that the return value is a StoredCollection and must be treated * as such; for example, its iterators must be explicitly closed.
* * @param fromValue is the lower bound. * * @param fromInclusive is true to include fromValue. * * @return the subset. * * @throws RuntimeExceptionWrapper if a {@link * com.sleepycat.db.DatabaseException} is thrown. */ public SortedSet tailSet(Object fromValue, boolean fromInclusive) { return subSet(fromValue, fromInclusive, null, false); } /** * Returns a view of the portion of this sorted set whose elements range * from fromValue, inclusive, to toValue, exclusive. * This method conforms to the {@link SortedSet#subSet} interface. * *Note that the return value is a StoredCollection and must be treated * as such; for example, its iterators must be explicitly closed.
* * @param fromValue is the lower bound. * * @param toValue is the upper bound. * * @return the subset. * * @throws RuntimeExceptionWrapper if a {@link * com.sleepycat.db.DatabaseException} is thrown. */ public SortedSet subSet(Object fromValue, Object toValue) { return subSet(fromValue, true, toValue, false); } /** * Returns a view of the portion of this sorted set whose elements are * strictly greater than fromValue and strictly less than toValue, * optionally including fromValue and toValue. * This method does not exist in the standard {@link SortedSet} interface. * *Note that the return value is a StoredCollection and must be treated * as such; for example, its iterators must be explicitly closed.
* * @param fromValue is the lower bound. * * @param fromInclusive is true to include fromValue. * * @param toValue is the upper bound. * * @param toInclusive is true to include toValue. * * @return the subset. * * @throws RuntimeExceptionWrapper if a {@link * com.sleepycat.db.DatabaseException} is thrown. */ public SortedSet subSet(Object fromValue, boolean fromInclusive, Object toValue, boolean toInclusive) { try { return new StoredSortedValueSet( view.subView(fromValue, fromInclusive, toValue, toInclusive, null)); } catch (Exception e) { throw StoredContainer.convertException(e); } } }