⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storedmap.java

📁 嵌入式数据库Berkeley DB-4.5.20源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2000-2006 *      Oracle Corporation.  All rights reserved. * * $Id: StoredMap.java,v 12.7 2006/09/08 20:32:13 bostic Exp $ */package com.sleepycat.collections;import java.util.Collection;import java.util.Collections;import java.util.Iterator;import java.util.Map;import java.util.Set;import com.sleepycat.bind.EntityBinding;import com.sleepycat.bind.EntryBinding;import com.sleepycat.db.Database;import com.sleepycat.util.keyrange.KeyRangeException;/** * A Map view of a {@link Database}. * * <p>In addition to the standard Map methods, this class provides the * following methods for stored maps only.  Note that the use of these methods * is not compatible with the standard Java collections interface.</p> * <ul> * <li>{@link #duplicates}</li> * <li>{@link #duplicatesMap}</li> * <li>{@link #append}</li> * </ul> * * @author Mark Hayes */public class StoredMap extends StoredContainer implements Map {    private StoredKeySet keySet;    private StoredEntrySet entrySet;    private StoredValueSet valueSet;    /**     * Creates a map view of a {@link Database}.     *     * @param database is the Database underlying the new collection.     *     * @param keyBinding is the binding used to translate between key buffers     * and key objects.     *     * @param valueBinding is the binding used to translate between value     * buffers and value objects.     *     * @param writeAllowed is true to create a read-write collection or false     * to create a read-only collection.     *     * @throws IllegalArgumentException if formats are not consistently     * defined or a parameter is invalid.     *     * @throws RuntimeExceptionWrapper if a {@link     * com.sleepycat.db.DatabaseException} is thrown.     */    public StoredMap(Database database, EntryBinding keyBinding,                     EntryBinding valueBinding, boolean writeAllowed) {        super(new DataView(database, keyBinding, valueBinding, null,                           writeAllowed, null));        initView();    }    /**     * Creates a map view of a {@link Database} with a {@link     * PrimaryKeyAssigner}.  Writing is allowed for the created map.     *     * @param database is the Database underlying the new collection.     *     * @param keyBinding is the binding used to translate between key buffers     * and key objects.     *     * @param valueBinding is the binding used to translate between value     * buffers and value objects.     *     * @param keyAssigner is used by the {@link #append} method to assign     * primary keys.     *     * @throws IllegalArgumentException if formats are not consistently     * defined or a parameter is invalid.     *     * @throws RuntimeExceptionWrapper if a {@link     * com.sleepycat.db.DatabaseException} is thrown.     */    public StoredMap(Database database, EntryBinding keyBinding,                     EntryBinding valueBinding,                     PrimaryKeyAssigner keyAssigner) {        super(new DataView(database, keyBinding, valueBinding, null,                           true, keyAssigner));        initView();    }    /**     * Creates a map entity view of a {@link Database}.     *     * @param database is the Database underlying the new collection.     *     * @param keyBinding is the binding used to translate between key buffers     * and key objects.     *     * @param valueEntityBinding is the binding used to translate between     * key/value buffers and entity value objects.     *     * @param writeAllowed is true to create a read-write collection or false     * to create a read-only collection.     *     * @throws IllegalArgumentException if formats are not consistently     * defined or a parameter is invalid.     *     * @throws RuntimeExceptionWrapper if a {@link     * com.sleepycat.db.DatabaseException} is thrown.     */    public StoredMap(Database database, EntryBinding keyBinding,                     EntityBinding valueEntityBinding, boolean writeAllowed) {        super(new DataView(database, keyBinding, null, valueEntityBinding,                           writeAllowed, null));        initView();    }    /**     * Creates a map entity view of a {@link Database} with a {@link     * PrimaryKeyAssigner}.  Writing is allowed for the created map.     *     * @param database is the Database underlying the new collection.     *     * @param keyBinding is the binding used to translate between key buffers     * and key objects.     *     * @param valueEntityBinding is the binding used to translate between     * key/value buffers and entity value objects.     *     * @param keyAssigner is used by the {@link #append} method to assign     * primary keys.     *     * @throws IllegalArgumentException if formats are not consistently     * defined or a parameter is invalid.     *     * @throws RuntimeExceptionWrapper if a {@link     * com.sleepycat.db.DatabaseException} is thrown.     */    public StoredMap(Database database, EntryBinding keyBinding,                     EntityBinding valueEntityBinding,                     PrimaryKeyAssigner keyAssigner) {        super(new DataView(database, keyBinding, null, valueEntityBinding,                           true, keyAssigner));        initView();    }    StoredMap(DataView view) {        super(view);        initView();    }    /**     * Override this method to initialize view-dependent fields.     */    void initAfterClone() {        initView();    }    /**     * The keySet, entrySet and valueSet are created during Map construction     * rather than lazily when requested (as done with the java.util.Map     * implementations).  This is done to avoid synchronization every time they     * are requested.  Since they are requested often but a StoredMap is     * created infrequently, this gives the best performance.  The additional     * views are small objects and are cheap to construct.     */    private void initView() {        /* entrySet */        if (isOrdered()) {            entrySet = new StoredSortedEntrySet(view);        } else {            entrySet = new StoredEntrySet(view);        }        /* keySet */        DataView newView = view.keySetView();        if (isOrdered()) {            keySet = new StoredSortedKeySet(newView);        } else {            keySet = new StoredKeySet(newView);        }        /* valueSet */        newView = view.valueSetView();        if (isOrdered() && newView.canDeriveKeyFromValue()) {            valueSet = new StoredSortedValueSet(newView);        } else {            valueSet = new StoredValueSet(newView);        }    }    /**     * Returns the value to which this map maps the specified key.  If     * duplicates are allowed, this method returns the first duplicate, in the     * order in which duplicates are configured, that maps to the specified     * key.     *     * This method conforms to the {@link Map#get} interface.     *     * @throws RuntimeExceptionWrapper if a {@link     * com.sleepycat.db.DatabaseException} is thrown.     */    public Object get(Object key) {        return super.get(key);    }    /**     * Associates the specified value with the specified key in this map     * (optional operation).  If duplicates are allowed and the specified key     * is already mapped to a value, this method appends the new duplicate     * after the existing duplicates.  This method conforms to the {@link     * Map#put} interface.     *     * <p>The key parameter may be null if an entity binding is used and the     * key will be derived from the value (entity) parameter.  If an entity     * binding is used and the key parameter is non-null, then the key     * parameter must be equal to the key derived from the value parameter.</p>     *     * @return the previous value associated with specified key, or null if     * there was no mapping for the key or if duplicates are allowed.     *     * @throws UnsupportedOperationException if the collection is indexed, or     * if the collection is read-only.     *     * @throws IllegalArgumentException if an entity value binding is used and     * the primary key of the value given is different than the existing stored     * primary key.     *     * @throws RuntimeExceptionWrapper if a {@link     * com.sleepycat.db.DatabaseException} is thrown.     */    public Object put(Object key, Object value) {        return super.put(key, value);    }    /**     * Appends a given value returning the newly assigned key.  If a {@link     * PrimaryKeyAssigner} is associated with Store for this map, it will be     * used to assigned the returned key.  Otherwise the Store must be a QUEUE     * or RECNO database and the next available record number is assigned as     * the key.  This method does not exist in the standard {@link Map}     * interface.     *     * <p>Note that for the JE product, QUEUE and RECNO databases are not     * supported, and therefore a PrimaryKeyAssigner must be associated with     * the map in order to call this method.</p>     *     * @param value the value to be appended.     *     * @return the assigned key.     *     * @throws UnsupportedOperationException if the collection is indexed, or     * if the collection is read-only, or if the Store has no {@link     * PrimaryKeyAssigner} and is not a QUEUE or RECNO database.     *     * @throws RuntimeExceptionWrapper if a {@link     * com.sleepycat.db.DatabaseException} is thrown.     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -