Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2000, 2010 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.collections;
  
 
 /* <!-- begin JE only --> */
 /* <!-- end JE only --> */
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.

Author(s):
Mark Hayes
 
 public class StoredSortedValueSet<E>
     extends StoredValueSet<E>
     implements SortedSet<E> {
 
     /*
      * No valueBinding ctor is possible since key cannot be derived.
      */

    
Creates a sorted value set entity view of a com.sleepycat.je.Database.

Parameters:
database is the Database underlying the new collection.
valueEntityBinding is the binding used to translate between key/value buffers and entity value objects.
writeAllowed is true to create a read-write collection or false to create a read-only collection.
Throws:
java.lang.IllegalArgumentException if formats are not consistently defined or a parameter is invalid.
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
 
     public StoredSortedValueSet(Database database,
                                 EntityBinding<E> valueEntityBinding,
                                 boolean writeAllowed) {
 
         super(new DataView(databasenullnullvalueEntityBinding,
                            writeAllowednull));
         checkKeyDerivation();
     }
 
     StoredSortedValueSet(DataView valueSetView) {
 
         super(valueSetView);
         checkKeyDerivation();
     }
 
     private void checkKeyDerivation() {
 
         if (!.canDeriveKeyFromValue()) {
             throw new IllegalArgumentException("Cannot derive key from value");
         }
     }

    
Returns null since comparators are not supported. The natural ordering of a stored collection is data byte order, whether the data classes implement the java.lang.Comparable interface or not. This method does not conform to the java.util.SortedSet.comparator() interface.

Returns:
null.
 
     public Comparator<? super E> comparator() {
 
         return null;
     }

    
Returns the first (lowest) element currently in this sorted set. This method conforms to the java.util.SortedSet.first() interface.

Returns:
the first element.
Throws:
com.sleepycat.je.OperationFailureException if one of the Read Operation Failures occurs.
com.sleepycat.je.EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
    public E first() {
        return getFirstOrLast(true);
    }

    
Returns the last (highest) element currently in this sorted set. This method conforms to the java.util.SortedSet.last() interface.

Returns:
the last element.
Throws:
com.sleepycat.je.OperationFailureException if one of the Read Operation Failures occurs.
com.sleepycat.je.EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
    public E last() {
        return getFirstOrLast(false);
    }

    
Returns a view of the portion of this sorted set whose elements are strictly less than toValue. This method conforms to the java.util.SortedSet.headSet(java.lang.Object) interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters:
toValue the upper bound.
Returns:
the subset.
Throws:
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
    public SortedSet<E> headSet(E toValue) {
        return subSet(nullfalsetoValuefalse);
    }

    
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 java.util.SortedSet interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters:
toValue is the upper bound.
toInclusive is true to include toValue.
Returns:
the subset.
Throws:
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
    public SortedSet<E> headSet(E toValueboolean toInclusive) {
        return subSet(nullfalsetoValuetoInclusive);
    }

    
Returns a view of the portion of this sorted set whose elements are greater than or equal to fromValue. This method conforms to the java.util.SortedSet.tailSet(java.lang.Object) interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters:
fromValue is the lower bound.
Returns:
the subset.
Throws:
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
    public SortedSet<E> tailSet(E fromValue) {
        return subSet(fromValuetruenullfalse);
    }

    
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 java.util.SortedSet interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters:
fromValue is the lower bound.
fromInclusive is true to include fromValue.
Returns:
the subset.
Throws:
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
    public SortedSet<E> tailSet(E fromValueboolean fromInclusive) {
        return subSet(fromValuefromInclusivenullfalse);
    }

    
Returns a view of the portion of this sorted set whose elements range from fromValue, inclusive, to toValue, exclusive. This method conforms to the java.util.SortedSet.subSet(java.lang.Object,java.lang.Object) interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters:
fromValue is the lower bound.
toValue is the upper bound.
Returns:
the subset.
Throws:
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
    public SortedSet<E> subSet(E fromValue, E toValue) {
        return subSet(fromValuetruetoValuefalse);
    }

    
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 java.util.SortedSet interface.

Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

Parameters:
fromValue is the lower bound.
fromInclusive is true to include fromValue.
toValue is the upper bound.
toInclusive is true to include toValue.
Returns:
the subset.
Throws:
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
    public SortedSet<E> subSet(E fromValue,
                               boolean fromInclusive,
                               E toValue,
                               boolean toInclusive) {
        try {
            return new StoredSortedValueSet<E>(.subView
                (fromValuefromInclusivetoValuetoInclusivenull));
        } catch (Exception e) {
            throw StoredContainer.convertException(e);
        }
    }
New to GrepCode? Check out our FAQ X