org.hd.d.pg2k.svrCore
Class CS8Bit

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.CS8Bit
All Implemented Interfaces:
java.io.Serializable, java.lang.CharSequence, MemoryTools.Internable, TextUtils.CharSequence8Bit

public final class CS8Bit
extends java.lang.Object
implements TextUtils.CharSequence8Bit, java.io.Serializable, MemoryTools.Internable

Immutable lightweight CharSequence holding 8-bit text only. Internally the text is stored as a byte[] for compactness.

Implements hashCode() and equals() so suitable as a hash key.

See Also:
Serialized Form

Field Summary
static CS8Bit EMPTY
          Empty sequence.
private  int hash
          Cache of the computed hash code.
private static long serialVersionUID
          Unique serialisation ID.
private  byte[] text
          The 8-bit text of this sequence; ever null but may be empty.
 
Constructor Summary
CS8Bit(byte[] d)
          Copy from byte array.
CS8Bit(java.lang.CharSequence other)
          Copy from another CharSequence, vetoing if any non-8-bit data.
CS8Bit(TextUtils.CharSequence8Bit other)
          Copy from another CharSequence8Bit (defensively).
CS8Bit(TextUtils.CharSequence8Bit other, int start, int end)
          Copy a sub-sequence of another CharSequence8Bit.
 
Method Summary
 char charAt(int index)
           
 boolean equals(java.lang.Object o)
          Equality depends on the entire content being the same.
 int hashCode()
          The hash is computed over the entire text as for String.
 int length()
           
private  void readObject(java.io.ObjectInputStream in)
          Deserialise.
protected  java.lang.Object readResolve()
          Deserialise: use constructor for validation, etc.
 TextUtils.CharSequence8Bit subSequence(int startSS, int endSS)
          Extract subsequence; never null.
 byte[] toByteArray()
          Create private byte[] copy for caller; never null.
 java.lang.String toString()
          Convert to String with same char sequence; never null.
private  void writeObject(java.io.ObjectOutputStream oos)
          Write out a minimally-redundant form of our internal information.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

text

private transient byte[] text
The 8-bit text of this sequence; ever null but may be empty.


hash

private transient int hash
Cache of the computed hash code. Not part of the permanent/serialised state of the object since easy to recompute.


serialVersionUID

private static final long serialVersionUID
Unique serialisation ID.

See Also:
Constant Field Values

EMPTY

public static final CS8Bit EMPTY
Empty sequence.

Constructor Detail

CS8Bit

public CS8Bit(byte[] d)
Copy from byte array.


CS8Bit

public CS8Bit(TextUtils.CharSequence8Bit other)
Copy from another CharSequence8Bit (defensively).


CS8Bit

public CS8Bit(TextUtils.CharSequence8Bit other,
              int start,
              int end)
Copy a sub-sequence of another CharSequence8Bit.

Parameters:
other - other sequence; never null
start - inclusive start index
end - exclusive end index

CS8Bit

public CS8Bit(java.lang.CharSequence other)
       throws java.lang.IllegalArgumentException
Copy from another CharSequence, vetoing if any non-8-bit data.

Throws:
java.lang.IllegalArgumentException
Method Detail

length

public int length()
Specified by:
length in interface java.lang.CharSequence

charAt

public char charAt(int index)
Specified by:
charAt in interface java.lang.CharSequence

subSequence

public TextUtils.CharSequence8Bit subSequence(int startSS,
                                              int endSS)
Extract subsequence; never null. Usually a very lightweight wrapper around this instance, but may be an outright copy for very short subsequences for efficiency.

Specified by:
subSequence in interface java.lang.CharSequence

toString

public final java.lang.String toString()
Convert to String with same char sequence; never null.

Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object

toByteArray

public final byte[] toByteArray()
Create private byte[] copy for caller; never null.

Specified by:
toByteArray in interface TextUtils.CharSequence8Bit

hashCode

public int hashCode()
The hash is computed over the entire text as for String.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Equality depends on the entire content being the same.

Overrides:
equals in class java.lang.Object

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Deserialise.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeObject

private void writeObject(java.io.ObjectOutputStream oos)
                  throws java.io.IOException
Write out a minimally-redundant form of our internal information. The more-efficient on-the-wire format also makes defensive reading easier.

We don't write *any* default state.

We must never be asked to serialise if we have a (non-null) dictionary.

We must never be asked to serialise if the text is too long for us to encode.

Throws:
java.io.IOException

readResolve

protected java.lang.Object readResolve()
Deserialise: use constructor for validation, etc. Also resolve all empty instances to a single value as a minor optimisation.


DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.