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;
  
 import java.util.Map;
 import java.util.Set;
 
 /* <!-- begin JE only --> */
 /* <!-- end JE only --> */
The Set returned by Map.entrySet(). This class may not be instantiated directly. Contrary to what is stated by java.util.Map.entrySet() this class does support the add(java.util.Map.Entry) and StoredCollection.addAll(java.util.Collection) methods.

The java.util.Map.Entry.setValue(java.lang.Object) method of the Map.Entry objects that are returned by this class and its iterators behaves just as the StoredIterator.set(java.lang.Object) method does.

Author(s):
Mark Hayes
 
 public class StoredEntrySet<K, V>
     extends StoredCollection<Map.Entry<K, V>>
     implements Set<Map.Entry<K, V>> {
 
     StoredEntrySet(DataView mapView) {
 
         super(mapView);
     }

    
Adds the specified element to this set if it is not already present (optional operation). This method conforms to the java.util.Set.add(java.lang.Object) interface.

Parameters:
mapEntry must be a java.util.Map.Entry instance.
Returns:
true if the key-value pair was added to the set (and was not previously present).
Throws:
com.sleepycat.je.OperationFailureException if one of the Write Operation Failures occurs.
com.sleepycat.je.EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.UnsupportedOperationException if the collection is read-only.
java.lang.ClassCastException if the mapEntry is not a java.util.Map.Entry instance.
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
 
     public boolean add(Map.Entry<K, V> mapEntry) {
 
         return add(mapEntry.getKey(), mapEntry.getValue());
     }

    
Removes the specified element from this set if it is present (optional operation). This method conforms to the java.util.Set.remove(java.lang.Object) interface.

Parameters:
mapEntry is a java.util.Map.Entry instance to be removed.
Returns:
true if the key-value pair was removed from the set, or false if the mapEntry is not a java.util.Map.Entry instance or is not present in the set.
Throws:
com.sleepycat.je.OperationFailureException if one of the Write Operation Failures occurs.
com.sleepycat.je.EnvironmentFailureException if an unexpected, internal or environment-wide failure occurs.
java.lang.UnsupportedOperationException if the collection is read-only.
com.sleepycat.util.RuntimeExceptionWrapper if a checked exception is thrown, including a DatabaseException on BDB (C edition).
 
     public boolean remove(Object mapEntry) {
 
        if (!(mapEntry instanceof Map.Entry)) {
            return false;
        }
        DataCursor cursor = null;
        boolean doAutoCommit = beginAutoCommit();
        try {
            cursor = new DataCursor(true);
            Map.Entry entry = (Map.EntrymapEntry;
            OperationStatus status =
                cursor.findBoth(entry.getKey(), entry.getValue(), true);
            if (status == .) {
                cursor.delete();
            }
            closeCursor(cursor);
            commitAutoCommit(doAutoCommit);
            return (status == .);
        } catch (Exception e) {
            closeCursor(cursor);
            throw handleException(edoAutoCommit);
        }
    }

    
Returns true if this set contains the specified element. This method conforms to the java.util.Set.contains(java.lang.Object) interface.

Parameters:
mapEntry is a java.util.Map.Entry instance to be checked.
Returns:
true if the key-value pair is present in the set, or false if the mapEntry is not a java.util.Map.Entry instance or is not present in the set.
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 boolean contains(Object mapEntry) {
        if (!(mapEntry instanceof Map.Entry)) {
            return false;
        }
        DataCursor cursor = null;
        try {
            cursor = new DataCursor(false);
            Map.Entry entry = (Map.EntrymapEntry;
            OperationStatus status =
                cursor.findBoth(entry.getKey(), entry.getValue(), false);
            return (status == .);
        } catch (Exception e) {
            throw StoredContainer.convertException(e);
        } finally {
            closeCursor(cursor);
        }
    }
    // javadoc is inherited
    public String toString() {
        StringBuilder buf = new StringBuilder();
        buf.append("[");
        StoredIterator i = null;
        try {
            i = storedIterator();
            while (i.hasNext()) {
                Map.Entry entry = (Map.Entryi.next();
                if (buf.length() > 1) buf.append(',');
                Object key = entry.getKey();
                Object val = entry.getValue();
                if (key != nullbuf.append(key.toString());
                buf.append('=');
                if (val != nullbuf.append(val.toString());
            }
            buf.append(']');
            return buf.toString();
        } catch (Exception e) {
            throw StoredContainer.convertException(e);
        } finally {
            StoredIterator.close(i);
        }
    }
    Map.Entry<K, V> makeIteratorData(BaseIterator iterator,
                                     DatabaseEntry keyEntry,
                                     DatabaseEntry priKeyEntry,
                                     DatabaseEntry valueEntry) {
        return new StoredMapEntry(.makeKey(keyEntrypriKeyEntry),
                                  .makeValue(priKeyEntryvalueEntry),
                                  thisiterator);
    }
    boolean hasValues() {
        return true;
    }
New to GrepCode? Check out our FAQ X