Class NamespaceUtil

java.lang.Object
com.pervasive.datarush.namespace.NamespaceUtil

public class NamespaceUtil extends Object
A collection of utility methods for working with Namespaces.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Namespace<T>
    merge(Namespace<? extends T>... namespaces)
    Merges the specified namespaces into a new namespace, handling name collisions by renaming.
    static <T> Namespace<T>
    overlay(Namespace<? extends T>... namespaces)
    Merges the specified namespaces into a new namespace, handling name collisions with a last-one-wins mechanism.
    static <T> Namespace<T>
    remove(Namespace<T> namespace, String... excludeFields)
    Creates a new namespace from an existing one, removing any fields matching the provided set of names.
    static <T> Namespace<T>
    remove(Namespace<T> namespace, Collection<String> excludeFields)
    Creates a new namespace from an existing one, removing any fields matching the provided set of names.
    static <T> Namespace<T>
    retain(Namespace<T> namespace, String... retainFields)
    Creates a new namespace from an existing one, copying any fields matching the provided set of names.
    static <T> Namespace<T>
    retain(Namespace<T> namespace, Collection<String> retainFields)
    Creates a new namespace from an existing one, copying any fields contained the provided set of names.
    static <T> Namespace<T>
    select(Namespace<T> namespace, String... selectFields)
    Creates a new namespace from an existing one, copying the specified fields.
    static <T> Namespace<T>
    select(Namespace<T> namespace, List<String> selectFields)
    Creates a new namespace from an existing one, copying the specified fields.
    static <T> Namespace<T>
    wrap(String prefix, List<? extends T> flows)
    Creates a new namespace with the specified flows.
    static <T> Namespace<T>
    wrap(String name, T flow)
    Creates a new namespace with specified flow as the named field.
    static <T> Namespace<T>
    wrap(String prefix, T... flows)
    Creates a new namespace with the specified flows.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NamespaceUtil

      public NamespaceUtil()
  • Method Details

    • retain

      public static <T> Namespace<T> retain(Namespace<T> namespace, Collection<String> retainFields)
      Creates a new namespace from an existing one, copying any fields contained the provided set of names. That is, create a copy with all fields not contained in the list removed. The order of fields in the result is unchanged; fields remain in the same relative order as in the source namespace.

      Unlike select(Namespace, String...), the provided names do not have to be valid fields in the namespace.

      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      namespace - the source namespace to copy
      retainFields - the names of fields which should be copied
      Returns:
      a new namespace containing only fields in the provided set.
    • retain

      public static <T> Namespace<T> retain(Namespace<T> namespace, String... retainFields)
      Creates a new namespace from an existing one, copying any fields matching the provided set of names. That is, create a copy with all fields not contained in the list removed. The order of fields in the result is unchanged; fields remain in the same relative order as in the source namespace.

      Unlike select(Namespace, String...), the provided names do not have to be valid fields in the namespace.

      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      namespace - the source namespace to copy
      retainFields - the names of fields which should be copied
      Returns:
      a new namespace containing only fields in the provided set.
    • remove

      public static <T> Namespace<T> remove(Namespace<T> namespace, Collection<String> excludeFields)
      Creates a new namespace from an existing one, removing any fields matching the provided set of names. The order of fields in the result is unchanged; fields remain in the same relative order as in the source namespace.

      The provided names do not have to be valid fields in the namespace.

      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      namespace - the source namespace to copy
      excludeFields - the names of fields which should be dropped
      Returns:
      a new namespace containing only fields not in the provided set.
    • remove

      public static <T> Namespace<T> remove(Namespace<T> namespace, String... excludeFields)
      Creates a new namespace from an existing one, removing any fields matching the provided set of names. The order of fields in the result is unchanged; fields remain in the same relative order as in the source namespace.

      The provided names do not have to be valid fields in the namespace.

      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      namespace - the source namespace to copy
      excludeFields - the names of fields which should be dropped
      Returns:
      a new namespace containing only fields not in the provided set.
    • select

      public static <T> Namespace<T> select(Namespace<T> namespace, List<String> selectFields)
      Creates a new namespace from an existing one, copying the specified fields. All specified fields must exist in the namespace. Furthermore, the order of the fields in the result matches the order in the input list.
      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      namespace - the source namespace to copy
      selectFields - the names of fields which should be copied
      Returns:
      a new namespace containing the fields in the provided set.
    • select

      public static <T> Namespace<T> select(Namespace<T> namespace, String... selectFields)
      Creates a new namespace from an existing one, copying the specified fields. All specified fields must exist in the namespace. Furthermore, the order of the fields in the result matches the order in the input list.
      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      namespace - the source namespace to copy
      selectFields - the names of fields which should be copied
      Returns:
      a new namespace containing the fields in the provided set.
    • wrap

      public static <T> Namespace<T> wrap(String name, T flow)
      Creates a new namespace with specified flow as the named field.
      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      name - the name for the field
      flow - the flow containing the field data
      Returns:
      a new namespace with a single field mapped to the provided flow
    • wrap

      public static <T> Namespace<T> wrap(String prefix, T... flows)
      Creates a new namespace with the specified flows. Each flow is given a field name of prefix + i, where i is the flow's 0-based position in the input list.
      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      prefix - the field name prefix for each flow
      flows - the flows containing field data
      Returns:
      a new namespace with fields corresponding to the provided flows
    • wrap

      public static <T> Namespace<T> wrap(String prefix, List<? extends T> flows)
      Creates a new namespace with the specified flows. Each flow is given a field name of prefix + i, where i is the flow's 0-based position in the input list.
      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      prefix - the field name prefix for each flow
      flows - the flows containing field data
      Returns:
      a new namespace with fields corresponding to the provided flows
    • merge

      public static <T> Namespace<T> merge(Namespace<? extends T>... namespaces)
      Merges the specified namespaces into a new namespace, handling name collisions by renaming. The nth instance of a field name will have "_" appended to it.

      The following conditions will hold with respect to the ordering of fields in the result:

      • All fields from a namespace will be before any field from a namespace later in the input list.
      • All fields from a namespace will preserve their relative ordering.
      As an example, consider two namespaces - "A" which is ordered {"a", "c"} and "B" which is ordered {"b", "c"}. The resulting namespace will be {"a", "c", "b", "c_2"}; "c" conflicts, so is renamed. The flow associated with "c" is the one from namespace "A", with "c_2" the one from namespace "B".

      For a destructive merge which overwrites mappings in collision, use overlay(Namespace...) instead.

      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      namespaces - the namespaces to merge
      Returns:
      a new namespace representing the merge of the input namespaces
    • overlay

      public static <T> Namespace<T> overlay(Namespace<? extends T>... namespaces)
      Merges the specified namespaces into a new namespace, handling name collisions with a last-one-wins mechanism. Last is defined as the rightmost namespace in the input list containing the name in conflict.

      The following conditions will hold with respect to the ordering of fields in the result:

      • All fields from a namespace will be before any field from a namespace later in the input list.
      • All fields from a namespace will preserve their relative ordering except those colliding with a field from an earlier namespace. Those fields always occur before other fields in the namespace, in an ordering consistent with the first namespace containing each.
      As an example, consider two namespaces - "A" which is ordered {"a", "c"} and "B" which is ordered {"b", "c"}. The resulting namespace will be {"a", "c", "b"}; "c" conflicts, so it appears in an order consistent with "A", the first namespace containing it. Note however, the flow associated with "c" will be the one from namespace "B"; the flow associated with "c" in "A" is lost.

      For a non-destructive merge which doesn't replace collisions, use merge(Namespace...) instead.

      Type Parameters:
      T - the type of elements in the namespace
      Parameters:
      namespaces - the namespaces to merge
      Returns:
      a new namespace representing the merge of the input namespaces