String instances which contain only ascii characters,
keyed by the byte[] representation (in ascii).
The values are stored in SoftReferences, allowing them to be garbage collected if not in use and there is
memory pressure.
Note
Instances are safe for concurrent use.
| Modifier and Type | Class and Description |
|---|---|
| private abstract static class | |
| private static class | AsciiStringInterner.
Instance used for inserting values into the cache. |
| private class | AsciiStringInterner.
Custom |
| private static class | AsciiStringInterner.
Only used for lookups, never to actually store entries. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final ConcurrentMap | cache
Contains the canonicalized values, keyed by the ascii |
| pack-priv final ReferenceQueue |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static boolean | arrayEquals(byte[] a, int aOffset, int aLength, byte[] b, int bOffset, int bLength)
Performs equality check between a and b (with corresponding offset/length values). |
| private void | |
| public String | |
| public String | Returns: DecodedString from bytes.The bytes of the String. Must not be bytes, int null.Offset into bytes to start. offset, int The number of bytes in bytes which are relevant. length, Encoding To use if non-ascii bytes seen. encoding)Produces a |
| private static int | Returns: hash code for relevant bytes, or0 if non-ascii bytes present.Generates a hash value for the relevant entries in bytes as long as all values are ascii ( |
| public boolean | |
| public String |
| cache | back to summary |
|---|---|
| pack-priv final ConcurrentMap<AsciiStringInterner. Contains the canonicalized values, keyed by the ascii | |
| refQueue | back to summary |
|---|---|
| pack-priv final ReferenceQueue<String> refQueue Used for | |
| AsciiStringInterner | back to summary |
|---|---|
| pack-priv AsciiStringInterner() | |
| arrayEquals | back to summary |
|---|---|
| pack-priv static boolean arrayEquals(byte[] a, int aOffset, int aLength, byte[] b, int bOffset, int bLength) Performs equality check between a and b (with corresponding offset/length values).
The | |
| cleanQueue | back to summary |
|---|---|
| private void cleanQueue() Process any entries in
| |
| getString | back to summary |
|---|---|
| public String getString(byte[] bytes, int offset, int length, Encoding encoding) throws IOException Produces a
If non-ascii bytes are discovered, the encoding will be used to
| |
| getStringIfPresent | back to summary |
|---|---|
| public String getStringIfPresent(byte[] bytes, int offset, int length, Encoding encoding) throws IOException Produces a
If all are valid ascii (i.e.
If non-ascii bytes are discovered, the encoding will be used to
| |
| hashKey | back to summary |
|---|---|
| private static int hashKey(byte[] bytes, int offset, int length) Generates a hash value for the relevant entries in bytes as long as all values are ascii (
| |
| putString | back to summary |
|---|---|
| public boolean putString(String val) Preemptively populates a value into the cache. This is intended to be used with
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| private final int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv abstract void | |
| public final boolean | equals(@Nullable Object
the reference object with which to compare. obj)Overrides java. Indicates whether some other object is "equal to" this one. |
| pack-priv abstract boolean | |
| pack-priv abstract boolean | |
| public final int |
| hash | back to summary |
|---|---|
| private final int hash | |
| BaseKey | back to summary |
|---|---|
| pack-priv BaseKey(int hash) | |
| appendString | back to summary |
|---|---|
| pack-priv abstract void appendString(StringBuilder sb) | |
| equals | back to summary |
|---|---|
| public final boolean equals(@Nullable Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
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. | |
| equals | back to summary |
|---|---|
| pack-priv abstract boolean equals(byte[] other, int offset, int length) | |
| equalsBytes | back to summary |
|---|---|
| pack-priv abstract boolean equalsBytes(AsciiStringInterner. | |
| hashCode | back to summary |
|---|---|
| public final int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
byte[] must be a copy
that will never be mutated.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final byte[] |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | appendString(StringBuilder sb)
Implements abstract org.
|
| public boolean | equals(byte[] other, int offset, int length)
Implements abstract org.
|
| pack-priv boolean | equalsBytes(AsciiStringInterner.
Implements abstract org.
|
| key | back to summary |
|---|---|
| pack-priv final byte[] key | |
| Key | back to summary |
|---|---|
| pack-priv Key(byte[] key, int hash) | |
| appendString | back to summary |
|---|---|
| pack-priv void appendString(StringBuilder sb) Implements abstract org.
| |
| equals | back to summary |
|---|---|
| public boolean equals(byte[] other, int offset, int length) Implements abstract org.
| |
| equalsBytes | back to summary |
|---|---|
| pack-priv boolean equalsBytes(AsciiStringInterner. Implements abstract org.
| |
SoftReference implementation which maintains a reference to the key in the cache,
which allows aggressive cleaning when garbage collector collects the String instance.
| Modifier and Type | Field and Description |
|---|---|
| private final AsciiStringInterner. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void |
| key | back to summary |
|---|---|
| private final AsciiStringInterner. | |
| StringReference | back to summary |
|---|---|
| pack-priv StringReference(AsciiStringInterner. | |
| dispose | back to summary |
|---|---|
| pack-priv void dispose() | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final byte[] | |
| pack-priv final int | |
| pack-priv final int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | appendString(StringBuilder sb)
Implements abstract org.
|
| public boolean | equals(byte[] other, int offset, int length)
Implements abstract org.
|
| pack-priv boolean | equalsBytes(AsciiStringInterner.
Implements abstract org.
|
| bytes | back to summary |
|---|---|
| pack-priv final byte[] bytes | |
| length | back to summary |
|---|---|
| pack-priv final int length | |
| offset | back to summary |
|---|---|
| pack-priv final int offset | |
| TempKey | back to summary |
|---|---|
| pack-priv TempKey(int hash, byte[] bytes, int offset, int length) | |
| appendString | back to summary |
|---|---|
| pack-priv void appendString(StringBuilder sb) Implements abstract org.
| |
| equals | back to summary |
|---|---|
| public boolean equals(byte[] other, int offset, int length) Implements abstract org.
| |
| equalsBytes | back to summary |
|---|---|
| pack-priv boolean equalsBytes(AsciiStringInterner. Implements abstract org.
| |