1 8 9 package com.sleepycat.collections; 10 11 import java.util.Comparator ; 12 import java.util.SortedMap ; 13 14 import com.sleepycat.bind.EntityBinding; 15 import com.sleepycat.bind.EntryBinding; 16 import com.sleepycat.je.Database; 17 import com.sleepycat.je.OperationStatus; 18 19 33 public class StoredSortedMap extends StoredMap implements SortedMap { 34 35 55 public StoredSortedMap(Database database, EntryBinding keyBinding, 56 EntryBinding valueBinding, boolean writeAllowed) { 57 58 super(new DataView(database, keyBinding, valueBinding, null, 59 writeAllowed, null)); 60 } 61 62 83 public StoredSortedMap(Database database, EntryBinding keyBinding, 84 EntryBinding valueBinding, 85 PrimaryKeyAssigner keyAssigner) { 86 87 super(new DataView(database, keyBinding, valueBinding, null, 88 true, keyAssigner)); 89 } 90 91 111 public StoredSortedMap(Database database, EntryBinding keyBinding, 112 EntityBinding valueEntityBinding, 113 boolean writeAllowed) { 114 115 super(new DataView(database, keyBinding, null, valueEntityBinding, 116 writeAllowed, null)); 117 } 118 119 140 public StoredSortedMap(Database database, EntryBinding keyBinding, 141 EntityBinding valueEntityBinding, 142 PrimaryKeyAssigner keyAssigner) { 143 144 super(new DataView(database, keyBinding, null, valueEntityBinding, 145 true, keyAssigner)); 146 } 147 148 StoredSortedMap(DataView mapView) { 149 150 super(mapView); 151 } 152 153 162 public Comparator comparator() { 163 164 return null; 165 } 166 167 176 public Object firstKey() { 177 178 return getFirstOrLastKey(true); 179 } 180 181 190 public Object lastKey() { 191 192 return getFirstOrLastKey(false); 193 } 194 195 private Object getFirstOrLastKey(boolean doGetFirst) { 196 197 DataCursor cursor = null; 198 try { 199 cursor = new DataCursor(view, false); 200 OperationStatus status; 201 if (doGetFirst) { 202 status = cursor.getFirst(false); 203 } else { 204 status = cursor.getLast(false); 205 } 206 return (status == OperationStatus.SUCCESS) ? 207 cursor.getCurrentKey() : null; 208 } catch (Exception e) { 209 throw StoredContainer.convertException(e); 210 } finally { 211 closeCursor(cursor); 212 } 213 } 214 215 230 public SortedMap headMap(Object toKey) { 231 232 return subMap(null, false, toKey, false); 233 } 234 235 252 public SortedMap headMap(Object toKey, boolean toInclusive) { 253 254 return subMap(null, false, toKey, toInclusive); 255 } 256 257 272 public SortedMap tailMap(Object fromKey) { 273 274 return subMap(fromKey, true, null, false); 275 } 276 277 294 public SortedMap tailMap(Object fromKey, boolean fromInclusive) { 295 296 return subMap(fromKey, fromInclusive, null, false); 297 } 298 299 316 public SortedMap subMap(Object fromKey, Object toKey) { 317 318 return subMap(fromKey, true, toKey, false); 319 } 320 321 343 public SortedMap subMap(Object fromKey, boolean fromInclusive, 344 Object toKey, boolean toInclusive) { 345 346 try { 347 return new StoredSortedMap( 348 view.subView(fromKey, fromInclusive, toKey, toInclusive, null)); 349 } catch (Exception e) { 350 throw StoredContainer.convertException(e); 351 } 352 } 353 } 354 | Popular Tags |