com.partnersoft.data
Class NumberedNames

java.lang.Object
  extended by com.partnersoft.data.NumberedNames

public class NumberedNames
extends java.lang.Object

A numbered list of names, or a named list of numbers, depending on how you look at it.

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.

Version:
$Id: NumberedNames.java 1012 2007-11-24 18:30:02Z paul $
Author:
Paul Reavis

Constructor Summary
NumberedNames()
           
NumberedNames(java.util.List<java.lang.String> list)
           
 
Method Summary
 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumberedNames

public NumberedNames()

NumberedNames

public NumberedNames(java.util.List<java.lang.String> list)
Method Detail

numberFor

public int numberFor(java.lang.String name)
Returns the assigned number for the given name. The name must already have been added via ensureNumberFor(String).

Parameters:
name - name to look up the number for
Returns:
number for the name, or -1 if it can't find it

nameFor

public java.lang.String nameFor(int number)
Returns the assigned name for the given number.

Parameters:
number - number to look up the name of
Returns:
name for the number, null if it can't find one

ensureNumberFor

public int ensureNumberFor(java.lang.String name)
This is probably the most useful method. Returns an existing ID for the given name; if there isn't one allocates the next sequential number and returns that.

Parameters:
name - name to look up
Returns:
valid number for the name

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

asArrayList

public java.util.ArrayList<java.lang.String> asArrayList()
Returns the encoding as an ArrayList of Strings. The index of each String is its ID.

Returns:
list of strings in numeric order

asNaming

public Naming<java.lang.Integer> asNaming()
Returns the encoding as a Naming, mapping the name to its numeric ID.

Returns:
Naming mapping Strings to their numbers

asArray

public java.lang.String[] asArray()
Returns the encoding as an array of Strings.

Returns:
array of names in numeric order