Package org.yamcs

Class Spec


  • public class Spec
    extends Object
    Specifies the valid structure of a YConfiguration instance. While not strictly 'validation', the spec also allows defining additional metadata like the 'default' keyword which is used in the merged result of a validation.
    • Field Detail

      • ANY

        public static final Spec ANY
        Spec implementation that allows any key.
    • Constructor Detail

      • Spec

        public Spec()
    • Method Detail

      • allowUnknownKeys

        public void allowUnknownKeys​(boolean allowUnknownKeys)
      • requireOneOf

        public void requireOneOf​(String... keys)
        Specify a set of keys of which at least one must be specified. Note that this not enforce that only one is specified. You can combine this check with mutuallyExclusive(String...) if that is required.
      • requireTogether

        public void requireTogether​(String... keys)
        Specify a set of keys that must appear together. This check only applies as soon as at least one of these keys has been specified.
      • mutuallyExclusive

        public void mutuallyExclusive​(String... keys)
        Specify a set of keys that are mutually exclusive. i.e. at most one of them may be specified.
      • when

        public Spec.WhenCondition when​(String key,
                                       Object value)
        Add a condition that is only verified when key.equals(value)
        Parameters:
        key - the name of an option
        value - the value that triggers the conditional check
        Returns:
        an instance of Spec.WhenCondition for further configuration options
      • validate

        public YConfiguration validate​(YConfiguration args)
                                throws ValidationException
        Validate the given arguments according to this spec.
        Parameters:
        args - the arguments to validate.
        Returns:
        the validation result where defaults have been added to the input arguments
        Throws:
        ValidationException - when the specified arguments did not match this specification
      • validate

        public Map<String,​Object> validate​(Map<String,​Object> args)
                                          throws ValidationException
        Validate the given arguments according to this spec.
        Parameters:
        args - the arguments to validate, keyed by argument name.
        Returns:
        the validation result where defaults have been added to the input arguments
        Throws:
        ValidationException - when the specified arguments did not match this specification
      • removeSecrets

        public Map<String,​Object> removeSecrets​(Map<String,​Object> unsafeArgs)
        Returns a copy of the given arguments but with all secret arguments recursively removed.

        This method does not validate the arguments, however it will throw random exceptions if the input does not match the expected structure. It is therefore best to validate the arguments before passing them.

      • maskSecrets

        public Map<String,​Object> maskSecrets​(Map<String,​Object> unsafeArgs)
        Returns a copy of the given arguments but with all secret arguments masked as *****.

        This method does not validate the arguments, however it will throw random exceptions if the input does not match the expected structure. It is therefore best to validate the arguments before passing them.