Class QueryParameters

java.lang.Object
com.vaadin.flow.router.QueryParameters
All Implemented Interfaces:
Serializable

public class QueryParameters extends Object implements Serializable
Holds query parameters information.
Since:
1.0.
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • QueryParameters

      public QueryParameters(Map<String,List<String>> parameters)
      Creates query parameters from parameter map.
      Parameters:
      parameters - the parameter map
  • Method Details

    • empty

      public static QueryParameters empty()
      Creates an empty query parameters information.
      Returns:
      query parameters information
    • full

      public static QueryParameters full(Map<String,String[]> parameters)
      Creates parameters from full representation, where each parameter name may correspond to multiple values.
      Parameters:
      parameters - query parameters map
      Returns:
      query parameters information
    • simple

      public static QueryParameters simple(Map<String,String> parameters)
      Creates parameters from simple representation, where each parameter name corresponds to a single value.
      Parameters:
      parameters - query parameters map
      Returns:
      query parameters information
    • of

      public static QueryParameters of(String key, String value)
      Creates parameters from given key-value pair.
      Parameters:
      key - the name of the parameter
      value - the value
      Returns:
      query parameters information
    • fromString

      public static QueryParameters fromString(String queryString)
      Creates parameters from a query string.

      Note that no length checking is done for the string. It is the responsibility of the caller (or the server) to limit the length of the query string.

      Parameters:
      queryString - the query string
      Returns:
      query parameters information
    • getParameters

      public Map<String,List<String>> getParameters()
      Returns query parameters information with support for multiple values corresponding to single parameter name.

      Example: https://example.com/?one=1&two=2&one=3 will result in the corresponding map: {"one" : [1, 3], "two": [2]}

      Returns:
      query parameters information
    • getParameters

      public List<String> getParameters(String key)
      Returns query parameter values mapped with the given key.

      Example: Calling the method with key "one" for a parameters like https://example.com/?one=1&two=2&one=3 will result in the corresponding list: [1, 3]

      Parameters:
      key - the key of query parameters to fetch
      Returns:
      query parameters or an empty list if there are no parameters with the given key
    • getSingleParameter

      public Optional<String> getSingleParameter(String key)
      Returns the first query parameter values mapped with the given key.

      Example: Calling with key value "one" with https://example.com/?one=1&two=2&one=3 will return 1

      Parameters:
      key - the key of query parameters to fetch
      Returns:
      query parameter value or empty if there are no parameters with the given key
    • getQueryString

      public String getQueryString()
      Returns a UTF-8 encoded query string containing all parameter names and values suitable for appending to a URL after the ? character. Parameters may appear in different order than in the query string they were originally parsed from, and may be differently encoded (for example, if a space was encoded as + in the initial URL it will be encoded as %20 in the result.
      Returns:
      query string suitable for appending to a URL
      See Also:
    • excluding

      public QueryParameters excluding(String... keys)
      Return new QueryParameters excluding given parameters by names.
      Parameters:
      keys - Names of the parameters to be excluded
      Returns:
      QueryParameters
    • including

      public QueryParameters including(String... keys)
      Return new QueryParameters including only the given parameters.
      Parameters:
      keys - Names of the parameters to be included
      Returns:
      QueryParameters.
    • merging

      public QueryParameters merging(String key, String... values)
      Return new QueryParameters adding given parameter to the existing ones. If a parameter with the same name is already present, its values will be replaced with the provided ones.
      Parameters:
      key - Parameter name as String
      values - Values for the parameter as Strings
      Returns:
      QueryParameters.
    • mergingAll

      public QueryParameters mergingAll(Map<String,List<String>> parameters)
      Return new QueryParameters including given parameters and the existing ones. Existing parameters will be replaced by the provided ones.
      Parameters:
      parameters - Map of new parameters to be included
      Returns:
      QueryParameters
    • toString

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

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

      public int hashCode()
      Overrides:
      hashCode in class Object