org.openide.util.lookup
Class ArrayStorage

java.lang.Object
  extended by org.openide.util.lookup.ArrayStorage
All Implemented Interfaces:
AbstractLookup.Storage<ArrayStorage.Transaction>

final class ArrayStorage
extends java.lang.Object
implements AbstractLookup.Storage<ArrayStorage.Transaction>

ArrayStorage of Pairs from AbstractLookup.

Author:
Jaroslav Tulach

Nested Class Summary
(package private) static class ArrayStorage.Transaction
          HashSet with additional field for new array which is callocated in case we are doing replace to hold all new items.
 
Field Summary
(package private) static java.lang.Integer DEFAULT_TRASH
          default trashold
 
Constructor Summary
ArrayStorage()
          Constructor
ArrayStorage(java.lang.Integer treshhold)
          Constructs new ArrayStorage
 
Method Summary
 boolean add(AbstractLookup.Pair<?> item, ArrayStorage.Transaction changed)
          Adds an item into the tree.
 ArrayStorage.Transaction beginTransaction(int ensure)
          We use a hash set of all modified Pair to handle the transaction
 AbstractLookup.ReferenceToResult cleanUpResult(Lookup.Template<?> templ)
          Cleanup the references
 void endTransaction(ArrayStorage.Transaction changed, java.util.Set<AbstractLookup.R> modified)
          Extract all results.
<T> java.util.Enumeration<AbstractLookup.Pair<T>>
lookup(java.lang.Class<T> clazz)
          Queries for instances of given class.
 AbstractLookup.ReferenceToResult registerReferenceToResult(AbstractLookup.ReferenceToResult<?> newRef)
          Associates another result with this storage.
 void remove(AbstractLookup.Pair item, ArrayStorage.Transaction changed)
          Removes an item.
 void retainAll(java.util.Map retain, ArrayStorage.Transaction changed)
          Removes all items that are not present in the provided collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TRASH

static final java.lang.Integer DEFAULT_TRASH
default trashold

Constructor Detail

ArrayStorage

public ArrayStorage()
Constructor


ArrayStorage

public ArrayStorage(java.lang.Integer treshhold)
Constructs new ArrayStorage

Method Detail

add

public boolean add(AbstractLookup.Pair<?> item,
                   ArrayStorage.Transaction changed)
Adds an item into the tree.

Specified by:
add in interface AbstractLookup.Storage<ArrayStorage.Transaction>
Parameters:
item - to add
changed - transaction token
Returns:
true if the Item has been added for the first time or false if some other item equal to this one already existed in the lookup

remove

public void remove(AbstractLookup.Pair item,
                   ArrayStorage.Transaction changed)
Removes an item.

Specified by:
remove in interface AbstractLookup.Storage<ArrayStorage.Transaction>

retainAll

public void retainAll(java.util.Map retain,
                      ArrayStorage.Transaction changed)
Removes all items that are not present in the provided collection.

Specified by:
retainAll in interface AbstractLookup.Storage<ArrayStorage.Transaction>
Parameters:
retain - Pair -> AbstractLookup.Info map
notify - set of Classes that has possibly changed

lookup

public <T> java.util.Enumeration<AbstractLookup.Pair<T>> lookup(java.lang.Class<T> clazz)
Queries for instances of given class.

Specified by:
lookup in interface AbstractLookup.Storage<ArrayStorage.Transaction>
Parameters:
clazz - the class to check
Returns:
enumeration of Item
See Also:
#unsorted

registerReferenceToResult

public AbstractLookup.ReferenceToResult registerReferenceToResult(AbstractLookup.ReferenceToResult<?> newRef)
Associates another result with this storage.

Specified by:
registerReferenceToResult in interface AbstractLookup.Storage<ArrayStorage.Transaction>
Parameters:
newRef - the new reference to remember
Returns:
the previous reference that was kept (null if newRef is the first one) the applications is expected to link from newRef to this returned value to form a linked list

cleanUpResult

public AbstractLookup.ReferenceToResult cleanUpResult(Lookup.Template<?> templ)
Cleanup the references

Specified by:
cleanUpResult in interface AbstractLookup.Storage<ArrayStorage.Transaction>
Parameters:
templ - template of a result(s) that should be checked
Returns:
null if all references for this template were cleared or one of them

beginTransaction

public ArrayStorage.Transaction beginTransaction(int ensure)
We use a hash set of all modified Pair to handle the transaction

Specified by:
beginTransaction in interface AbstractLookup.Storage<ArrayStorage.Transaction>
Parameters:
ensure - the amount of items that will appear in the storage after the modifications (-1 == remove one, -2 == add one, >= 0 the amount of objects at the end
Returns:
a token to identify the transaction

endTransaction

public void endTransaction(ArrayStorage.Transaction changed,
                           java.util.Set<AbstractLookup.R> modified)
Extract all results.

Specified by:
endTransaction in interface AbstractLookup.Storage<ArrayStorage.Transaction>
Parameters:
changed - the transaction indentification