edu.stanford.nlp.util
Class Numberer

java.lang.Object
  extended by edu.stanford.nlp.util.Numberer
All Implemented Interfaces:
java.io.Serializable

public class Numberer
extends java.lang.Object
implements java.io.Serializable

Gives unique integer serial numbers to a family of objects, identified by a name space. A Numberer is like a collection of Indexes, and for many purposes it is more straightforward to use an Index, but Numberer can be useful precisely because it maintains a global name space for numbered object families, and provides facilities for mapping across numberings within that space. At any rate, it's widely used in some existing packages.

This implementation is not thread-safe and should be externally synchronised if a Numberer is being accessed from multiple threads.

Author:
Dan Klein
See Also:
Serialized Form

Constructor Summary
Numberer()
           
Numberer(Numberer numb)
          Initialize a new Numberer with a copy of the contents of an existing Numberer.
 
Method Summary
static void clearGlobalNumberers()
           
static Numberer getGlobalNumberer(java.lang.String type)
           
static java.util.Map<java.lang.String,Numberer> getNumberers()
           
 boolean hasSeen(java.lang.Object o)
           
 void lock()
           
 int number(java.lang.Object o)
           
static int number(java.lang.String type, java.lang.Object o)
          Get a number for an object in namespace type.
 java.lang.Object object(int n)
           
static java.lang.Object object(java.lang.String type, int n)
           
 java.util.Set<java.lang.Object> objects()
           
static void setGlobalNumberer(java.lang.String key, Numberer numb)
           
static void setNumberers(java.util.Map<java.lang.String,Numberer> numbs)
          You need to call this after deserializing Numberer objects to restore the global namespace, since static objects aren't serialized.
 java.lang.String toString()
           
 int total()
           
static int translate(java.lang.String sourceType, java.lang.String targetType, int n)
          For an Object o that occurs in Numberers of type sourceType and targetType, translates the serial number n of o in the sourceType Numberer to the serial number in the targetType Numberer.
 void unlock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Numberer

public Numberer()

Numberer

public Numberer(Numberer numb)
Initialize a new Numberer with a copy of the contents of an existing Numberer. The Numberer is a fully new object, but the objects stored in the Numberer are the same.

Method Detail

getNumberers

public static java.util.Map<java.lang.String,Numberer> getNumberers()

clearGlobalNumberers

public static void clearGlobalNumberers()

setNumberers

public static void setNumberers(java.util.Map<java.lang.String,Numberer> numbs)
You need to call this after deserializing Numberer objects to restore the global namespace, since static objects aren't serialized.


setGlobalNumberer

public static void setGlobalNumberer(java.lang.String key,
                                     Numberer numb)

getGlobalNumberer

public static Numberer getGlobalNumberer(java.lang.String type)

number

public static int number(java.lang.String type,
                         java.lang.Object o)
Get a number for an object in namespace type. This looks up the Numberer for type in the global namespace map (creating it if none previously existed), and then returns the appropriate number for the key.


object

public static java.lang.Object object(java.lang.String type,
                                      int n)

translate

public static int translate(java.lang.String sourceType,
                            java.lang.String targetType,
                            int n)
For an Object o that occurs in Numberers of type sourceType and targetType, translates the serial number n of o in the sourceType Numberer to the serial number in the targetType Numberer.


total

public int total()

lock

public void lock()

unlock

public void unlock()

hasSeen

public boolean hasSeen(java.lang.Object o)

objects

public java.util.Set<java.lang.Object> objects()

number

public int number(java.lang.Object o)

object

public java.lang.Object object(int n)

toString

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


Stanford NLP Group