VASSAL.tools
Class UniqueIdManager
java.lang.Object
|
+--VASSAL.tools.UniqueIdManager
- All Implemented Interfaces:
- ValidityChecker
- public class UniqueIdManager
- extends java.lang.Object
- implements ValidityChecker
A class for assigning unique identifiers to objects. Identifiers will be of
the form prefix#, where prefix is specified at initialization and the #
is an increasing digit. Components will have the same ID provided they
are loaded in the same order
Unfortunately, this approach is flawed. If a module is edited, saved games from previous
versions can become broken. Worse, two players with different extensions loaded
could have incompatible behavior.
The preferred way to have unique identifiers is to allow the user to provide
names and use a ValidityChecker to ensure that the
names are unique. This class provides some support for using this approach while
providing backward compatibility with old saved games and modules.
Usage: an UniqueIdManager.Identifyable instance invokes add(VASSAL.tools.UniqueIdManager.Identifyable), typically
during the Buildable.build(org.w3c.dom.Element) method. Classes can use the getIdentifier(VASSAL.tools.UniqueIdManager.Identifyable)
method to look up an identifier for that instance, and can use findInstance(java.lang.String)
to look up a component by id.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
UniqueIdManager
public UniqueIdManager(java.lang.String prefix)
add
public void add(UniqueIdManager.Identifyable i)
remove
public void remove(UniqueIdManager.Identifyable i)
getIdentifier
public static java.lang.String getIdentifier(UniqueIdManager.Identifyable target)
- Make a best guess for a unique identifier for the target.
Use Identifyable#getConfigureName if non-null, otherwise
use {@link Identifyable#getId
- Parameters:
target - - Returns:
-
getAllInstances
public java.util.Iterator getAllInstances()
findInstance
public UniqueIdManager.Identifyable findInstance(java.lang.String id)
- Return the first instance whose name or id matches the argument
- Parameters:
id - - Returns:
-
validate
public void validate(Buildable target,
ValidationReport report)
- Ensures that no other instance of the same class has the same name
- Specified by:
validate in interface ValidityChecker