de.uni_paderborn.robots.data
Class Index

java.lang.Object
  |
  +--de.uni_paderborn.robots.data.Index

public class Index
extends java.lang.Object

This class organizes the indices used for identifying fields and items in the arena. It is ensured that the indices are unique and randomly created. The IDs not used anymore are remove by the VM GC when calling finalize(). The class is realized as a singleton.


Field Summary
private static Index index
          instance to the object of this class
private  java.util.HashSet indices
          contains the indices
private  java.util.Random random
          random number generator
 
Constructor Summary
private Index()
          Constructor, creates empty index.
 
Method Summary
 void addIDs(java.util.HashSet otherIndices)
          Adds the given IDs to our index.
static Index getIndex()
          Returns an instance of the class Index.
 int getNewID(Identifyable identifyable)
          Returns a new unique and random number for an ID.
 boolean removeID(int id)
          Removes given ID from index.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

indices

private java.util.HashSet indices
contains the indices

index

private static Index index
instance to the object of this class

random

private java.util.Random random
random number generator
Constructor Detail

Index

private Index()
Constructor, creates empty index.
Method Detail

getIndex

public static Index getIndex()
Returns an instance of the class Index.
Returns:
instance of class Index

getNewID

public int getNewID(Identifyable identifyable)
Returns a new unique and random number for an ID.
Parameters:
identifyable - the Identifyable object which wants an ID
Returns:
a new unique and random number

removeID

public boolean removeID(int id)
Removes given ID from index.
Parameters:
id - the ID that is to be removed from index
Returns:
true, if ID was sucessfully removed, false if not

addIDs

public void addIDs(java.util.HashSet otherIndices)
Adds the given IDs to our index.
Parameters:
otherIndices - IDs