public class NumberedNames
extends java.lang.Object
This class is designed to solve the frequent problem of associating a sequential ID with a human-readable name. It can be used as a canonicalization structure, but is more often used to represent a long string as a short ID in binary files. The Partner ROVER format uses this concept extensively to encode graphicTypes and dataTypes.
Names are handled case-insensitively and stored with the case they were first
built with. This structure can build the coding sequentially, or can be
initialized from a list or DynamicStringArray. You can retrieve the
results as a Naming or as an array of Strings as you prefer.
This class is poorly suited to non-sequential numberings. You can have some
holes, but if you have a wide distribution of codes you'd be better off using
a OneToOneMapping instead.
Copyright 2001-2006 Partner Software, Inc.
| Constructor and Description |
|---|
NumberedNames() |
NumberedNames(java.util.List<java.lang.String> list) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String[] |
asArray()
Returns the encoding as an array of Strings.
|
java.util.ArrayList<java.lang.String> |
asArrayList()
Returns the encoding as an ArrayList of Strings.
|
Naming<java.lang.Integer> |
asNaming()
Returns the encoding as a Naming, mapping the name to its numeric ID.
|
int |
ensureNumberFor(java.lang.String name)
This is probably the most useful method.
|
java.lang.String |
nameFor(int number)
Returns the assigned name for the given number.
|
int |
numberFor(java.lang.String name)
Returns the assigned number for the given name.
|
java.lang.String |
toString() |
public NumberedNames()
public NumberedNames(java.util.List<java.lang.String> list)
public int numberFor(java.lang.String name)
ensureNumberFor(String).name - name to look up the number forpublic java.lang.String nameFor(int number)
number - number to look up the name ofpublic int ensureNumberFor(java.lang.String name)
name - name to look uppublic java.lang.String toString()
toString in class java.lang.Objectpublic java.util.ArrayList<java.lang.String> asArrayList()
public Naming<java.lang.Integer> asNaming()
public java.lang.String[] asArray()