org.hd.d.pg2k.svrCore
Class ROIntArray

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

public final class ROIntArray
extends java.lang.Object
implements java.io.Serializable, MemoryTools.Internable

An immutable, Serializable, wrapper for an int array. This enables int array data to be safely shared between multiple users, thus avoid copies and duplicates.

We clone at entry and exit and deserialisation to protect our internal data.

These instances are suitable for pooling with MemoryTools.intern().

Intended to be efficient on the wire and in memory.

See Also:
Serialized Form

Field Summary
static ROIntArray EMPTY
          Empty array.
private  int[] payload
          The (non-null) payload reference.
private static long serialVersionUID
          Unique Serialisation class ID.
 
Constructor Summary
ROIntArray(int[] data)
          Construct with (copy of) non-null data block.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Is equal to an instance with a payload of the same length and content; may be slow to compute.
 int get(int index)
          Get value at specified index.
 int[] getData()
          Get (a copy of) the entire data block.
 int[] getData(int start, int afterEnd)
          Get (a copy of) a portion of the data block.
 int hashCode()
          Compute a hash based on the length and some of the payload.
 int length()
          Get length of the data; non-negative.
protected  java.lang.Object readResolve()
          Deserialise: use constructor for validation, defensive copying, etc.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

payload

private final int[] payload
The (non-null) payload reference.


EMPTY

public static final ROIntArray EMPTY
Empty array.


serialVersionUID

private static final long serialVersionUID
Unique Serialisation class ID.

See Also:
Constant Field Values
Constructor Detail

ROIntArray

public ROIntArray(int[] data)
Construct with (copy of) non-null data block.

Parameters:
data - non-null array of bytes
Method Detail

getData

public int[] getData()
Get (a copy of) the entire data block.


getData

public int[] getData(int start,
                     int afterEnd)
Get (a copy of) a portion of the data block.


length

public int length()
Get length of the data; non-negative.


get

public int get(int index)
Get value at specified index.


hashCode

public int hashCode()
Compute a hash based on the length and some of the payload. This tries to fix the time taken to compute the hash even for large payloads at the cost of possible/probable extra collisions (as per the String experience).

This takes a fixed small number of sample points whose relative positions partly depend on the length, and the length itself is part of the hash.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Is equal to an instance with a payload of the same length and content; may be slow to compute.

Overrides:
equals in class java.lang.Object

readResolve

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


DHD Multimedia Gallery V1.53.0

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