00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.sleepycat.collections;
00011
00012 import java.util.Comparator;
00013 import java.util.SortedSet;
00014
00015 import com.sleepycat.bind.EntityBinding;
00016 import com.sleepycat.db.Database;
00017
00047 public class StoredSortedValueSet extends StoredValueSet implements SortedSet {
00048
00049
00050
00051
00052
00070 public StoredSortedValueSet(Database database,
00071 EntityBinding valueEntityBinding,
00072 boolean writeAllowed) {
00073
00074 super(new DataView(database, null, null, valueEntityBinding,
00075 writeAllowed, null));
00076 checkKeyDerivation();
00077 }
00078
00079 StoredSortedValueSet(DataView valueSetView) {
00080
00081 super(valueSetView);
00082 checkKeyDerivation();
00083 }
00084
00085 private void checkKeyDerivation() {
00086
00087 if (!view.canDeriveKeyFromValue()) {
00088 throw new IllegalArgumentException("Cannot derive key from value");
00089 }
00090 }
00091
00101 public Comparator comparator() {
00102
00103 return null;
00104 }
00105
00115 public Object first() {
00116
00117 return getFirstOrLast(true);
00118 }
00119
00129 public Object last() {
00130
00131 return getFirstOrLast(false);
00132 }
00133
00149 public SortedSet headSet(Object toValue) {
00150
00151 return subSet(null, false, toValue, false);
00152 }
00153
00171 public SortedSet headSet(Object toValue, boolean toInclusive) {
00172
00173 return subSet(null, false, toValue, toInclusive);
00174 }
00175
00191 public SortedSet tailSet(Object fromValue) {
00192
00193 return subSet(fromValue, true, null, false);
00194 }
00195
00213 public SortedSet tailSet(Object fromValue, boolean fromInclusive) {
00214
00215 return subSet(fromValue, fromInclusive, null, false);
00216 }
00217
00235 public SortedSet subSet(Object fromValue, Object toValue) {
00236
00237 return subSet(fromValue, true, toValue, false);
00238 }
00239
00262 public SortedSet subSet(Object fromValue, boolean fromInclusive,
00263 Object toValue, boolean toInclusive) {
00264
00265 try {
00266 return new StoredSortedValueSet(
00267 view.subView(fromValue, fromInclusive, toValue, toInclusive,
00268 null));
00269 } catch (Exception e) {
00270 throw StoredContainer.convertException(e);
00271 }
00272 }
00273 }