Class ModelNodeHelper


  • public class ModelNodeHelper
    extends Object
    Static helper methods for dealing with ModelNodes and NamedNodes. Some methods accept a path parameter separated by "/" to get a deeply nested data.
    • Method Detail

      • encodeValue

        public static String encodeValue​(String value)
      • decodeValue

        public static String decodeValue​(String value)
      • failSafeGet

        public static ModelNode failSafeGet​(ModelNode modelNode,
                                            String path)
        Tries to get a deeply nested model node from the specified model node. Nested paths must be separated with "/".
        Parameters:
        modelNode - The model node to read from
        path - A path separated with "/"
        Returns:
        The nested node or an empty / undefined model node
      • failSafeBoolean

        public static boolean failSafeBoolean​(ModelNode modelNode,
                                              String path)
        Tries to get a deeply nested boolean value from the specified model node. Nested paths must be separated with "/".
        Parameters:
        modelNode - The model node to read from
        path - A path separated with "/"
        Returns:
        the boolean value or false.
      • getOrDefault

        public static <T> T getOrDefault​(ModelNode modelNode,
                                         String attribute,
                                         Supplier<T> supplier,
                                         T defaultValue)
      • storeIndex

        public static <T extends ModelNode> void storeIndex​(List<T> modelNodes)
      • asEnumValue

        public static <E extends Enum<E>> E asEnumValue​(ModelNode modelNode,
                                                        String attribute,
                                                        Function<String,​E> valueOf,
                                                        E defaultValue)
        Looks for the specified attribute and tries to convert it to an enum constant using LOWER_HYPHEN.to(UPPER_UNDERSCORE, modelNode.get(attribute).asString()).
      • asEnumValue

        public static <E extends Enum<E>> E asEnumValue​(ModelNode modelNodeValue,
                                                        Function<String,​E> valueOf,
                                                        E defaultValue)
      • move

        public static void move​(ModelNode modelNode,
                                String source,
                                String destination)
        Moves an attribute to another destination. Both source and destination can be a paths.
      • properties

        public static ModelNode properties​(String... properties)
        Turns a list of properties (keys and values) into a model node.
        Parameters:
        properties - A list of properties with even size.
        Returns:
        a model node with the specified properties.
      • flatToNested

        public static ModelNode flatToNested​(ModelNode modelNode)
        Turns all properties which contain one or more '.' into nested model nodes.