Package net.sf.gridarta.model.index
Class AbstractIndex<V extends java.io.Serializable>
- java.lang.Object
-
- net.sf.gridarta.model.index.AbstractIndex<V>
-
-
Constructor Summary
Constructors Constructor Description AbstractIndex()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(V value, long timestamp)Adds a value to the cache.voidaddIndexListener(@NotNull IndexListener<V> listener)Adds anIndexListenerto be notified of changes.voidbeginUpdate()Starts an update.voidclear()Clears all values from the index.voidendUpdate()Ends an update.@NotNull java.util.Collection<V>findPartialName(@NotNull java.lang.String name)Returns all matching values for a (possibly partial) key name.@Nullable java.lang.StringgetName(V value)Returns the name associated with a value.booleanhasPending()Returns whether at least one pending value exists.voidindexingFinished()Should be called after indexing has finished.booleanisModified()Returns whether the state was modified since last save.voidload(@NotNull java.io.ObjectInputStream objectInputStream)Restores the state from anObjectInputStream.voidremove(V value)Removes a value from the cache.voidremoveIndexListener(@NotNull IndexListener<V> listener)Removes anIndexListenerto be notified of changes.VremovePending()Returns one pending value.voidsave(@NotNull java.io.ObjectOutputStream objectOutputStream)Saves the state to anObjectOutputStream.voidsetName(V value, long timestamp, @NotNull java.lang.String name)Associates a value with a name.voidsetPending(V value)Marks a value as pending.intsize()Returns the number of values in this cache.
-
-
-
Method Detail
-
size
public int size()
Description copied from interface:IndexReturns the number of values in this cache.
-
findPartialName
@NotNull public @NotNull java.util.Collection<V> findPartialName(@NotNull @NotNull java.lang.String name)
Description copied from interface:IndexReturns all matching values for a (possibly partial) key name.- Specified by:
findPartialNamein interfaceIndex<V extends java.io.Serializable>- Parameters:
name- the partial name to look up- Returns:
- the matching values
-
beginUpdate
public void beginUpdate()
Description copied from interface:IndexStarts an update. Updates do not nest. This function andIndex.endUpdate()should be called from only a single thread.- Specified by:
beginUpdatein interfaceIndex<V extends java.io.Serializable>
-
endUpdate
public void endUpdate()
Description copied from interface:IndexEnds an update. Removes all values from the index that were notaddedsince the last call toIndex.beginUpdate(). Must not be called unless a directly preceding call tobeginUpdate()was made.
-
add
public void add(@NotNull V value, long timestamp)Description copied from interface:IndexAdds a value to the cache. Newly added values and existing values for which the new timestamp does not match the old timestamp are marked as pending.
-
remove
public void remove(@NotNull V value)Description copied from interface:IndexRemoves a value from the cache. Does nothing if the values does not exist.
-
setPending
public void setPending(@NotNull V value)Description copied from interface:IndexMarks a value as pending. The value is added if it does not exist.- Specified by:
setPendingin interfaceIndex<V extends java.io.Serializable>- Parameters:
value- the value to mark pending
-
setName
public void setName(@NotNull V value, long timestamp, @NotNull @NotNull java.lang.String name)Description copied from interface:IndexAssociates a value with a name. Adds the value if it does not exist.
-
getName
@Nullable public @Nullable java.lang.String getName(@NotNull V value)Description copied from interface:IndexReturns the name associated with a value.
-
removePending
@Nullable public V removePending()
Description copied from interface:IndexReturns one pending value.- Specified by:
removePendingin interfaceIndex<V extends java.io.Serializable>- Returns:
- a pending value or
nullif no pending values exist
-
hasPending
public boolean hasPending()
Description copied from interface:IndexReturns whether at least one pending value exists.- Specified by:
hasPendingin interfaceIndex<V extends java.io.Serializable>- Returns:
- whether at least one pending value exists
-
isModified
public boolean isModified()
Description copied from interface:IndexReturns whether the state was modified since last save.- Specified by:
isModifiedin interfaceIndex<V extends java.io.Serializable>- Returns:
- whether the state was modified
-
addIndexListener
public void addIndexListener(@NotNull @NotNull IndexListener<V> listener)Description copied from interface:IndexAdds anIndexListenerto be notified of changes.- Specified by:
addIndexListenerin interfaceIndex<V extends java.io.Serializable>- Parameters:
listener- the index listener to add
-
removeIndexListener
public void removeIndexListener(@NotNull @NotNull IndexListener<V> listener)Description copied from interface:IndexRemoves anIndexListenerto be notified of changes.- Specified by:
removeIndexListenerin interfaceIndex<V extends java.io.Serializable>- Parameters:
listener- the index listener to remove
-
save
public void save(@NotNull @NotNull java.io.ObjectOutputStream objectOutputStream) throws java.io.IOExceptionDescription copied from interface:IndexSaves the state to anObjectOutputStream. Pending maps are not saved.
-
load
public void load(@NotNull @NotNull java.io.ObjectInputStream objectInputStream) throws java.io.IOExceptionDescription copied from interface:IndexRestores the state from anObjectInputStream. The previous state is overwritten.
-
clear
public void clear()
Description copied from interface:IndexClears all values from the index.
-
indexingFinished
public void indexingFinished()
Description copied from interface:IndexShould be called after indexing has finished.- Specified by:
indexingFinishedin interfaceIndex<V extends java.io.Serializable>
-
-