Package com.gengoai

Class ParamMap<V extends ParamMap<V>>

    • Constructor Detail

      • ParamMap

        public ParamMap()
    • Method Detail

      • as

        public <Z extends V> Z as​(@NonNull
                                  @NonNull Class<Z> zClass)
        Attempts to cast this ParamMap as child class.
        Type Parameters:
        Z - the child type parameter
        Parameters:
        zClass - the child class
        Returns:
        this map as the given Child class
        Throws:
        IllegalArgumentException - if this class is not an instance of the given child class
      • copy

        public V copy()
        Description copied from interface: Copyable

        Makes a copy of this object.

        Specified by:
        copy in interface Copyable<V extends ParamMap<V>>
        Returns:
        A copy of this object.
      • get

        public <T> T get​(@NonNull
                         @NonNull ParameterDef<T> param)
        Gets the value of the given ParameterDef
        Type Parameters:
        T - the type of the Param parameter
        Parameters:
        param - the param whose value we want
        Returns:
        the value of the param
        Throws:
        IllegalArgumentException - if the parm is unknown to this map
      • get

        public <T> T get​(String param)
        Gets the value of the given ParameterDef name
        Type Parameters:
        T - the type of the Param parameter
        Parameters:
        param - the param whose value we want
        Returns:
        the value of the param
        Throws:
        IllegalArgumentException - if the parm is unknown to this map
      • getOrDefault

        public <T> T getOrDefault​(@NonNull
                                  @NonNull ParameterDef<T> param,
                                  T defaultValue)
        Gets the value of the given ParameterDef or the default value if the Param is not in the map
        Type Parameters:
        T - the type of the Param parameter
        Parameters:
        param - the param whose value we want
        defaultValue - the default value to return if the param is not in the map
        Returns:
        the value of the param or the default value if the Param is not in the map
      • getOrDefault

        public <T> T getOrDefault​(String param,
                                  T defaultValue)
        Gets the value of the given ParameterDef or the default value if the Param is not in the map
        Type Parameters:
        T - the type of the Param parameter
        Parameters:
        param - the param whose value we want
        defaultValue - the default value to return if the param is not in the map
        Returns:
        the value of the param or the default value if the Param is not in the map
      • getParam

        public <T> ParameterDef<T> getParam​(String name)
        Gets the ParameterDef with the given name in the map.
        Type Parameters:
        T - the Param type parameter
        Parameters:
        name - the name of the param
        Returns:
        the param
        Throws:
        IllegalArgumentException - if the parm is unknown to this map
      • parameter

        public <T> ParamMap.Parameter<T> parameter​(@NonNull
                                                   @NonNull ParameterDef<T> param,
                                                   T defValue)
        Creates a ParamMap.Parameter of the given ParameterDef with the given default value registering it with this ParamMap and returning the created Parameter.
        Type Parameters:
        T - the parameter type parameter
        Parameters:
        param - the parameter definition
        defValue - the default value
        Returns:
        the parameter
      • parameterNames

        public Set<String> parameterNames()
        Gets the parameter names associated with this ParamMap
        Returns:
        the set
      • set

        public <T> V set​(@NonNull
                         @NonNull ParameterDef<T> param,
                         T value)
        Sets the value for the given parameter
        Type Parameters:
        T - the type parameter
        Parameters:
        param - the param
        value - the value
        Returns:
        this ParamMap
      • set

        public <T> V set​(String param,
                         T value)
        Sets the value for the given parameter
        Type Parameters:
        T - the type parameter
        Parameters:
        param - the param
        value - the value
        Returns:
        this ParamMap
      • setAll

        public <T> T setAll​(@NonNull
                            @NonNull ParamMap<V> paramMap)
        Sets all values on this parameter map to those on the given parameter. It will ignore any parameters not defined on this parameter map.
        Type Parameters:
        T - the parameter map type parameter
        Parameters:
        paramMap - the parameter map
        Returns:
        this ParameterMap
      • update

        public V update​(@NonNull
                        @NonNull Consumer<V> updater)
        Updates the ParamMap using the given consumer.
        Parameters:
        updater - the updater
        Returns:
        this ParamMap