org.norther.tammi.core.base
Class AttributeSupport

java.lang.Object
  extended by org.norther.tammi.core.base.AttributeSupport
All Implemented Interfaces:
Serializable

public class AttributeSupport
extends Object
implements Serializable

A support class for maintaining MBean attributes.

Version:
$Id: AttributeSupport.java,v 1.18 2009/11/13 16:31:45 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
AttributeSupport(MBeanDelegate adapter)
          Constructs a new attribute support.
 
Method Summary
<V> boolean
addAttributeValue(String name, String type, Collection<V> c, int index, V value)
          Adds a multi-valued attribute value at the specified position.
<V> boolean
addAttributeValue(String name, String type, Collection<V> c, V value)
          Adds a multi-valued attribute value.
<K,V> boolean
addAttributeValue(String name, String type, ConcurrentMap<K,Collection<V>> map, K key, int index, V value)
          Adds a multi-valued key attribute value at the specified position.
<K,V> boolean
addAttributeValue(String name, String type, ConcurrentMap<K,Collection<V>> map, K key, V value)
          Adds a multi-valued key attribute value.
 int attributeIndexOf(Object[] values, Object value)
          Returns index of a multi-valued attribute value.
<K> Set<K>
attributeKeySet(ConcurrentMap<K,?> map)
          Returns a read-only set of attribute keys.
 Set<String> attributeKeySet(ConcurrentMap<String,?> map, String prefix)
          Returns a read-only set of prefixed attribute keys.
<V> V[]
clearAttribute(String name, String type, Collection<V> c)
          Clears a multi-valued attribute.
<K,V> V[]
clearAttribute(String name, String type, ConcurrentMap<K,Collection<V>> map, Object key)
          Clears a multi-valued key attribute.
<K> boolean
clearAttributes(String name, String type, ConcurrentMap<K,?> map)
          Clears all key attributes.
 boolean clearAttributes(String name, String type, ConcurrentMap<String,?> map, String prefix)
          Clears prefixed key attributes.
<K,V> boolean
containsAttribute(ConcurrentMap<K,V> map, Object key)
          Checks a key attribute.
<K,V> V
getAttributeValue(ConcurrentMap<K,V> map, Object key)
          Gets the value of a key attribute.
<V> V[]
getAttributeValues(Collection<V> c)
          Gets values of a multi-valued attribute.
<K,V> V[]
getAttributeValues(ConcurrentMap<K,Collection<V>> map, Object key)
          Gets values of a multi-valued key attribute.
<K,V> V
removeAttribute(String name, String type, ConcurrentMap<K,V> map, Object key)
          Removes a key attribute.
<V> V
removeAttributeValue(String name, String type, Collection<V> c, int index)
          Removes an indexed multi-valued attribute value.
<V> boolean
removeAttributeValue(String name, String type, Collection<V> c, Object value)
          Removes a multi-valued attribute value.
<K,V> V
removeAttributeValue(String name, String type, ConcurrentMap<K,Collection<V>> map, int index, Object key)
          Removes an indexed multi-valued attribute value.
<K,V> boolean
removeAttributeValue(String name, String type, ConcurrentMap<K,Collection<V>> map, Object key, Object value)
          Removes a multi-valued key attribute value.
<K,V> void
setAttributeValue(String name, String type, ConcurrentMap<K,List<V>> map, K key, int index, V value)
          Sets a multi-valued key attribute value at the specified position.
<K,V> V
setAttributeValue(String name, String type, ConcurrentMap<K,V> map, K key, V value)
          Sets the value of a key attribute.
<V> void
setAttributeValue(String name, String type, List<V> l, int index, V value)
          Sets a multi-valued attribute value at the specified position.
<K,V> V
setAttributeValue(String name, String type, OrderedMap<K,V> map, int index, K key, V value)
          Sets an indexed value for a key attribute.
<K,V> boolean
setAttributeValueIfAbsent(String name, String type, ConcurrentMap<K,V> map, K key, V value)
          Sets a missing value for a key attribute.
<V> V[]
setAttributeValues(String name, String type, Collection<V> c, V[] values)
          Sets values of a multi-valued attribute.
<K,V> V[]
setAttributeValues(String name, String type, ConcurrentMap<K,Collection<V>> map, K key, V[] values)
          Sets values of a multi-valued key attribute.
<K,V> void
setAttributeValues(String name, String type, ConcurrentMap<K,V> map, Map<K,V> values)
          Sets values of key attributes without clearing existing ones.
<K,V> V[]
setAttributeValuesIfAbsent(String name, String type, ConcurrentMap<K,Collection<V>> map, K key, V[] values)
          Sets values of a multi-valued key attribute if absent.
<K,V> void
setAttributeValuesIfAbsent(String name, String type, ConcurrentMap<K,V> map, Map<K,V> values)
          Sets missing values of key attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttributeSupport

public AttributeSupport(MBeanDelegate adapter)
Constructs a new attribute support.

Parameters:
adapter - the adapter MBean.
Method Detail

attributeIndexOf

public int attributeIndexOf(Object[] values,
                            Object value)
Returns index of a multi-valued attribute value.

Parameters:
values - attribute values.
value - the searched value.
Returns:
the index of the value or -1 if not found.

getAttributeValues

public <V> V[] getAttributeValues(Collection<V> c)
Gets values of a multi-valued attribute.

Type Parameters:
V - the value type.
Parameters:
c - the attribute collection.
Returns:
an array of attribute values.

setAttributeValues

public <V> V[] setAttributeValues(String name,
                                  String type,
                                  Collection<V> c,
                                  V[] values)
Sets values of a multi-valued attribute.

Type Parameters:
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
c - the attribute collection.
values - the attribute values.
Returns:
the previous values or null.

setAttributeValue

public <V> void setAttributeValue(String name,
                                  String type,
                                  List<V> l,
                                  int index,
                                  V value)
Sets a multi-valued attribute value at the specified position.

Type Parameters:
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
l - the attribute list.
index - the index of the attribute.
value - the attribute value.

addAttributeValue

public <V> boolean addAttributeValue(String name,
                                     String type,
                                     Collection<V> c,
                                     V value)
Adds a multi-valued attribute value.

Type Parameters:
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
c - the attribute collection.
value - the attribute value.
Returns:
true if accepted, false otherwise.

addAttributeValue

public <V> boolean addAttributeValue(String name,
                                     String type,
                                     Collection<V> c,
                                     int index,
                                     V value)
Adds a multi-valued attribute value at the specified position.

Type Parameters:
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
c - the attribute collection.
index - the index of the attribute.
value - the attribute value.
Returns:
true if accepted, false otherwise.

removeAttributeValue

public <V> boolean removeAttributeValue(String name,
                                        String type,
                                        Collection<V> c,
                                        Object value)
Removes a multi-valued attribute value.

Type Parameters:
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
c - the attribute collection.
value - the attribute value.
Returns:
true if removed, false otherwise.

removeAttributeValue

public <V> V removeAttributeValue(String name,
                                  String type,
                                  Collection<V> c,
                                  int index)
Removes an indexed multi-valued attribute value.

Type Parameters:
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
c - the attribute collection.
index - the index of the attribute.
Returns:
the removed value or null.

clearAttribute

public <V> V[] clearAttribute(String name,
                              String type,
                              Collection<V> c)
Clears a multi-valued attribute.

Type Parameters:
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
c - the attribute collection.
Returns:
the cleared values or null.

setAttributeValues

public <K,V> void setAttributeValues(String name,
                                     String type,
                                     ConcurrentMap<K,V> map,
                                     Map<K,V> values)
Sets values of key attributes without clearing existing ones.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
values - the attribute values.

setAttributeValuesIfAbsent

public <K,V> void setAttributeValuesIfAbsent(String name,
                                             String type,
                                             ConcurrentMap<K,V> map,
                                             Map<K,V> values)
Sets missing values of key attributes.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
values - the attribute values.

containsAttribute

public <K,V> boolean containsAttribute(ConcurrentMap<K,V> map,
                                       Object key)
Checks a key attribute.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
map - the attribute map.
key - the attribute key.
Returns:
true if defined, false otherwise.

getAttributeValue

public <K,V> V getAttributeValue(ConcurrentMap<K,V> map,
                                 Object key)
Gets the value of a key attribute.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
map - the attribute map.
key - the attribute key.
Returns:
the attribute value or null.

setAttributeValue

public <K,V> V setAttributeValue(String name,
                                 String type,
                                 ConcurrentMap<K,V> map,
                                 K key,
                                 V value)
Sets the value of a key attribute.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
value - the attribute value.
Returns:
the previous value or null.

setAttributeValueIfAbsent

public <K,V> boolean setAttributeValueIfAbsent(String name,
                                               String type,
                                               ConcurrentMap<K,V> map,
                                               K key,
                                               V value)
Sets a missing value for a key attribute.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
value - the attribute value.
Returns:
true if added, false otherwise.

setAttributeValue

public <K,V> V setAttributeValue(String name,
                                 String type,
                                 OrderedMap<K,V> map,
                                 int index,
                                 K key,
                                 V value)
Sets an indexed value for a key attribute.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
index - the attribute index.
key - the attribute key.
value - the attribute value.
Returns:
the previous value or null.

removeAttribute

public <K,V> V removeAttribute(String name,
                               String type,
                               ConcurrentMap<K,V> map,
                               Object key)
Removes a key attribute.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
Returns:
the removed value or null.

getAttributeValues

public <K,V> V[] getAttributeValues(ConcurrentMap<K,Collection<V>> map,
                                    Object key)
Gets values of a multi-valued key attribute.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
map - the attribute map.
key - the attribute key.
Returns:
an array of attribute values or null.

setAttributeValues

public <K,V> V[] setAttributeValues(String name,
                                    String type,
                                    ConcurrentMap<K,Collection<V>> map,
                                    K key,
                                    V[] values)
Sets values of a multi-valued key attribute.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
values - the attribute values.
Returns:
the previous values.

setAttributeValuesIfAbsent

public <K,V> V[] setAttributeValuesIfAbsent(String name,
                                            String type,
                                            ConcurrentMap<K,Collection<V>> map,
                                            K key,
                                            V[] values)
Sets values of a multi-valued key attribute if absent.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
values - the attribute values.
Returns:
the previous values.

setAttributeValue

public <K,V> void setAttributeValue(String name,
                                    String type,
                                    ConcurrentMap<K,List<V>> map,
                                    K key,
                                    int index,
                                    V value)
Sets a multi-valued key attribute value at the specified position.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
index - the index of the attribute.
value - the attribute value.

addAttributeValue

public <K,V> boolean addAttributeValue(String name,
                                       String type,
                                       ConcurrentMap<K,Collection<V>> map,
                                       K key,
                                       V value)
Adds a multi-valued key attribute value.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
value - the attribute value.
Returns:
true if accepted, false otherwise.

addAttributeValue

public <K,V> boolean addAttributeValue(String name,
                                       String type,
                                       ConcurrentMap<K,Collection<V>> map,
                                       K key,
                                       int index,
                                       V value)
Adds a multi-valued key attribute value at the specified position.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
index - the index of the attribute.
value - the attribute value.
Returns:
true if accepted, false otherwise.

removeAttributeValue

public <K,V> boolean removeAttributeValue(String name,
                                          String type,
                                          ConcurrentMap<K,Collection<V>> map,
                                          Object key,
                                          Object value)
Removes a multi-valued key attribute value.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
value - the attribute value.
Returns:
true if removed, false if already missing.

removeAttributeValue

public <K,V> V removeAttributeValue(String name,
                                    String type,
                                    ConcurrentMap<K,Collection<V>> map,
                                    int index,
                                    Object key)
Removes an indexed multi-valued attribute value.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
index - the index of the value.
Returns:
the removed value or null.

clearAttribute

public <K,V> V[] clearAttribute(String name,
                                String type,
                                ConcurrentMap<K,Collection<V>> map,
                                Object key)
Clears a multi-valued key attribute.

Type Parameters:
K - the key type.
V - the value type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
key - the attribute key.
Returns:
the removed values or null.

clearAttributes

public <K> boolean clearAttributes(String name,
                                   String type,
                                   ConcurrentMap<K,?> map)
Clears all key attributes.

Type Parameters:
K - the key type.
Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
Returns:
true if cleared, false if already empty.

clearAttributes

public boolean clearAttributes(String name,
                               String type,
                               ConcurrentMap<String,?> map,
                               String prefix)
Clears prefixed key attributes.

Parameters:
name - the attribute name.
type - the attribute type.
map - the attribute map.
prefix - the attribute prefix.
Returns:
true if cleared, false if already empty.

attributeKeySet

public <K> Set<K> attributeKeySet(ConcurrentMap<K,?> map)
Returns a read-only set of attribute keys.

Type Parameters:
K - the key type.
Parameters:
map - the attribute map.
Returns:
a set of attribute keys or an empty set.

attributeKeySet

public Set<String> attributeKeySet(ConcurrentMap<String,?> map,
                                   String prefix)
Returns a read-only set of prefixed attribute keys.

Parameters:
map - the attribute map.
prefix - the attribute prefix.
Returns:
a set of attribute keys or an empty set.


Copyright © 2004 The Norther Organization. All rights reserved.