Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.http.util

public final Class StringCache

extends Object
Class Inheritance
Imports
java.nio.charset.Charset, java.util.ArrayList, .HashMap, .Iterator, .TreeMap, java.util.logging.Level, .Logger, org.glassfish.grizzly.Grizzly

This class implements a String cache for ByteChunk and CharChunk.
Author
Remy Maucherat

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
protected static class

Field Summary

Modifier and TypeField and Description
pack-priv static int
accessCount

Access count.

pack-priv static StringCache.ByteEntry[]
bcCache

Cache for byte chunk.

pack-priv static int
bcCount

toString count for byte chunk.

pack-priv static final HashMap<StringCache.ByteEntry, int[]>
bcStats

Statistics hash map for byte chunk.

pack-priv static boolean
byteEnabled

Enabled ?

pack-priv static int
pack-priv static StringCache.CharEntry[]
ccCache

Cache for char chunk.

pack-priv static int
ccCount

toString count for char chunk.

pack-priv static final HashMap<StringCache.CharEntry, int[]>
ccStats

Statistics hash map for char chunk.

pack-priv static boolean
pack-priv static int
hitCount

Hit count.

private static final Logger
logger

Default Logger.

pack-priv static int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected static int
compare(ByteChunk name, byte[] compareTo)

Compare given byte chunk with byte array.

protected static int
compare(CharChunk name, char[] compareTo)

Compare given char chunk with char array.

protected static String
find(ByteChunk name)

Find an entry given its name in the cache and return the associated String.

protected static String
find(CharChunk name)

Find an entry given its name in the cache and return the associated String.

protected static int
findClosest(ByteChunk name, StringCache.ByteEntry[] array, int len)

Find an entry given its name in a sorted array of map elements.

protected static int
findClosest(CharChunk name, StringCache.CharEntry[] array, int len)

Find an entry given its name in a sorted array of map elements.

public static int
getAccessCount()

Returns: Returns the accessCount.

public static boolean
getByteEnabled()

Returns: Returns the enabled.

public static int
getCacheSize()

Returns: Returns the cacheSize.

public static boolean
getCharEnabled()

Returns: Returns the enabled.

public static int
getHitCount()

Returns: Returns the hitCount.

public static int
getTrainThreshold()

Returns: Returns the trainThreshold.

public static void
public static void
setByteEnabled(boolean
The enabled to set.
byteEnabled
)

public static void
setCacheSize(int
The cacheSize to set.
cacheSize
)

public static void
setCharEnabled(boolean
The enabled to set.
charEnabled
)

public static void
setTrainThreshold(int
The trainThreshold to set.
trainThreshold
)

public static String
public static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accessCountback to summary
pack-priv static int accessCount

Access count.

bcCacheback to summary
pack-priv static StringCache.ByteEntry[] bcCache

Cache for byte chunk.

bcCountback to summary
pack-priv static int bcCount

toString count for byte chunk.

bcStatsback to summary
pack-priv static final HashMap<StringCache.ByteEntry, int[]> bcStats

Statistics hash map for byte chunk.

byteEnabledback to summary
pack-priv static boolean byteEnabled

Enabled ?

cacheSizeback to summary
pack-priv static int cacheSize
ccCacheback to summary
pack-priv static StringCache.CharEntry[] ccCache

Cache for char chunk.

ccCountback to summary
pack-priv static int ccCount

toString count for char chunk.

ccStatsback to summary
pack-priv static final HashMap<StringCache.CharEntry, int[]> ccStats

Statistics hash map for char chunk.

charEnabledback to summary
pack-priv static boolean charEnabled
hitCountback to summary
pack-priv static int hitCount

Hit count.

loggerback to summary
private static final Logger logger

Default Logger.

trainThresholdback to summary
pack-priv static int trainThreshold

Constructor Detail

StringCacheback to summary
public StringCache()

Method Detail

compareback to summary
protected static int compare(ByteChunk name, byte[] compareTo)

Compare given byte chunk with byte array. Return -1, 0 or +1 if inferior, equal, or superior to the String.

compareback to summary
protected static int compare(CharChunk name, char[] compareTo)

Compare given char chunk with char array. Return -1, 0 or +1 if inferior, equal, or superior to the String.

findback to summary
protected static String find(ByteChunk name)

Find an entry given its name in the cache and return the associated String.

findback to summary
protected static String find(CharChunk name)

Find an entry given its name in the cache and return the associated String.

findClosestback to summary
protected static int findClosest(ByteChunk name, StringCache.ByteEntry[] array, int len)

Find an entry given its name in a sorted array of map elements. This will return the index for the closest inferior or equal item in the given array.

findClosestback to summary
protected static int findClosest(CharChunk name, StringCache.CharEntry[] array, int len)

Find an entry given its name in a sorted array of map elements. This will return the index for the closest inferior or equal item in the given array.

getAccessCountback to summary
public static int getAccessCount()
Returns:int

Returns the accessCount.

getByteEnabledback to summary
public static boolean getByteEnabled()
Returns:boolean

Returns the enabled.

getCacheSizeback to summary
public static int getCacheSize()
Returns:int

Returns the cacheSize.

getCharEnabledback to summary
public static boolean getCharEnabled()
Returns:boolean

Returns the enabled.

getHitCountback to summary
public static int getHitCount()
Returns:int

Returns the hitCount.

getTrainThresholdback to summary
public static int getTrainThreshold()
Returns:int

Returns the trainThreshold.

resetback to summary
public static void reset()
setByteEnabledback to summary
public static void setByteEnabled(boolean byteEnabled)
Parameters
byteEnabled:boolean

The enabled to set.

setCacheSizeback to summary
public static void setCacheSize(int cacheSize)
Parameters
cacheSize:int

The cacheSize to set.

setCharEnabledback to summary
public static void setCharEnabled(boolean charEnabled)
Parameters
charEnabled:boolean

The enabled to set.

setTrainThresholdback to summary
public static void setTrainThreshold(int trainThreshold)
Parameters
trainThreshold:int

The trainThreshold to set.

toStringback to summary
public static String toString(ByteChunk bc)
toStringback to summary
public static String toString(CharChunk cc)
org.glassfish.grizzly.http.util back to summary

protected Class StringCache.ByteEntry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public Charset
public byte[]
public String

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

charsetback to summary
public Charset charset
nameback to summary
public byte[] name
valueback to summary
public String value

Constructor Detail

ByteEntryback to summary
protected ByteEntry()

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
org.glassfish.grizzly.http.util back to summary

protected Class StringCache.CharEntry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public char[]
public String

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

nameback to summary
public char[] name
valueback to summary
public String value

Constructor Detail

CharEntryback to summary
protected CharEntry()

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override