Class PrimitiveConstructor<KeyT extends Key,​PrimitiveT>


  • public abstract class PrimitiveConstructor<KeyT extends Key,​PrimitiveT>
    extends java.lang.Object
    Create Primitive objects from Key objects of a certain kind.

    This class should eventually be in Tinks public API -- however, it might still change before that. Note: Before making this public, the class name should be reconsidered. (Currently the desirable option "PrimitiveFactory" is unavailable because such a class already exists.)

    • Method Detail

      • constructPrimitive

        public abstract PrimitiveT constructPrimitive​(KeyT key)
                                               throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
      • getKeyClass

        public java.lang.Class<KeyT> getKeyClass()
      • getPrimitiveClass

        public java.lang.Class<PrimitiveT> getPrimitiveClass()
      • create

        public static <KeyT extends Key,​PrimitiveT> PrimitiveConstructor<KeyT,​PrimitiveT> create​(PrimitiveConstructor.PrimitiveConstructionFunction<KeyT,​PrimitiveT> function,
                                                                                                             java.lang.Class<KeyT> keyClass,
                                                                                                             java.lang.Class<PrimitiveT> primitiveClass)
        Creates a PrimitiveConstructor object.

        This function should only be used by Primitives authors, that is, end users should almost certainly avoid using this function directly, and instead use their respective Primitive's register() method.

        That being said, one typically creates a PrimitiveConstructor object by writing a function

        
         class MyClass {
           private static MyPrimitive getPrimitive(MyKey key)
                     throws GeneralSecurityException {
             ...
           }
         }
         
        This function can then be used to create a PrimitiveConstructor:
        
         PrimitiveConstructor<MyKey, MyPrimitive> serializer =
               PrimitiveConstructor.create(MyClass::getPrimitive, MyKey.class,
                                          MyPrimitive.class);
         
        -- and the resulting PrimitiveConstructor object can in turn be registered in a PrimitiveRegistry.