Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.ibm.ulc.util
Class Anything

    java.lang.Object
      |
      +--com.ibm.ulc.util.Anything

public final class Anything
extends java.lang.Object
implements java.io.Serializable

Anything is a polymorphic, self describing, and dynamic data structure. An Anything can represent simple data types like longs, boolean, doubles or strings, arrays of Anythings, and dictionaries mapping between strings and Anythings (i.e. associative arrays). Because Anythings are recursive by definition, they can model arbitrarily complex structures.

Anything are streamed with AnythingWriters and AnythingReaders. Two formats exist: a pretty printing pure ASCII format (classes AnythingReader and AnythingWriter) and a more compact easier to parse format (classes AnythingReader2 and AnythingWriter2).

In the context of ULC Anythings are used as a simple but robust marshalling mechanism.

See Also:
  `AnythingReader`, `AnythingWriter`, `AnythingReader2`, `AnythingWriter2`, Serialized Form

Field Summary
`static int` | `BOOLEAN`
`static int` | `BYTES`
`static int` | `DOUBLE`
`static int` | `LONG`
`static int` | `NULL`
`static int` | `SERIALIZABLE`
`static int` | `STRING`
`static int` | `VECTOR`

Constructor Summary
`Anything()` Constructs an empty (null) Anything.
`Anything(boolean l)` Constructs an Anything representing a boolean.
`Anything(byte[] s)` Constructs an Anything representing a byte array.
`Anything(double d)` Constructs an Anything representing a double.
`Anything(java.lang.Double d)` Constructs an Anything representing a double.
`Anything(int l)` Constructs an Anything representing an int.
`Anything(long l)` Constructs an Anything representing a long.
`Anything(java.io.Serializable s)` Constructs an Anything representing a Serializable.
`Anything(java.lang.String s)` Constructs an Anything representing a String.

Method Summary
`void` | `append(Anything value)` Converts this Anything to a vector and adds the given Anything to the end of the vector.
`boolean` | `asBoolean(boolean dflt)` Generates the boolean representation of this Anything.
`byte[]` | `asBytes()` Generates the byte array representation of this Anything.
`double` | `asDouble(double dflt)` Generates the double representation of this Anything.
`int` | `asInt(int dflt)` Generates the int representation of this Anything.
`long` | `asLong(long dflt)` Generates the long representation of this Anything.
`java.io.Serializable` | `asSerializable(java.io.Serializable dflt)` Generates the Serializable representation of this Anything.
`java.lang.String` | `asString(java.lang.String dflt)` Generates the string representation of this Anything.
`java.lang.Object` | `clone()` Clones an Anything.
`void` | `dump(java.io.OutputStream out)` Pretty prints the Anything to the given stream.
`void` | `dump(java.io.OutputStream out, boolean compact)` Pretty prints the Anything to the given stream.
`Anything` | `get(int index)` Retrieves the element at the specified index in this Anything.
`Anything` | `get(java.lang.String key)` Retrieves the element associated with the given key from this Anything.
`boolean` | `get(java.lang.String key, boolean dflt)` Retrieves the element associated with the given key from this Anything and converts it to a boolean.
`double` | `get(java.lang.String key, double dflt)` Retrieves the element associated with the given key from this Anything and converts it to a double.
`int` | `get(java.lang.String key, int dflt)` Retrieves the element associated with the given key from this Anything and converts it to an int.
`long` | `get(java.lang.String key, long dflt)` Retrieves the element associated with the given key from this Anything and converts it to a long.
`java.io.Serializable` | `get(java.lang.String key, java.io.Serializable dflt)` Retrieves the element associated with the given key from this Anything and converts it to a Serializable.
`java.lang.String` | `get(java.lang.String key, java.lang.String dflt)` Retrieves the element associated with the given key from this Anything and converts it to a String.
`byte[]` | `getBytes(java.lang.String key)` Retrieves the element associated with the given key from this Anything and converts it to a byte array.
`int` | `getType()` Retrieve the tag from the Anything.
`boolean` | `isDefined(java.lang.String key)` Determines whether the given key is in this Anything.
`boolean` | `isNull()` Is the Anything empty?
`java.util.Enumeration` | `keys()` Gets all slot names (keys) of the Anything If the Anything doesn't represent a dictionary or if the index is out of bounds null is returned.
`static void` | `main(java.lang.String[] args)` A unit test :-)
`void` | `put(int index, Anything value)` Replaces the element at the specified index in this vector.
`void` | `put(java.lang.String key, Anything value)` Stores the given value under the given key in this Anything.
`void` | `put(java.lang.String key, boolean value)` Stores the given boolean value under the given key in this Anything.
`void` | `put(java.lang.String key, byte[] value)` Stores the given byte array value under the given key in this Anything.
`void` | `put(java.lang.String key, double value)` Stores the given double value under the given key in this Anything.
`void` | `put(java.lang.String key, int value)` Stores the given int value under the given key in this Anything.
`void` | `put(java.lang.String key, long value)` Stores the given long value under the given key in this Anything.
`void` | `put(java.lang.String key, java.io.Serializable o)`
`void` | `put(java.lang.String key, java.lang.String value)` Stores the given String value under the given key in this Anything.
`static Anything` | `read(java.io.InputStream in)` Read an Anything from the given stream.
`static Anything` | `read(java.lang.String filename)` Read an Anything from the given file.
`void` | `remove(int ix)` Removes the element at the specified index from this vector.
`int` | `size()` The size of the Anything.
`java.lang.String` | `slotName(int ix)` Gets the slot name (key) at the given index.
`java.lang.String` | `toString()` Generates the string representation of this Anything.
`java.util.Enumeration` | `values()` Retrieves the values of this Anything
`void` | `write(java.io.OutputStream out, IAnythingWriter format)` Writes the Anything to the specified stream using the given format.
`void` | `write(java.lang.String filename)` Write the Anything to the given file by using the pretty printing format.

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

Field Detail

### NULL

    public static final int NULL

### BOOLEAN

    public static final int BOOLEAN

### LONG

    public static final int LONG

### DOUBLE

    public static final int DOUBLE

### STRING

    public static final int STRING

### BYTES

    public static final int BYTES

### VECTOR

    public static final int VECTOR

### SERIALIZABLE

    public static final int SERIALIZABLE

Constructor Detail

### Anything

    public Anything()

  Constructs an empty (null) Anything.

### Anything

    public Anything(byte[] s)

  Constructs an Anything representing a byte array.

### Anything

    public Anything(double d)

  Constructs an Anything representing a double.

### Anything

    public Anything(int l)

  Constructs an Anything representing an int.

### Anything

    public Anything(long l)

  Constructs an Anything representing a long.

### Anything

    public Anything(java.io.Serializable s)

  Constructs an Anything representing a Serializable.
  Parameters:
    `ob` - java.io.Serializable

### Anything

    public Anything(java.lang.Double d)

  Constructs an Anything representing a double.

### Anything

    public Anything(java.lang.String s)

  Constructs an Anything representing a String.

### Anything

    public Anything(boolean l)

  Constructs an Anything representing a boolean.

Method Detail

### append

    public void append(Anything value)

  Converts this Anything to a vector and adds the given Anything to the end of the vector.

### asBoolean

    public boolean asBoolean(boolean dflt)

  Generates the boolean representation of this Anything. If the Anything doesn't represent a simple type or if it cannot converted int a boolean the given default value is returned.

### asBytes

    public byte[] asBytes()

  Generates the byte array representation of this Anything. If the Anything doesn't represent a simple type or if it cannot converted into a byte array (boolean, long, double, string, byte[]) null is returned.

### asDouble

    public double asDouble(double dflt)

  Generates the double representation of this Anything. If the Anything doesn't represent a simple type or if it cannot converted int a double the given default value is returned.

### asInt

    public int asInt(int dflt)

  Generates the int representation of this Anything. If the Anything doesn't represent a simple type or if it cannot converted int a int the given default value is returned.

### asLong

    public long asLong(long dflt)

  Generates the long representation of this Anything. If the Anything doesn't represent a simple type or if it cannot converted int a long the given default value is returned.

### asSerializable

    public java.io.Serializable asSerializable(java.io.Serializable dflt)

  Generates the Serializable representation of this Anything. If the Anything doesn't represent a Serializable type or if it cannot converted int a Serializable the given default value is returned.

### asString

    public java.lang.String asString(java.lang.String dflt)

  Generates the string representation of this Anything. If the Anything doesn't represent a simple type (boolean, long, double, string, byte[]) the given default value is returned.

### clone

    public java.lang.Object clone()

  Clones an Anything. Creates a clone by using the storing mechanism to flatten the Anything to a stream followed by resurrecting it from the same stream.
  Returns:
    Object
  Overrides:
    clone in class java.lang.Object

### dump

    public void dump(java.io.OutputStream out)

  Pretty prints the Anything to the given stream.

### dump

    public void dump(java.io.OutputStream out,
                     boolean compact)

  Pretty prints the Anything to the given stream.

### get

    public Anything get(int index)

  Retrieves the element at the specified index in this Anything. If the Anything doesn't represent a vector or if the index is out of bounds an empty Anything is returned.

### get

    public Anything get(java.lang.String key)

  Retrieves the element associated with the given key from this Anything. If the Anything doesn't represent a dictionary or if there is no element associated with the key null is returned.

### get

    public double get(java.lang.String key,
                      double dflt)

  Retrieves the element associated with the given key from this Anything and converts it to a double. If the Anything doesn't represent a dictionary or if there is no element associated with the key the given default double is returned.

### get

    public int get(java.lang.String key,
                   int dflt)

  Retrieves the element associated with the given key from this Anything and converts it to an int. If the Anything doesn't represent a dictionary or if there is no element associated with the key the given default int is returned.

### get

    public long get(java.lang.String key,
                    long dflt)

  Retrieves the element associated with the given key from this Anything and converts it to a long. If the Anything doesn't represent a dictionary or if there is no element associated with the key the given default long is returned.

### get

    public java.io.Serializable get(java.lang.String key,
                                    java.io.Serializable dflt)

  Retrieves the element associated with the given key from this Anything and converts it to a Serializable. If the Anything doesn't represent a dictionary or if there is no element associated with the key the given default Serializable is returned.

### get

    public java.lang.String get(java.lang.String key,
                                java.lang.String dflt)

  Retrieves the element associated with the given key from this Anything and converts it to a String. If the Anything doesn't represent a dictionary or if there is no element associated with the key the given default string is returned.

### get

    public boolean get(java.lang.String key,
                       boolean dflt)

  Retrieves the element associated with the given key from this Anything and converts it to a boolean. If the Anything doesn't represent a dictionary or if there is no element associated with the key the given default boolean is returned.

### getBytes

    public byte[] getBytes(java.lang.String key)

  Retrieves the element associated with the given key from this Anything and converts it to a byte array. If the Anything doesn't represent a dictionary or if there is no element associated with the key null is returned.

### getType

    public int getType()

  Retrieve the tag from the Anything.

### isDefined

    public boolean isDefined(java.lang.String key)

  Determines whether the given key is in this Anything.

### isNull

    public boolean isNull()

  Is the Anything empty?

### keys

    public java.util.Enumeration keys()

  Gets all slot names (keys) of the Anything If the Anything doesn't represent a dictionary or if the index is out of bounds null is returned.
  Returns:
    java.util.Enumeration

### main

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

  A unit test :-)

### put

    public void put(int index,
                    Anything value)

  Replaces the element at the specified index in this vector. If the Anything doesn't represent a vector it is converted to a vector first.

### put

    public void put(java.lang.String key,
                    byte[] value)

  Stores the given byte array value under the given key in this Anything.

### put

    public void put(java.lang.String key,
                    double value)

  Stores the given double value under the given key in this Anything.

### put

    public void put(java.lang.String key,
                    int value)

  Stores the given int value under the given key in this Anything.

### put

    public void put(java.lang.String key,
                    long value)

  Stores the given long value under the given key in this Anything.

### put

    public void put(java.lang.String key,
                    Anything value)

  Stores the given value under the given key in this Anything. If the Anything doesn't represent a dictionary it is converted to a dictionary first.

### put

    public void put(java.lang.String key,
                    java.io.Serializable o)

### put

    public void put(java.lang.String key,
                    java.lang.String value)

  Stores the given String value under the given key in this Anything.

### put

    public void put(java.lang.String key,
                    boolean value)

  Stores the given boolean value under the given key in this Anything.

### read

    public static Anything read(java.io.InputStream in)

  Read an Anything from the given stream. In case of errors null is returned. This method is able to detect both formats automatically and uses either an AnythingReader or an AnythingReader2.

### read

    public static Anything read(java.lang.String filename)

  Read an Anything from the given file. In case of errors null is returned. This method is able to detect both formats automatically and uses either an AnythingReader or an AnythingReader2.

### remove

    public void remove(int ix)

  Removes the element at the specified index from this vector.

### size

    public int size()

  The size of the Anything. The size of an empty (null) Anything is 0. The Size of Anythings representing simple types (boolean, long, double, String, byte[]) is 1. For Anythings representing the structured types vector and dictionary the number of slots is returned.

### slotName

    public java.lang.String slotName(int ix)

  Gets the slot name (key) at the given index. If the Anything doesn't represent a dictionary or if the index is out of bounds null is returned.

### toString

    public java.lang.String toString()

  Generates the string representation of this Anything.
  Overrides:
    toString in class java.lang.Object

### values

    public java.util.Enumeration values()

  Retrieves the values of this Anything

### write

    public void write(java.io.OutputStream out,
                      IAnythingWriter format)

  Writes the Anything to the specified stream using the given format.

### write

    public void write(java.lang.String filename)

  Write the Anything to the given file by using the pretty printing format.
  See Also:
    `AnythingWriter`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD