Annotation Type KeyedCompoundParm


@Retention(CLASS) @Target(FIELD) public @interface KeyedCompoundParm
Annotation for keyed parameters. The object annotated must be a field whose type implements the interface java.util.Map. with both type parameters provided. The type of the map's key must be the type of a named object, an Integer, a String, or an Enum (with a type parameter). The type of a value must be a class annotated with a @CompoundParmType annotation. This class must have a constructor with zero arguments and will have some or all of its fields annotated by a @PrimitiveParm annotation. For example,
    @CompoundParmType
    class MapValue {
       @PrimitiveParm("size")
       int size = 10;
       @PrimitiveParm("base")
       int base = 0;
    }

    @FactoryParmManager("OurFactoryParmManager")
    public class OurFactory<Obj extends NamedObject1> extends ... {
       @KeyedCompoundParm("map")
       Map<OurNamedObject,MapValue> hashmap = new HashMap<>();
       ...
    }
 
This will define factory parameters whose names are "map", "map.size" and "map.base". The parameters "map.size" and "map.base" will be initialized using a method named set that has three arguments: the parameter name, the key (of type OurNamedObject in this case), and a value (an int in this case). A delimiter is provided, that will be inserted after the string "map" in the name, with a default delimiter ".". If no delimiter is desired, set the delimiter to an empty string. For the parameter whose name is "map", the add method will create default entry for the keys, the remove method will allow all entries associated with a key to be removed, and the clear method with the parameter name will clear the table. For example,
    factory.set("object.base", 1, 20);
    factory.add("object", 2);
    factory.set("object.base", 3, 30);
 
will create the entries show in the following table:
 
keyobject.sizeobject.base
11020
2100
31030
Calling
    factory.remove("object", 1);
 
will remove the values whose key is 1. Calling
    factory.clear("object")
 
will remove all the keys associated with "object".

If a subclass of a factory defines the same keyed compound parameter, and the ParmManager defined is used in each factory's constructor, the primitive values set are the ones specified by both. For example,

    @CompoundParmType
    class MapValue2 {
       @PrimitiveParm("size2")
       int size2 = 100;
       @PrimitiveParm("base2")
       int base2 = 200;
    }

    @FactoryParmManager("OurFactory2ParmManager")
    public class OurFactory2<Obj extends NamedObject2>
       extends OurFactory<Obj>
    {
       @KeyedCompoundParm("map")
       Map<OurNamedObject,MapValue2> hashmap2 = new HashMap<>();
       ...
    }
 
will provide a factory with compound keys "object.size", "object.base", "object.size2", and "object.base2". If we set one entry for a key the remaining entries will be set to their default values. Thus, if the object factory is an instance of OurFactory2
    factory.set("object.base", 1, 20);
    factory.add("object", 2);
    factory.set("object.base", 3, 30);
 
will result in the values in the following table:
 
keyobject.sizeobject.base object.size2object.base2
11020100200
2100100200
31030100200
Similarly, the use of "remove" or "clear" will eliminate the same keys as in the previous example.
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The name of the key.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The delimiter separating the key's name from one of its value's names.
  • Element Details

    • value

      String value
      The name of the key.
      Returns:
      the name of the key
    • delimiter

      String delimiter
      The delimiter separating the key's name from one of its value's names.
      Returns:
      the delimiter
      Default:
      "."