- java.lang.Object
-
- com.pervasive.datarush.namespace.NamespaceUtil
-
public class NamespaceUtil extends Object
A collection of utility methods for working withNamespace
s.
-
-
Constructor Summary
Constructors Constructor Description NamespaceUtil()
-
Method Summary
All Methods Static Methods Concrete Methods 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.
-
-
-
Method Detail
-
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 copyretainFields
- 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 copyretainFields
- 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 copyexcludeFields
- 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 copyexcludeFields
- 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 copyselectFields
- 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 copyselectFields
- 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 fieldflow
- 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 ofprefix + i
, wherei
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 flowflows
- 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 ofprefix + i
, wherei
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 flowflows
- 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.
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.
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
-
-