Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

StoredSortedMap.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2000-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: StoredSortedMap.java,v 12.2 2005/10/05 20:40:10 mark Exp $
00008  */
00009 
00010 package com.sleepycat.collections;
00011 
00012 import java.util.Comparator;
00013 import java.util.SortedMap;
00014 
00015 import com.sleepycat.bind.EntityBinding;
00016 import com.sleepycat.bind.EntryBinding;
00017 import com.sleepycat.db.Database;
00018 import com.sleepycat.db.OperationStatus;
00019 
00046 public class StoredSortedMap extends StoredMap implements SortedMap {
00047 
00068     public StoredSortedMap(Database database, EntryBinding keyBinding,
00069                            EntryBinding valueBinding, boolean writeAllowed) {
00070 
00071         super(new DataView(database, keyBinding, valueBinding, null,
00072                            writeAllowed, null));
00073     }
00074 
00096     public StoredSortedMap(Database database, EntryBinding keyBinding,
00097                            EntryBinding valueBinding,
00098                            PrimaryKeyAssigner keyAssigner) {
00099 
00100         super(new DataView(database, keyBinding, valueBinding, null,
00101                            true, keyAssigner));
00102     }
00103 
00124     public StoredSortedMap(Database database, EntryBinding keyBinding,
00125                            EntityBinding valueEntityBinding,
00126                            boolean writeAllowed) {
00127 
00128         super(new DataView(database, keyBinding, null, valueEntityBinding,
00129                            writeAllowed, null));
00130     }
00131 
00153     public StoredSortedMap(Database database, EntryBinding keyBinding,
00154                            EntityBinding valueEntityBinding, 
00155                            PrimaryKeyAssigner keyAssigner) {
00156 
00157         super(new DataView(database, keyBinding, null, valueEntityBinding,
00158                            true, keyAssigner));
00159     }
00160 
00161     StoredSortedMap(DataView mapView) {
00162 
00163         super(mapView);
00164     }
00165 
00175     public Comparator comparator() {
00176 
00177         return null;
00178     }
00179 
00189     public Object firstKey() {
00190 
00191         return getFirstOrLastKey(true);
00192     }
00193 
00203     public Object lastKey() {
00204 
00205         return getFirstOrLastKey(false);
00206     }
00207 
00208     private Object getFirstOrLastKey(boolean doGetFirst) {
00209 
00210         DataCursor cursor = null;
00211         try {
00212             cursor = new DataCursor(view, false);
00213             OperationStatus status;
00214             if (doGetFirst) {
00215                 status = cursor.getFirst(false);
00216             } else {
00217                 status = cursor.getLast(false);
00218             }
00219             return (status == OperationStatus.SUCCESS) ?
00220                     cursor.getCurrentKey() : null;
00221         } catch (Exception e) {
00222             throw StoredContainer.convertException(e);
00223         } finally {
00224             closeCursor(cursor);
00225         }
00226     }
00227 
00243     public SortedMap headMap(Object toKey) {
00244 
00245         return subMap(null, false, toKey, false);
00246     }
00247 
00265     public SortedMap headMap(Object toKey, boolean toInclusive) {
00266 
00267         return subMap(null, false, toKey, toInclusive);
00268     }
00269 
00285     public SortedMap tailMap(Object fromKey) {
00286 
00287         return subMap(fromKey, true, null, false);
00288     }
00289 
00307     public SortedMap tailMap(Object fromKey, boolean fromInclusive) {
00308 
00309         return subMap(fromKey, fromInclusive, null, false);
00310     }
00311 
00329     public SortedMap subMap(Object fromKey, Object toKey) {
00330 
00331         return subMap(fromKey, true, toKey, false);
00332     }
00333 
00356     public SortedMap subMap(Object fromKey, boolean fromInclusive,
00357                             Object toKey, boolean toInclusive) {
00358 
00359         try {
00360             return new StoredSortedMap(
00361                view.subView(fromKey, fromInclusive, toKey, toInclusive, null));
00362         } catch (Exception e) {
00363             throw StoredContainer.convertException(e);
00364         }
00365     }
00366 }

Generated on Sun Dec 25 12:14:31 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2