Class BaseNCodec

    • Constructor Detail

      • BaseNCodec

        protected BaseNCodec​(BaseN base)
        Parameters:
        base - an object that represents the base-n encoding
      • BaseNCodec

        protected BaseNCodec​(BaseN base,
                             BaseNEncoder encoder,
                             BaseNDecoder decoder)
        Parameters:
        base - an object that represents the base-n encoding
        encoder - a functional encoder
        decoder - a functional decoder
    • Method Detail

      • newInstance

        public static BaseNCodec newInstance​(BaseN base)
        Static factory that returns a new instance of BaseNCodec using the specified BaseN. This method can be used if none of the existing concrete codecs of this package class is desired. The BaseNCodec objects provided by this method encode UUIDs using remainder operation (modulus), a common approach to encode integers. If you need a BaseN that is not available in this package, use the static factories newInstance(String) or newInstance(int).
        Parameters:
        base - an object that represents the base-n encoding
        Returns:
        a BaseNCodec
      • newInstance

        public static BaseNCodec newInstance​(int radix)
        Static factory that returns a new instance of BaseNCodec using the specified radix. This method can be used if none of the existing concrete codecs of this package class is desired. The BaseNCodec objects provided by this method encode UUIDs using remainder operator (modulus), a common approach to encode integers. The example below shows how to create a BaseNCodec for an hypothetical base-40 encoding that contains only letters. You only need to pass a number 40. The BaseNCodec instantiates a BaseN object internally. See BaseN.
         String radix = 40;
         BaseNCodec codec = BaseNCodec.newInstance(radix);
         
        If radix is greater than 36, the alphabet generated is a subset of the character sequence "0-9A-Za-z-_". Otherwise it is a subset of "0-9a-z". In the example above the resulting alphabet is "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd" (0-9A-Za-d).
        Parameters:
        radix - the radix to be used
        Returns:
        a BaseNCodec
      • newInstance

        public static BaseNCodec newInstance​(String alphabet)
        Static factory that returns a new instance of BaseNCodec using the specified alphabet. This method can be used if none of the existing concrete codecs of this package class is desired. The BaseNCodec objects provided by this method encode UUIDs using remainder operator (modulus), a common approach to encode integers. The example below shows how to create a BaseNCodec for an hypothetical base-26 encoding that contains only letters. You only need to pass a string with 26 characters. The BaseNCodec instantiates a BaseN object internally. See BaseN.
         String alphabet = "abcdefghijklmnopqrstuvwxyz";
         BaseNCodec codec = BaseNCodec.newInstance(alphabet);
         
        Alphabet strings similar to "a-f0-9" are expanded to "abcdef0123456789". The same example using the string "a-z" instead of "abcdefghijklmnopqrstuvwxyz":
         String alphabet = "a-z";
         BaseNCodec codec = BaseNCodec.newInstance(alphabet);
         
        Parameters:
        alphabet - the alphabet to be used
        Returns:
        a BaseNCodec
      • getBase

        public BaseN getBase()