Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javafe.ast
Class Identifier

    java.lang.Object
      javafe.ast.Identifier

public final class Identifier
extends java.lang.Object

An `Identifier` is a symbol, that is, a sequence of characters. `Identifier`s are interned: for any given sequence of characters, we create exactly one instance of `Identifier` to represent it (we say that the sequence of characters is associated with this `Identifier` instance). This allows us to use object equality (that is, `==`) to check symbol equality.

This class is thread-safe: multiple threads can enter its any of its methods (static or non-static) simultaneously.

Field Summary
`private static Identifier[][]` | `chains` Table containing every instance of `Identifier` created.
`private char[]` | `chars` Sequence of characters represented by this Identifier (never `null`).
`private java.lang.String` | `equiv` Memoization of `String.valueOf(chars, 0, chars.length)`; may be `null`.
`(package private) static int` | `HC` Constant used for hashing.
`private static int` | `INITIAL_CHAIN_SIZE` Initial size of chains inside the table.
`private static int` | `TABLE_SIZE` Size of intern table.
`(package private) int` | `tokenType` This field defaults to `TagConstants.IDENT`, but is set to other values by the scanner to indicate keywords.

Constructor Summary
`private` | `Identifier(char[] text, int textlen, int hashcode)`

Method Summary
`static void` | `check()` Return true if all invariants are satisfied.
`boolean` | `equals(java.lang.Object o)`
`(package private) static int` | `hash(char[] text, int textlen)`
`(package private) static int` | `hash(java.lang.String s)`
`int` | `hashCode()`
`(package private) static Identifier` | `intern(char[] text, int textlen, int hashcode)` Intern a sequence of characters with a pre-computed hashcode.
`static Identifier` | `intern(java.lang.String s)` Returns the `Identifier` associated with `s`.
`static void` | `main(java.lang.String[] argv)`
`private static Identifier` | `slowFind(java.lang.String s)` Used by `check`; checks for duplicates.
`java.lang.String` | `toString()` Return a string containing the symbol associated with `this`.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### TABLE_SIZE

    private static final int TABLE_SIZE

  Size of intern table.

  See Also:
    Constant Field Values

### chains

    private static final Identifier[][] chains

  Table containing every instance of `Identifier` created. If a symbol `s` has been interned, its associated `Identifier` is found by hashing it to integer `h` such that `0 <= h <= TABLE_SIZE`, looking up `v = chains[h]`, which is a an array of arrays of `Identifier`s, then searching `v` for the `Identifier` associated with `s`. If no such element exists, then `s` hasn't been interned yet.

  This table is only extended, old parts are never updated. Thus, reading the table can occur without any locks being held. Extension of the table is protected by the mutex associated with the table itself (that is, the object pointed to by `chains`.

### INITIAL_CHAIN_SIZE

    private static final int INITIAL_CHAIN_SIZE

  Initial size of chains inside the table.

  See Also:
    Constant Field Values

### chars

    private char[] chars

  Sequence of characters represented by this Identifier (never `null`).

### equiv

    private java.lang.String equiv

  Memoization of `String.valueOf(chars, 0, chars.length)`; may be `null`. This variable may be written exactly once.

### HC

    static final int HC

  Constant used for hashing. The hash function used to hash a n-character identifier `idn` is to sum `HC`^(n-(i+1))`*idn[`i`]`. Note that this is the same hash function used by Java 1.1 for hashing `String` objects.

  See Also:
    Constant Field Values

### tokenType

    int tokenType

  This field defaults to `TagConstants.IDENT`, but is set to other values by the scanner to indicate keywords.

Constructor Detail

### Identifier

    private Identifier(char[] text,
                       int textlen,
                       int hashcode)

Method Detail

### intern

    public static Identifier intern(java.lang.String s)

  Returns the `Identifier` associated with `s`.

### intern

    static Identifier intern(char[] text,
                             int textlen,
                             int hashcode)

  Intern a sequence of characters with a pre-computed hashcode.
  Requires: `hashcode = Identifier.hash(text, textlen)`

  Ensures: returns the `Identifier` instance associated with the symbol consisting of the first `textlen` characters of `text`.

### hash

    static int hash(java.lang.String s)

### hash

    static int hash(char[] text,
                    int textlen)

### toString

    public java.lang.String toString()

  Return a string containing the symbol associated with `this`.

### hashCode

    public int hashCode()

### equals

    public boolean equals(java.lang.Object o)

### check

    public static void check()

  Return true if all invariants are satisfied.

### slowFind

    private static Identifier slowFind(java.lang.String s)

  Used by `check`; checks for duplicates.

### main

    public static void main(java.lang.String[] argv)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

The ESC/Java2 Project Homepage