java.lang.Object
com.pervasive.datarush.namespace.NamespaceBuilder<T>
- Type Parameters:
T- the type of object stored in the namespace
- All Implemented Interfaces:
Iterable<T>
A mutable implementation of a
Namespace.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CollisionPolicy<?>Predefined collision policy throwing a DRException on a name collision.static final NamingPolicy<?>Predefined name generation policy throwing an exception.static final CollisionPolicy<?>Predefined collision policy retrying the name binding with a new name.static final CollisionPolicy<?>Predefined collision policy replacing the existing entry on a name collision. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new mutable namespace with collisions causing an error and no default name generation.NamespaceBuilder(CollisionPolicy<T> onCollision) Creates a new mutable namespace with the specified collision policy and no default name generation.NamespaceBuilder(CollisionPolicy<T> onCollision, NamingPolicy<T> defaultNaming) Creates a new mutable namespace with the specified collision and name generation policies.NamespaceBuilder(NamingPolicy<T> defaultNaming) Creates a new mutable namespace with collisions causing an error and the specified name generation policy. -
Method Summary
Modifier and TypeMethodDescriptionAdds an entry to the name space, associated with the given name.Add an entry to the namespace.voidAdd all entries from a namespace into this namespace.voidclear()Removes all entries from the namespace.get(int i) Gets the entry at the specified index.Gets the entry associated with the specified namefrom the namespace.getBinding(int i) Gets the name-entry association at the specified index.List<NameBinding<T>>Gets a collection of all the name-entry associations.getName(int i) Gets the name associated with entry at the specified index.String[]getNames()Gets all names registered in the namespace.intGets the index of the entry associated with the given name.final booleanisEmpty()Indicates whether the namespace is empty.iterator()nameSet()Get an unmodifiable collection of all names.Removes an entry from the namespace.static <T> NamespaceBuilder<T>Gets a mutable namespace with no default naming policy.static <T> NamespaceBuilder<T>sequencedNamespace(NamingPolicy<T> defaultNaming) Gets a mutable namespace using the specified default naming policy.voidsetListener(BindListener<T> listener) Attaches a listener for namespace entry assignment events.final intsize()Retrieves the number of elements in the namespace.Constructs the currently defined namespace.toString()static <T> NamespaceBuilder<T>Gets a mutable namespace with no default naming policy.static <T> NamespaceBuilder<T>uniqueNamespace(NamingPolicy<T> defaultNaming) Gets a mutable namespace using the specified default naming policy.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
FAIL_ON_COLLISION
Predefined collision policy throwing a DRException on a name collision. -
REPLACE_ON_COLLISION
Predefined collision policy replacing the existing entry on a name collision. -
RENAME_SEQUENTIALLY
Predefined collision policy retrying the name binding with a new name. The original name is repeatedly suffixed with an increasing number until a collision no longer exists. -
NO_DEFAULT_NAME
Predefined name generation policy throwing an exception. If used, theadd(Object)method will always fail.
-
-
Constructor Details
-
NamespaceBuilder
public NamespaceBuilder()Creates a new mutable namespace with collisions causing an error and no default name generation. -
NamespaceBuilder
Creates a new mutable namespace with the specified collision policy and no default name generation.- Parameters:
onCollision- the collision policy to use in the namespace
-
NamespaceBuilder
Creates a new mutable namespace with collisions causing an error and the specified name generation policy.- Parameters:
defaultNaming- the name generation strategy to use in the namespace
-
NamespaceBuilder
Creates a new mutable namespace with the specified collision and name generation policies.- Parameters:
onCollision- the collision policy to use in the namespacedefaultNaming- the name generation strategy to use in the namespace
-
-
Method Details
-
uniqueNamespace
Gets a mutable namespace with no default naming policy. An error is raised on name collisions; seeFAIL_ON_COLLISION.- Type Parameters:
T- the type of elements in the namespace- Returns:
- a builder for constructing a namespace
-
uniqueNamespace
Gets a mutable namespace using the specified default naming policy. An error is raised on name collisions; seeFAIL_ON_COLLISION.- Type Parameters:
T- the type of elements in the namespace- Parameters:
defaultNaming- the naming policy to use when adding elements without a name- Returns:
- a builder for constructing a namespace
-
sequencedNamespace
Gets a mutable namespace with no default naming policy. Collisions are resolved by appending a sequence number; seeRENAME_SEQUENTIALLY.- Type Parameters:
T- the type of elements in the namespace- Returns:
- a builder for constructing a namespace
-
sequencedNamespace
Gets a mutable namespace using the specified default naming policy. Collisions are resolved by appending a sequence number; seeRENAME_SEQUENTIALLY.- Type Parameters:
T- the type of elements in the namespace- Parameters:
defaultNaming- the naming policy to use when adding elements without a name- Returns:
- a builder for constructing a namespace
-
setListener
Attaches a listener for namespace entry assignment events. Only one listener at a time is supported; if a listener already exists, it will stop receiving events.- Parameters:
listener- the listener to attach
-
size
public final int size()Retrieves the number of elements in the namespace.- Returns:
- the count of elements
-
isEmpty
public final boolean isEmpty()Indicates whether the namespace is empty. This is equivalent to checkingsize() == 0.- Returns:
trueif empty,falseotherwise
-
add
Add an entry to the namespace. A name will be generated using the default naming policy. Name collisions are handled according to the collision policy in effect.- Parameters:
entry- the value to add to the namespace- Returns:
- the name assigned to the entry.
- Throws:
DRException- if one of the namespace policies is violated
-
add
Adds an entry to the name space, associated with the given name. Name collisions are handled according to the collision policy in effect.- Parameters:
name- the name to associate with the entryentry- the value to add to the namespace- Returns:
- the actual name associated with the entry. For some collision policies, this may be different than the supplied name.
- Throws:
DRException- if one of the namespace policies is violated
-
addAll
Add all entries from a namespace into this namespace. The given namespace is not modified. Name collisions are handled according to the collision policy in effect.- Parameters:
entries- source of namespace entries to add- Throws:
DRException- if one of the namespace policies is violated. No guarantee is made about the contents of the namespace if this occurs.
-
clear
public void clear()Removes all entries from the namespace. -
get
Gets the entry at the specified index. Indexing is based on the order in which the entries were added to the namespace.- Parameters:
i- index of the element to retrieve- Returns:
- the ith entry inserted into the namespace
- Throws:
IndexOutOfBoundsException- ifi < 0 || i >= size()
-
getBinding
Gets the name-entry association at the specified index. Indexing is based on the order in which the entries were added to the namespace.- Parameters:
i- index of the element to retrieve- Returns:
- the ith name-entry binding in the namespace
- Throws:
IndexOutOfBoundsException- ifi < 0 || i >= size()
-
indexOf
Gets the index of the entry associated with the given name.- Parameters:
name- the name of the entry to find- Returns:
- the index of the matching entry,
-1if no entry with the given name exists
-
get
Gets the entry associated with the specified namefrom the namespace.- Parameters:
name- the name of the entry to find- Returns:
- the associated entry, or
nullif there is no such entry
-
remove
Removes an entry from the namespace.- Parameters:
name- the name of the entry to remove- Returns:
- the entry with the specified name,
nullif there is no such entry
-
iterator
-
getName
Gets the name associated with entry at the specified index. Indexing is based on the order in which the entries were added to the namespace.- Parameters:
i- index of the element name to retrieve- Returns:
- the name of the ith entry inserted into the namespace
- Throws:
IndexOutOfBoundsException- ifi < 0 || i >= size()
-
getNames
Gets all names registered in the namespace. The names are ordered according to the order in which the entries were added.- Returns:
- the namespace's registered names
-
nameSet
Get an unmodifiable collection of all names. The order of entries when iterating over the set does not preserve the order in the namespace.- Returns:
- the set of the namespace's registered names
-
getBindings
Gets a collection of all the name-entry associations. The ordering of the result is the same as that of the namespace.- Returns:
- a list of bindings in the namespace
-
toNamespace
Constructs the currently defined namespace.- Returns:
- the namespace
-
toString
-