Class DataQuery

java.lang.Object
org.spongepowered.api.data.persistence.DataQuery
All Implemented Interfaces:
Iterable<String>

public final class DataQuery extends Object implements Iterable<String>
Represents a query that can be done on views. Queries do not depend on their separator, it is just a way to construct them.
  • Method Details

    • of

      public static DataQuery of()
      Gets an empty DataQuery. This query is constant and never changes and therefor can be called multiple times returning the same instance.
      Returns:
      An empty data query
    • of

      public static DataQuery of(char separator, String path)
      Constructs a query using the given separator character and path.

      As an example, new DataQuery('/', "a/b/c") and new DataQuery('.', "a.b.c") represent the same path but are constructed using different separators.

      Parameters:
      separator - The separator
      path - The path
      Returns:
      The newly constructed DataQuery
    • of

      public static DataQuery of(String... parts)
      Constructs a query using the given parts.
      Parameters:
      parts - The parts
      Returns:
      The newly constructed DataQuery
    • of

      public static DataQuery of(List<String> parts)
      Constructs a query using the given parts.
      Parameters:
      parts - The parts
      Returns:
      The newly constructed DataQuery
    • parts

      public List<String> parts()
      Gets the parts that make up this query. The returned list is immutable.
      Returns:
      The parts of this query
    • then

      public DataQuery then(DataQuery that)
      Returns a new query that is made up of this query's parts followed by the given query's parts.
      Parameters:
      that - The given query to follow this one
      Returns:
      The constructed query
    • then

      public DataQuery then(String that)
      Returns a new query that is made up of this query's parts followed by the given query.
      Parameters:
      that - The given query to follow this one
      Returns:
      The constructed query
    • queryParts

      public List<DataQuery> queryParts()
      Returns the parts of this query as individual queries. The returned list is immutable.
      Returns:
      The constructed queries
    • pop

      public DataQuery pop()
      Returns a DataQuery where the last node is "popped" off. If this query is already the top level query, then the of() is returned.
      Returns:
      The next level query
    • popFirst

      public DataQuery popFirst()
      Returns a DataQuery where the first node is "popped" off. If this query is already the top level query, then the of() is returned.
      Returns:
      The next level query
    • last

      public DataQuery last()
      Gets the last entry of this DataQuery. If this query is a single entry query or an empty query, it returns itself.
      Returns:
      The last entry as a data query, if not already last
    • asString

      public String asString(String separator)
      Gets this query as a string separated by the given separator.
      Parameters:
      separator - The separator
      Returns:
      This query as a string
    • asString

      public String asString(char separator)
      Gets this query as a string separated by the given separator character.
      Parameters:
      separator - The separator
      Returns:
      This query as a string
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • iterator

      public Iterator<String> iterator()
      Specified by:
      iterator in interface Iterable<String>
    • forEach

      public void forEach(Consumer<? super String> action)
      Specified by:
      forEach in interface Iterable<String>
    • spliterator

      public Spliterator<String> spliterator()
      Specified by:
      spliterator in interface Iterable<String>