Package net.sf.gridarta.model.index
Interface Index<V>
-
- Type Parameters:
V- the value's type
- All Known Implementing Classes:
AbstractIndex,MapsIndex
public interface Index<V>An index of values. Values are associated with a timestamp and zero or one name. The timestamp is used to mark values as pending whenever they have changed. Pending values may be retrieved for re-indexing.Values may be looked up by partial names.
All methods are synchronized: concurrent access from multiple threads is supported.
-
-
Method Summary
All Methods Instance Methods Abstract 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
int size()
Returns the number of values in this cache.- Returns:
- the number of values
-
findPartialName
@NotNull @NotNull java.util.Collection<V> findPartialName(@NotNull @NotNull java.lang.String name)
Returns all matching values for a (possibly partial) key name.- Parameters:
name- the partial name to look up- Returns:
- the matching values
-
beginUpdate
void beginUpdate()
Starts an update. Updates do not nest. This function andendUpdate()should be called from only a single thread.
-
endUpdate
void endUpdate()
Ends an update. Removes all values from the index that were notaddedsince the last call tobeginUpdate(). Must not be called unless a directly preceding call tobeginUpdate()was made.
-
add
void add(@NotNull V value, long timestamp)Adds 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.- Parameters:
value- the value to addtimestamp- a timestamp associated with the value
-
remove
void remove(@NotNull V value)Removes a value from the cache. Does nothing if the values does not exist.- Parameters:
value- the value to remove
-
setPending
void setPending(@NotNull V value)Marks a value as pending. The value is added if it does not exist.- Parameters:
value- the value to mark pending
-
setName
void setName(@NotNull V value, long timestamp, @NotNull @NotNull java.lang.String name)Associates a value with a name. Adds the value if it does not exist.- Parameters:
value- the value to associate with a nametimestamp- the value's timestampname- the name associated with the value
-
getName
@Nullable @Nullable java.lang.String getName(@NotNull V value)Returns the name associated with a value.- Parameters:
value- the value- Returns:
- the name or
nullif the value does not exist or has no associated name
-
removePending
@Nullable V removePending()
Returns one pending value.- Returns:
- a pending value or
nullif no pending values exist
-
hasPending
boolean hasPending()
Returns whether at least one pending value exists.- Returns:
- whether at least one pending value exists
-
isModified
boolean isModified()
Returns whether the state was modified since last save.- Returns:
- whether the state was modified
-
addIndexListener
void addIndexListener(@NotNull @NotNull IndexListener<V> listener)Adds anIndexListenerto be notified of changes.- Parameters:
listener- the index listener to add
-
removeIndexListener
void removeIndexListener(@NotNull @NotNull IndexListener<V> listener)Removes anIndexListenerto be notified of changes.- Parameters:
listener- the index listener to remove
-
save
void save(@NotNull @NotNull java.io.ObjectOutputStream objectOutputStream) throws java.io.IOExceptionSaves the state to anObjectOutputStream. Pending maps are not saved.- Parameters:
objectOutputStream- the object output stream to write to- Throws:
java.io.IOException- if an I/O error occurs
-
load
void load(@NotNull @NotNull java.io.ObjectInputStream objectInputStream) throws java.io.IOExceptionRestores the state from anObjectInputStream. The previous state is overwritten.- Parameters:
objectInputStream- the input stream to read from- Throws:
java.io.IOException- if an I/O error occurs
-
clear
void clear()
Clears all values from the index.
-
indexingFinished
void indexingFinished()
Should be called after indexing has finished.
-
-