Package com.google.javascript.jscomp
Class Xid
- java.lang.Object
-
- com.google.javascript.jscomp.Xid
-
public class Xid extends java.lang.Object
A simple utility for shortening identifiers in a stable way. Generates short substitution strings deterministically, using a compact (1 to 6 characters in length) repesentation of a 32-bit hash of the key. The string is suitable to be used as a JavaScript or CSS identifier. Collisions are possible but unlikely, depending on the underlying hash algorithm used. This substitution scheme uses case-sensitive names for maximum compression. Digits are also allowed in all but the first character of a class name. There are a few characters allowed by the CSS grammar that we choose not to use (e.g. the underscore and hyphen), to keep names simple. Xid should maintain as minimal dependencies as possible to ease its integration with other tools, such as server side HTML generators.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Xid.HashFunction
Strategy for selecting the underlying hash code function to be used by Xid.
-
Constructor Summary
Constructors Constructor Description Xid()
Xid(Xid.HashFunction hasher)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
get(java.lang.String key)
Gets the string that should be substituted forkey
.int
getAsInt(java.lang.String key)
Returns the underlying integer representation of the given key.
-
-
-
Constructor Detail
-
Xid
public Xid()
-
Xid
public Xid(Xid.HashFunction hasher)
-
-
Method Detail
-
get
public java.lang.String get(java.lang.String key)
Gets the string that should be substituted forkey
. The same value will be consistently returned for any particularkey
.- Parameters:
key
- the text to be replaced (never null)- Returns:
- the value to substitute for
key
-
getAsInt
public int getAsInt(java.lang.String key)
Returns the underlying integer representation of the given key.
-
-