Package ec.util

# Class Code

java.lang.Object
ec.util.Code

public class Code extends Object
Code provides some simple wrapper functions for encoding and decoding basic data types for storage in a pseudo-Java source code strings format. This differs from just "printing" them to string in that the actual precision of the object is maintained. Code attempts to keep the representations as "Java-like" as possible -- the exceptions being primarily floats and doubles, which are encoded as ints and longs. Encoding of objects and arrays is not supported. You'll have to handle that yourself. Strings are supported.

Everything is case-SENSITIVE. Here's the breakdown.

Type | Format
boolean | `true` or `false` (old style, case sensitive) or `T` or `F` (new style, case sensitive)
byte | `bbyte|`
short | `sshort|`
int | `iint|`
long | `llong|`
float | `ffloatConvertedToIntForStorage|humanReadableFloat|` or (only for reading in) f|humanReadableFloat|
float | `ddoubleConvertedToLongForStorage|humanReadableDouble|` or (only for reading in) d|humanReadableDouble|
char | standard Java char, except that the only valid escape sequences are: \0 \t \n \b \' \" \ u unicodeHex
string | standard Java string with \ u ...\ u Unicode escapes, except that the only other valid escape sequences are: \0 \t \n \b \' \"

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Code()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static DecodeReturn`
  `checkPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, then trims the line and checks the preamble.
  `static void`
  `decode(DecodeReturn d)`
  Decodes the next item out of a DecodeReturn and modifies the DecodeReturn to hold the results.
  `static String`
  `encode(boolean b)`
  Encodes a boolean.
  `static String`
  `encode(byte b)`
  Encodes a byte.
  `static String`
  `encode(char c)`
  Encodes a character.
  `static String`
  `encode(double d)`
  Encodes a double.
  `static String`
  `encode(float f)`
  Encodes a float.
  `static String`
  `encode(int i)`
  Encodes an int.
  `static String`
  `encode(long l)`
  Encodes a long.
  `static String`
  `encode(short s)`
  Encodes a short.
  `static String`
  `encode(String s)`
  Encodes a String.
  `static boolean`
  `readBooleanWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, skips past an expected preamble, and reads in a boolean value ("true" or "false") if there is one, and returns it.
  `static byte`
  `readByteWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, skips past an expected preamble, and reads in a byte if there is one, and returns it.
  `static char`
  `readCharacterWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, skips past an expected preamble, and reads in a character if there is one, and returns it.
  `static double`
  `readDoubleWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, skips past an expected preamble, and reads in a double if there is one, and returns it.
  `static float`
  `readFloatWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, skips past an expected preamble, and reads in a float if there is one, and returns it.
  `static int`
  `readIntegerWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, skips past an expected preamble, and reads in an integer if there is one, and returns it.
  `static long`
  `readLongWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, skips past an expected preamble, and reads in a long if there is one, and returns it.
  `static short`
  `readShortWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, skips past an expected preamble, and reads in a short if there is one, and returns it.
  `static String`
  `readStringWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)`
  Finds the next nonblank line, skips past an expected preamble, and reads in a string if there is one, and returns it.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Code

    public Code()

- ## Method Details

  - ### encode

    public static String encode(boolean b)
    Encodes a boolean.

  - ### encode

    public static String encode(byte b)
    Encodes a byte.

  - ### encode

    public static String encode(char c)
    Encodes a character.

  - ### encode

    public static String encode(short s)
    Encodes a short.

  - ### encode

    public static String encode(int i)
    Encodes an int.

  - ### encode

    public static String encode(long l)
    Encodes a long.

  - ### encode

    public static String encode(float f)
    Encodes a float.

  - ### encode

    public static String encode(double d)
    Encodes a double.

  - ### encode

    public static String encode(String s)
    Encodes a String.

  - ### decode

    public static void decode(DecodeReturn d)
    Decodes the next item out of a DecodeReturn and modifies the DecodeReturn to hold the results. See DecodeReturn for more explanations about how to interpret the results.

  - ### checkPreamble

    public static DecodeReturn checkPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, then trims the line and checks the preamble. Returns a DecodeReturn on the line if successful, else posts a fatal error. Sets the DecodeReturn's line number. The DecodeReturn has not yet been decoded. You'll need to do that with Code.decode(...)

  - ### readStringWithPreamble

    public static String readStringWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, skips past an expected preamble, and reads in a string if there is one, and returns it. Generates an error otherwise.

  - ### readCharacterWithPreamble

    public static char readCharacterWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, skips past an expected preamble, and reads in a character if there is one, and returns it. Generates an error otherwise.

  - ### readByteWithPreamble

    public static byte readByteWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, skips past an expected preamble, and reads in a byte if there is one, and returns it. Generates an error otherwise.

  - ### readShortWithPreamble

    public static short readShortWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, skips past an expected preamble, and reads in a short if there is one, and returns it. Generates an error otherwise.

  - ### readLongWithPreamble

    public static long readLongWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, skips past an expected preamble, and reads in a long if there is one, and returns it. Generates an error otherwise.

  - ### readIntegerWithPreamble

    public static int readIntegerWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, skips past an expected preamble, and reads in an integer if there is one, and returns it. Generates an error otherwise.

  - ### readFloatWithPreamble

    public static float readFloatWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, skips past an expected preamble, and reads in a float if there is one, and returns it. Generates an error otherwise.

  - ### readDoubleWithPreamble

    public static double readDoubleWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, skips past an expected preamble, and reads in a double if there is one, and returns it. Generates an error otherwise.

  - ### readBooleanWithPreamble

    public static boolean readBooleanWithPreamble(String preamble, EvolutionState state, LineNumberReader reader)
    Finds the next nonblank line, skips past an expected preamble, and reads in a boolean value ("true" or "false") if there is one, and returns it. Generates an error otherwise.