Gridarta Editor
net.sf.gridarta.model.index.AbstractIndex< V extends Serializable > Class Template Reference

Abstract base class for Index implementations. More...

+ Inheritance diagram for net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >:
+ Collaboration diagram for net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >:

Public Member Functions

void add (@NotNull final V value, final long timestamp)
 Adds a value to the cache. More...
 
void addIndexListener (@NotNull final IndexListener< V > listener)
 Adds an IndexListener to be notified of changes. More...
 
void beginUpdate ()
 Starts an update. More...
 
void clear ()
 Clears all values from the index. More...
 
void endUpdate ()
 Ends an update. More...
 
Collection< V > findPartialName (@NotNull final String name)
 Returns all matching values for a (possibly partial) key name. More...
 
String getName (@NotNull final V value)
 Returns the name associated with a value. More...
 
boolean hasPending ()
 Returns whether at least one pending value exists. More...
 
void indexingFinished ()
 Should be called after indexing has finished. More...
 
boolean isModified ()
 Returns whether the state was modified since last save. More...
 
void load (@NotNull final ObjectInputStream objectInputStream) throws IOException
 @noinspection unchecked More...
 
void remove (@NotNull final V value)
 Removes a value from the cache. More...
 
void removeIndexListener (@NotNull final IndexListener< V > listener)
 Removes an IndexListener to be notified of changes. More...
 
removePending ()
 Returns one pending value. More...
 
void save (@NotNull final ObjectOutputStream objectOutputStream) throws IOException
 Saves the state to an ObjectOutputStream. More...
 
void setName (@NotNull final V value, final long timestamp, @NotNull final String name)
 Associates a value with a name. More...
 
void setPending (@NotNull final V value)
 Marks a value as pending. More...
 
int size ()
 Returns the number of values in this cache. More...
 

Private Attributes

final Collection< IndexListener< V > > indexListeners = new CopyOnWriteArrayList<>()
 The registered listeners. More...
 
boolean modified
 Whether the state (timestamps or names) was modified since last save. More...
 
final Map< V, String > names = new HashMap<>()
 Maps value to name. More...
 
final Collection< V > pending = new HashSet<>()
 Pending values. More...
 
final Object sync = new Object()
 Objects used to synchronize accesses to other fields. More...
 
final Map< V, Long > timestamps = new HashMap<>()
 Maps value to timestamp. More...
 
boolean transaction
 Whether a transaction is active. More...
 
final Collection< V > transactionDelete = new HashSet<>()
 The values to delete at the end of the current transaction. More...
 

Detailed Description

Abstract base class for Index implementations.

Parameters
<V>the value's type
Author
Andreas Kirschbaum

Definition at line 42 of file AbstractIndex.java.

Member Function Documentation

◆ add()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.add ( @NotNull final V  value,
final 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
valuethe value to add
timestampa timestamp associated with the value

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 154 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.scanMapsDirectoryInt().

+ Here is the caller graph for this function:

◆ addIndexListener()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.addIndexListener ( @NotNull final IndexListener< V >  listener)

Adds an IndexListener to be notified of changes.

Parameters
listenerthe index listener to add

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 269 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.start(), and net.sf.gridarta.model.index.MapsIndexerTest.test2().

+ Here is the caller graph for this function:

◆ beginUpdate()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.beginUpdate ( )

Starts an update.

Updates do not nest. This function and {} should be called from only a single thread.

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 118 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.updateMapsDirectory().

+ Here is the caller graph for this function:

◆ clear()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.clear ( )

Clears all values from the index.

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 316 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.AbstractIndex< MapFile >.load(), and net.sf.gridarta.model.index.MapsIndexer< G, A, R >.loadMapsIndex().

+ Here is the caller graph for this function:

◆ endUpdate()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.endUpdate ( )

◆ findPartialName()

Collection<V> net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.findPartialName ( @NotNull final String  name)

Returns all matching values for a (possibly partial) key name.

Parameters
namethe partial name to look up
Returns
the matching values

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 104 of file AbstractIndex.java.

Referenced by net.sf.gridarta.gui.dialog.gomap.GoMapDialog< G extends GameObject< G, A, R, A extends MapArchObject< A, R extends Archetype< G, A, R >.doSearch(), net.sf.gridarta.model.index.MapsIndexerTest.test1(), and net.sf.gridarta.model.index.MapsIndexerTest.test2().

+ Here is the caller graph for this function:

◆ getName()

String net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.getName ( @NotNull final V  value)

Returns the name associated with a value.

Parameters
valuethe value
Returns
the name or
null
if the value does not exist or has no associated name

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 233 of file AbstractIndex.java.

Referenced by net.sf.gridarta.gui.dialog.gomap.MapListCellRenderer.getListCellRendererComponent().

+ Here is the caller graph for this function:

◆ hasPending()

boolean net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.hasPending ( )

Returns whether at least one pending value exists.

Returns
whether at least one pending value exists

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 255 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.waitForIdle().

+ Here is the caller graph for this function:

◆ indexingFinished()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.indexingFinished ( )

Should be called after indexing has finished.

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 327 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.reportStateChange().

+ Here is the caller graph for this function:

◆ isModified()

boolean net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.isModified ( )

Returns whether the state was modified since last save.

Returns
whether the state was modified

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 262 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.saveMapsIndex().

+ Here is the caller graph for this function:

◆ load()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.load ( @NotNull final ObjectInputStream  objectInputStream) throws IOException

@noinspection unchecked

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 292 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.loadMapsIndex().

+ Here is the caller graph for this function:

◆ remove()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.remove ( @NotNull final V  value)

Removes a value from the cache.

Does nothing if the values does not exist.

Parameters
valuethe value to remove

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 182 of file AbstractIndex.java.

◆ removeIndexListener()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.removeIndexListener ( @NotNull final IndexListener< V >  listener)

Removes an IndexListener to be notified of changes.

Parameters
listenerthe index listener to remove

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 274 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.stop().

+ Here is the caller graph for this function:

◆ removePending()

V net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.removePending ( )

Returns one pending value.

Returns
a pending value or
null
if no pending values exist

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 241 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.indexPendingMaps().

+ Here is the caller graph for this function:

◆ save()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.save ( @NotNull final ObjectOutputStream  objectOutputStream) throws IOException

Saves the state to an ObjectOutputStream.

Pending maps are not saved.

Parameters
objectOutputStreamthe object output stream to write to
Exceptions
IOExceptionif an I/O error occurs

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 279 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.saveMapsIndex().

+ Here is the caller graph for this function:

◆ setName()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.setName ( @NotNull final V  value,
final long  timestamp,
@NotNull final String  name 
)

Associates a value with a name.

Adds the value if it does not exist.

Parameters
valuethe value to associate with a name
timestampthe value's timestamp
namethe name associated with the value

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 217 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.indexPendingMaps().

+ Here is the caller graph for this function:

◆ setPending()

void net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.setPending ( @NotNull final V  value)

Marks a value as pending.

The value is added if it does not exist.

Parameters
valuethe value to mark pending

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 198 of file AbstractIndex.java.

◆ size()

int net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.size ( )

Returns the number of values in this cache.

Returns
the number of values

Implements net.sf.gridarta.model.index.Index< V >.

Definition at line 98 of file AbstractIndex.java.

Referenced by net.sf.gridarta.model.index.MapsIndexer< G, A, R >.loadMapsIndex(), and net.sf.gridarta.model.index.MapsIndexer< G, A, R >.saveMapsIndex().

+ Here is the caller graph for this function:

Member Data Documentation

◆ indexListeners

◆ modified

◆ names

◆ pending

◆ sync

◆ timestamps

◆ transaction

◆ transactionDelete

final Collection<V> net.sf.gridarta.model.index.AbstractIndex< V extends Serializable >.transactionDelete = new HashSet<>()
private

The documentation for this class was generated from the following file: