Top Description Inners Fields Constructors Methods
org.apache.tomcat.util.buf

public Class StringCache

extends Object
Class Inheritance
Imports
java.nio.charset.CharacterCodingException, .Charset, .CodingErrorAction, java.util.ArrayList, .HashMap, .Map.Entry, .Objects, .TreeMap, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.res.StringManager

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
protected static int
accessCount

Access count.

protected static volatile StringCache.ByteEntry[]
bcCache

Cache for byte chunk.

protected static int
bcCount

toString count for byte chunk.

protected static final HashMap<StringCache.ByteEntry, int[]>
bcStats

Statistics hash map for byte chunk.

protected static boolean
byteEnabled

Enabled ?

protected static int
protected static volatile StringCache.CharEntry[]
ccCache

Cache for char chunk.

protected static int
ccCount

toString count for char chunk.

protected static final HashMap<StringCache.CharEntry, int[]>
ccStats

Statistics hash map for char chunk.

protected static boolean
protected static int
hitCount

Hit count.

private static final Log
protected static final int
private static final StringManager
protected static int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected static final int

Returns:

-1, 0 or +1 if inferior, equal, or superior to the String.
compare
(ByteChunk
The name to compare
name
,
byte[]
The compared to data
compareTo
)

Compare given byte chunk with byte array.

protected static final int

Returns:

-1, 0 or +1 if inferior, equal, or superior to the String.
compare
(CharChunk
The name to compare
name
,
char[]
The compared to data
compareTo
)

Compare given char chunk with char array.

protected static final String

Returns:

the corresponding value
find
(ByteChunk
The name to find
name
)
Deprecated Unused.

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

protected static final String

Returns:

the corresponding value
find
(ByteChunk
The name to find
name
,
CodingErrorAction
Action to take if an malformed input is encountered
malformedInputAction
,
CodingErrorAction
Action to take if an unmappable character is encountered
unmappableCharacterAction
)

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

protected static final String

Returns:

the corresponding value
find
(CharChunk
The name to find
name
)

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

protected static final int

Returns:

the position of the best match
findClosest
(ByteChunk
The name to find
name
,
StringCache.ByteEntry[]
The array in which to look
array
,
int
The effective length of the array
len
)

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

protected static final int

Returns:

the position of the best match
findClosest
(CharChunk
The name to find
name
,
StringCache.CharEntry[]
The array in which to look
array
,
int
The effective length of the array
len
)

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

public int

Returns:

Returns the accessCount.
getAccessCount
()

public boolean

Returns:

Returns the enabled.
getByteEnabled
()

public int

Returns:

Returns the cacheSize.
getCacheSize
()

public boolean

Returns:

Returns the enabled.
getCharEnabled
()

public int

Returns:

Returns the hitCount.
getHitCount
()

public int

Returns:

Returns the trainThreshold.
getTrainThreshold
()

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

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

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

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

public static String
public static String
toString(ByteChunk bc, CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction)

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

Field Detail

accessCountback to summary
protected static int accessCount

Access count.

bcCacheback to summary
protected static volatile StringCache.ByteEntry[] bcCache

Cache for byte chunk.

bcCountback to summary
protected static int bcCount

toString count for byte chunk.

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

Statistics hash map for byte chunk.

byteEnabledback to summary
protected static boolean byteEnabled

Enabled ?

cacheSizeback to summary
protected static int cacheSize
ccCacheback to summary
protected static volatile StringCache.CharEntry[] ccCache

Cache for char chunk.

ccCountback to summary
protected static int ccCount

toString count for char chunk.

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

Statistics hash map for char chunk.

charEnabledback to summary
protected static boolean charEnabled
hitCountback to summary
protected static int hitCount

Hit count.

logback to summary
private static final Log log
maxStringSizeback to summary
protected static final int maxStringSize
smback to summary
private static final StringManager sm
trainThresholdback to summary
protected static int trainThreshold

Constructor Detail

StringCacheback to summary
public StringCache()

Method Detail

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

Compare given byte chunk with byte array.

Parameters
name:ByteChunk

The name to compare

compareTo:byte[]

The compared to data

Returns:int

-1, 0 or +1 if inferior, equal, or superior to the String.

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

Compare given char chunk with char array.

Parameters
name:CharChunk

The name to compare

compareTo:char[]

The compared to data

Returns:int

-1, 0 or +1 if inferior, equal, or superior to the String.

findback to summary
protected static final String find(ByteChunk name)

Deprecated

Unused. Will be removed in Tomcat 11. Use find(ByteChunk, CodingErrorAction, CodingErrorAction)

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

Parameters
name:ByteChunk

The name to find

Returns:String

the corresponding value

Annotations
@Deprecated
findback to summary
protected static final String find(ByteChunk name, CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction)

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

Parameters
name:ByteChunk

The name to find

malformedInputAction:CodingErrorAction

Action to take if an malformed input is encountered

unmappableCharacterAction:CodingErrorAction

Action to take if an unmappable character is encountered

Returns:String

the corresponding value

findback to summary
protected static final String find(CharChunk name)

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

Parameters
name:CharChunk

The name to find

Returns:String

the corresponding value

findClosestback to summary
protected static final 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.

Parameters
name:ByteChunk

The name to find

array:StringCache.ByteEntry[]

The array in which to look

len:int

The effective length of the array

Returns:int

the position of the best match

findClosestback to summary
protected static final 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.

Parameters
name:CharChunk

The name to find

array:StringCache.CharEntry[]

The array in which to look

len:int

The effective length of the array

Returns:int

the position of the best match

getAccessCountback to summary
public int getAccessCount()
Returns:int

Returns the accessCount.

getByteEnabledback to summary
public boolean getByteEnabled()
Returns:boolean

Returns the enabled.

getCacheSizeback to summary
public int getCacheSize()
Returns:int

Returns the cacheSize.

getCharEnabledback to summary
public boolean getCharEnabled()
Returns:boolean

Returns the enabled.

getHitCountback to summary
public int getHitCount()
Returns:int

Returns the hitCount.

getTrainThresholdback to summary
public int getTrainThreshold()
Returns:int

Returns the trainThreshold.

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

The enabled to set.

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

The cacheSize to set.

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

The enabled to set.

setTrainThresholdback to summary
public 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(ByteChunk bc, CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction) throws CharacterCodingException
toStringback to summary
public static String toString(CharChunk cc)
org.apache.tomcat.util.buf back to summary

private Class StringCache.ByteEntry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Charset
private CodingErrorAction
private byte[]
private CodingErrorAction
private String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
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
private Charset charset
malformedInputActionback to summary
private CodingErrorAction malformedInputAction
nameback to summary
private byte[] name
unmappableCharacterActionback to summary
private CodingErrorAction unmappableCharacterAction
valueback to summary
private String value

Constructor Detail

ByteEntryback to summary
private 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.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

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.
Returns:int

a hash code value for this object

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.

Returns:String

a string representation of the object

Annotations
@Override
org.apache.tomcat.util.buf back to summary

private Class StringCache.CharEntry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private char[]
private String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
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
private char[] name
valueback to summary
private String value

Constructor Detail

CharEntryback to summary
private 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.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

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.
Returns:int

a hash code value for this object

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.

Returns:String

a string representation of the object

Annotations
@Override