Class 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.
    • 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 for key.
      int getAsInt​(java.lang.String key)
      Returns the underlying integer representation of the given key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • get

        public java.lang.String get​(java.lang.String key)
        Gets the string that should be substituted for key. The same value will be consistently returned for any particular key.
        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.