Class Expansion


  • @ExperimentalApi
    public class Expansion
    extends Object
    Represents an expansion tree. An expansion has the initial property to expand node and any sub properties will get collected in the subExpansions

    If its the root node it will only have children e.g. "a.b,c.d" will become an Expansion with a root node ("ROOT"), with two sub nodes "a" and "c"

    If its a sub node, it will have the name of the sub node, and its children. e.g. "a.c,a.b" will have "a" as the node and subExpansion of "c" and "b"

    • Method Detail

      • parse

        @NotNull
        public static @NotNull Expansion parse​(@Nullable
                                               @Nullable String string)
        Takes in expansion arguments and parses/splits/merges them into an expansion tree. Tree has a root node. Sub nodes may be empty representing no requested expands
        Parameters:
        string - to parse
        Returns:
        expansion with
      • getName

        @NotNull
        public @NotNull String getName()
        Returns:
        The name of the current node of expansion
      • isRoot

        public boolean isRoot()
        Returns:
        true if this node is the root node
      • getSubExpansions

        @NotNull
        public @NotNull Collection<Expansion> getSubExpansions()
        Returns:
        a collection of all sub expansions of this node
      • addSubExpansions

        public void addSubExpansions​(@Nullable
                                     @Nullable Collection<Expansion> expansions)
        Adds sub expansions to this expansion. If expansions with similar node names exist, it will me merged with existing nodes
        Parameters:
        expansions - to add
      • addSubExpansion

        public void addSubExpansion​(@Nullable
                                    @Nullable Expansion expansion)
        Adds a single sub expansion to this expansion. If expansions with similar node names exist, it will me merged with existing nodes
        Parameters:
        expansion - to add
      • canExpand

        public boolean canExpand​(@NotNull
                                 @NotNull String name)
        Check if the given property is a sub node of the current property
        Parameters:
        name - to check
        Returns:
        true if this sub expansion is included
      • canExpand

        public boolean canExpand()
        Check if the current property can be expanded
        Returns:
        true if the current property can be expanded
      • getExpansion

        @NotNull
        public @NotNull Expansion getExpansion​(@NotNull
                                               @NotNull String name)
        Get expansion at a specific sub node. Expansion will have all sub nodes of the sub node. If the expansion you are getting does not exist, NONE will be returned.
        Parameters:
        name - of the sub expansion to get
        Returns:
        Expansion for the sub node
      • getSubExpansion

        @NotNull
        public @NotNull Expansion getSubExpansion​(@NotNull
                                                  @NotNull String name)
        Get expansion at a specific sub node. Expansion will have all sub nodes of the sub node. The expansion you are getting must exist, so please use canExpand(String) first
        Parameters:
        name - of the sub expansion to get
        Returns:
        Expansion for the sub node
      • toParts

        @NotNull
        protected static @NotNull Pair<String,​String> toParts​(@NotNull
                                                                    @NotNull String expansionString)
        Split an expansion string into its first node and rest. e.g. one.two.three would become "one", "two.three"
        Parameters:
        expansionString - string to split
        Returns:
        pair containing the first node, and remaining nodes. If only one node, pair.snd will be null
      • toString

        public String toString()
        Flattens the tree into a string format
        Overrides:
        toString in class Object
        Returns:
        String representation of expansion map
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object