Class UniqueIdManager
java.lang.Object
VASSAL.tools.UniqueIdManager
- All Implemented Interfaces:
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.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
An object with an identifier that can be manipulated by aUniqueIdManager
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
findInstance
(String id) Return the first instance whose name or id matches the argumentstatic String
Make a best guess for a unique identifier for the target.void
void
validate
(Buildable target, ValidationReport report) Ensures that no other instance of the same class has the same name
-
Constructor Details
-
UniqueIdManager
-
-
Method Details
-
add
-
remove
-
getIdentifier
Make a best guess for a unique identifier for the target. UseUniqueIdManager.Identifyable.getConfigureName()
if non-null, otherwise useUniqueIdManager.Identifyable.getId()
- Parameters:
target
- identifiable target- Returns:
- identifier for target
-
getAllInstances
-
findInstance
Return the first instance whose name or id matches the argument- Parameters:
id
- name or id- Returns:
- Return the first instance whose name or id matches the argument
-
validate
Ensures that no other instance of the same class has the same name- Specified by:
validate
in interfaceValidityChecker
-