APIdia Launch Partner
Top Description Fields Constructors Methods
sun.text

public final Class CompactByteArray

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
java.util.Arrays

class CompactATypeArray : use only on primitive data types Provides a compact way to store information that is indexed by Unicode values, such as character properties, types, keyboard values, etc.This is very useful when you have a block of Unicode data that contains significant values while the rest of the Unicode data is unused in the application or when you have a lot of redundance, such as where all 21,000 Han ideographs have the same value. However, lookup is much faster than a hash table. A compact array of any primitive data type serves two purposes: A compact array is composed of a index array and value array. The index array contains the indices of Unicode characters to the value array.
Author
Helena Shih
See Also
CompactIntArray, CompactShortArray

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private int[]
private static final int
private static final int
private short[]
private boolean
public static final int
UNICODECOUNT

The total number of Unicode characters.

private byte[]

Constructor Summary

AccessConstructor and Description
public
CompactByteArray(byte
the default value of the compact array.
defaultValue
)

Constructor for CompactByteArray.

public
CompactByteArray(short[]
the indices of the compact array.
indexArray
,
byte[]
the values of the compact array.
newValues
)

Constructor for CompactByteArray.

Method Summary

Modifier and TypeMethod and Description
pack-priv static final boolean
arrayRegionMatches(byte[] source, int sourceStart, byte[] target, int targetStart, int
the length to compare. The start indices and start+len must be valid.
len
)

Convenience utility to compare two arrays of doubles.

private final boolean
blockTouched(int i)

Query whether a specified block was "touched", i.e. had a value set.

public Object
clone()

Overrides java.lang.Object.clone.

Overrides Cloneable

public void
compact()

Compact the array.

public byte

Returns:

the mapped value of the given character
elementAt
(char
the character to get the mapped value with
index
)

Get the mapped value of a Unicode character.

public boolean

Returns:

true if the current compact array object is the same as the compact array object obj; false otherwise.
equals
(Object
the compact array object to be compared with this.
obj
)

Overrides java.lang.Object.equals.

Compares the equality of two compact array objects.

private void
expand()

Expanding takes the array back to a 65536 element array.

public short[]
getIndexArray()

For internal use only.

public byte[]
getStringArray()

For internal use only.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Generates the hash code for the compact array object

public void
setElementAt(char
the character to set the mapped value with
index
,
byte
the new mapped value
value
)

Set a new value for a Unicode character.

public void
setElementAt(char
the starting offset o of the range
start
,
char
the ending offset of the range
end
,
byte
the new mapped value
value
)

Set new values for a range of Unicode character.

private final void
touchBlock(int i, int value)

Remember that a specified block was "touched", i.e. had a value set.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

BLOCKCOUNTback to summary
private static final int BLOCKCOUNT
BLOCKMASKback to summary
private static final int BLOCKMASK
BLOCKSHIFTback to summary
private static final int BLOCKSHIFT
hashesback to summary
private int[] hashes
INDEXCOUNTback to summary
private static final int INDEXCOUNT
INDEXSHIFTback to summary
private static final int INDEXSHIFT
indicesback to summary
private short[] indices
isCompactback to summary
private boolean isCompact
UNICODECOUNTback to summary
public static final int UNICODECOUNT

The total number of Unicode characters.

valuesback to summary
private byte[] values

Constructor Detail

CompactByteArrayback to summary
public CompactByteArray(byte defaultValue)

Constructor for CompactByteArray.

Parameters
defaultValue:byte

the default value of the compact array.

CompactByteArrayback to summary
public CompactByteArray(short[] indexArray, byte[] newValues)

Constructor for CompactByteArray.

Parameters
indexArray:short[]

the indices of the compact array.

newValues:byte[]

the values of the compact array.

Exceptions
IllegalArgumentException:
If index is out of range.

Method Detail

arrayRegionMatchesback to summary
pack-priv static final boolean arrayRegionMatches(byte[] source, int sourceStart, byte[] target, int targetStart, int len)

Convenience utility to compare two arrays of doubles.

Parameters
len:int

the length to compare. The start indices and start+len must be valid.

blockTouchedback to summary
private final boolean blockTouched(int i)

Query whether a specified block was "touched", i.e. had a value set. Untouched blocks can be skipped when compacting the array

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Overrides Cloneable

compactback to summary
public void compact()

Compact the array.

elementAtback to summary
public byte elementAt(char index)

Get the mapped value of a Unicode character.

Parameters
index:char

the character to get the mapped value with

Returns:byte

the mapped value of the given character

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Compares the equality of two compact array objects.

Parameters
obj:Object

the compact array object to be compared with this.

Returns:boolean

true if the current compact array object is the same as the compact array object obj; false otherwise.

expandback to summary
private void expand()

Expanding takes the array back to a 65536 element array.

getIndexArrayback to summary
public short[] getIndexArray()

For internal use only. Do not modify the result, the behavior of modified results are undefined.

getStringArrayback to summary
public byte[] getStringArray()

For internal use only. Do not modify the result, the behavior of modified results are undefined.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Generates the hash code for the compact array object

setElementAtback to summary
public void setElementAt(char index, byte value)

Set a new value for a Unicode character. Set automatically expands the array if it is compacted.

Parameters
index:char

the character to set the mapped value with

value:byte

the new mapped value

setElementAtback to summary
public void setElementAt(char start, char end, byte value)

Set new values for a range of Unicode character.

Parameters
start:char

the starting offset o of the range

end:char

the ending offset of the range

value:byte

the new mapped value

touchBlockback to summary
private final void touchBlock(int i, int value)

Remember that a specified block was "touched", i.e. had a value set. Untouched blocks can be skipped when compacting the array