Class RelationSet
- java.lang.Object
-
- com.caplin.management.jmx.relations.RelationSet
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable
,java.util.Collection
,java.util.Set
public class RelationSet extends java.lang.Object implements java.util.Set, java.io.Serializable
Represents a "to many" relationship, where a particular MBean attribute defines a link between that MBean and many other MBeans. All of the elements returned from a RelationSet should be of the type
ObjectNameLink
.Once the initial state of a RelationSet has been obtained, it can be kept up to date with the server by registering the NotificationListener returned by the
getNotificationListener()
method and the NotificationFilter returned by thegetNotificationFilter()
method with the MBean server (e.g.mbeanServer.addNotificationListener(objectName, relationSet.getNotificationListener(), relationSet.getNotificationFilter(), null);
). Updates to the RelationSet can be handled by registering aRelationSetUpdateListener
via theaddUpdateListener(RelationSetUpdateListener)
method.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RelationSet(javax.management.ObjectName sourceObjectName, java.lang.String attributeName)
Constructs a RelationSet with the specified source ObjectName and attribte name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(java.lang.Object object)
Adds the specified element to this set if it is not already present.boolean
addAll(java.util.Collection collection)
Adds all of the elements in the specified collection to this set if they're not already present.boolean
addUpdateListener(RelationSetUpdateListener updateListener)
Adds the specified RelationSetUpdateListener to the RelationSet.void
clear()
Removes all of the elements from this set.boolean
contains(java.lang.Object object)
Returnstrue
if this set contains the specified element.boolean
containsAll(java.util.Collection collection)
Returnstrue
if this set contains all of the elements of the specified collection.javax.management.NotificationFilter
getNotificationFilter()
Gets a notification filter that will only enable notifications that apply to this RelationSet.javax.management.NotificationListener
getNotificationListener()
Gets a notification listener that will automatically process any Notifications it receives to update this RelationSet's internal state.boolean
isEmpty()
Returnstrue
if this set contains no elements.java.util.Iterator
iterator()
Returns an iterator over the elements in this set.boolean
remove(java.lang.Object object)
Removes the specified element from this set if it is present.boolean
removeAll(java.util.Collection collection)
Removes from this set all of its elements that are contained in the specified collection.boolean
removeUpdateListener(RelationSetUpdateListener updateListener)
Removes the specified RelationSetUpdateListener from the RelationSet.boolean
retainAll(java.util.Collection collection)
Retains only the elements in this set that are contained in the specified collection.int
size()
Returns the number of elements in this set (its cardinality).java.lang.Object[]
toArray()
Returns an array containing all of the elements in this set.java.lang.Object[]
toArray(java.lang.Object[] array)
Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.
-
-
-
Constructor Detail
-
RelationSet
public RelationSet(javax.management.ObjectName sourceObjectName, java.lang.String attributeName)
Constructs a RelationSet with the specified source ObjectName and attribte name.
- Parameters:
sourceObjectName
- The ObjectName of the MBean that the RelationSet belongs to.attributeName
- The name of the attribute the RelationSet was obtained from.- Throws:
java.lang.IllegalArgumentException
- If either the sourceObjectName or attributeName arguments arenull
.
-
-
Method Detail
-
size
public int size()
Returns the number of elements in this set (its cardinality).
- Specified by:
size
in interfacejava.util.Collection
- Specified by:
size
in interfacejava.util.Set
- Returns:
- The number of elements in this set (its cardinality).
-
isEmpty
public boolean isEmpty()
Returns
true
if this set contains no elements.- Specified by:
isEmpty
in interfacejava.util.Collection
- Specified by:
isEmpty
in interfacejava.util.Set
- Returns:
true
if this set contains no elements.
-
contains
public boolean contains(java.lang.Object object)
Returns
true
if this set contains the specified element.- Specified by:
contains
in interfacejava.util.Collection
- Specified by:
contains
in interfacejava.util.Set
- Parameters:
object
- Element whose presence in this set is to be tested.- Returns:
true
if this set contains the specified element.
-
iterator
public java.util.Iterator iterator()
Returns an iterator over the elements in this set. The elements are returned in no particular order.
- Specified by:
iterator
in interfacejava.util.Collection
- Specified by:
iterator
in interfacejava.lang.Iterable
- Specified by:
iterator
in interfacejava.util.Set
- Returns:
- An Iterator over the elements in this set.
-
toArray
public java.lang.Object[] toArray()
Returns an array containing all of the elements in this set. Obeys the general contract of the
Collection.toArray
method.- Specified by:
toArray
in interfacejava.util.Collection
- Specified by:
toArray
in interfacejava.util.Set
- Returns:
- An array containing all of the elements in this set.
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] array)
Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. Obeys the general contract of the
Collection.toArray(Object[])
method.- Specified by:
toArray
in interfacejava.util.Collection
- Specified by:
toArray
in interfacejava.util.Set
- Parameters:
array
- the array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
- An array containing the elements of this set.
- Throws:
java.lang.ArrayStoreException
- If the runtime type of a is not a supertype of the runtime type of every element in this set.java.lang.NullPointerException
- If the specified array isnull
.
-
add
public boolean add(java.lang.Object object)
Adds the specified element to this set if it is not already present.
- Specified by:
add
in interfacejava.util.Collection
- Specified by:
add
in interfacejava.util.Set
- Parameters:
object
- element to be added to this set.- Returns:
true
if the set did not already contain the specified element.
-
remove
public boolean remove(java.lang.Object object)
Removes the specified element from this set if it is present.
- Specified by:
remove
in interfacejava.util.Collection
- Specified by:
remove
in interfacejava.util.Set
- Parameters:
object
- Object to be removed from this set, if present.- Returns:
true
if the set contained the specified element.
-
containsAll
public boolean containsAll(java.util.Collection collection)
Returns
true
if this set contains all of the elements of the specified collection. If the specified collection is also a set, this method returnstrue
if it is a subset of this set.- Specified by:
containsAll
in interfacejava.util.Collection
- Specified by:
containsAll
in interfacejava.util.Set
- Parameters:
collection
- Collection to be checked for containment in this set.- Returns:
true
if this set contains all of the elements of the specified collection.- Throws:
java.lang.NullPointerException
- if the specified collection isnull
.- See Also:
contains(Object)
-
addAll
public boolean addAll(java.util.Collection collection)
Adds all of the elements in the specified collection to this set if they're not already present. If the specified collection is also a set, the
addAll
operation effectively modifies this set so that its value is the union of the two sets. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress.- Specified by:
addAll
in interfacejava.util.Collection
- Specified by:
addAll
in interfacejava.util.Set
- Parameters:
collection
- Collection whose elements are to be added to this set.- Returns:
true
if this set changed as a result of the call.- Throws:
java.lang.IllegalArgumentException
- If some aspect of some element of the specified collection prevents it from being added to this set.- See Also:
add(Object)
-
retainAll
public boolean retainAll(java.util.Collection collection)
Retains only the elements in this set that are contained in the specified collection. In other words, removes from this set all of its elements that are not contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the intersection of the two sets.
- Specified by:
retainAll
in interfacejava.util.Collection
- Specified by:
retainAll
in interfacejava.util.Set
- Parameters:
collection
- Collection that defines which elements this set will retain.- Returns:
true
if this collection changed as a result of the call.- Throws:
java.lang.NullPointerException
- If the specified collection isnull
.- See Also:
remove(Object)
-
removeAll
public boolean removeAll(java.util.Collection collection)
Removes from this set all of its elements that are contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.
- Specified by:
removeAll
in interfacejava.util.Collection
- Specified by:
removeAll
in interfacejava.util.Set
- Parameters:
collection
- Collection that defines which elements will be removed from this set.- Returns:
true
if this set changed as a result of the call.- Throws:
java.lang.NullPointerException
- If the specified collection isnull
.- See Also:
remove(Object)
-
clear
public void clear()
Removes all of the elements from this set.
- Specified by:
clear
in interfacejava.util.Collection
- Specified by:
clear
in interfacejava.util.Set
-
getNotificationFilter
public javax.management.NotificationFilter getNotificationFilter()
Gets a notification filter that will only enable notifications that apply to this RelationSet. It is recommended that this is used in conjunction with the NotificationListener returned by
getNotificationListener()
.- Returns:
- A notification filter that will only enable notifications that apply to this RelationSet.
-
getNotificationListener
public javax.management.NotificationListener getNotificationListener()
Gets a notification listener that will automatically process any Notifications it receives to update this RelationSet's internal state. It is recommended that this is used in conjunction with the NotificationFilter returned by
getNotificationFilter()
.- Returns:
- A notification listener that will automatically process any Notifications it receives to update this RelationSet's internal state.
-
addUpdateListener
public boolean addUpdateListener(RelationSetUpdateListener updateListener)
Adds the specified RelationSetUpdateListener to the RelationSet. Every update listener that has been registered with the RelationSet will be informed whenever the RelationSet receives a notification that an element has been added or removed.
- Parameters:
updateListener
- The update listener to add to the RelationSet.- Returns:
true
if the specified update listener has not previously been added to the RelationSet, otherwisefalse
.- Throws:
java.lang.IllegalArgumentException
- If the updateListener argument is null.
-
removeUpdateListener
public boolean removeUpdateListener(RelationSetUpdateListener updateListener)
Removes the specified RelationSetUpdateListener from the RelationSet. The update listener will no longer be informed of any element added/removed changes to the RelationSet.
- Parameters:
updateListener
- The update listener to remove from the RelationSet.- Returns:
true
if the specified update listener had been registered with the RelationSet, otherwisefalse
.- Throws:
java.lang.IllegalArgumentException
- If the updateListener argument is null.
-
-