com.splunk
Class ResourceCollection<T extends Resource>

java.lang.Object
  extended by com.splunk.Resource
      extended by com.splunk.ResourceCollection<T>
Type Parameters:
T - The type of members of the collection.
All Implemented Interfaces:
java.util.Map<java.lang.String,T>
Direct Known Subclasses:
ConfCollection, EntityCollection

public class ResourceCollection<T extends Resource>
extends Resource
implements java.util.Map<java.lang.String,T>

The ResourceCollection abstract base class represents a collection of Splunk resources.


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected  java.lang.Class itemClass
           
protected  java.util.LinkedHashMap<java.lang.String,java.util.LinkedList<T>> items
           
 
Fields inherited from class com.splunk.Resource
actions, path, refreshArgs, service, title
 
Method Summary
 void clear()
          
 boolean containsKey(java.lang.Object key)
          
 boolean containsKey(java.lang.Object key, Args namespace)
          Determines whether a scoped, namespace-constrained key exists within this collection.
 boolean containsValue(java.lang.Object value)
          
protected  T createItem(AtomEntry entry)
          Creates a collection member corresponding to a given Atom entry.
protected  T createItem(java.lang.Class itemClass, java.lang.String path, Args namespace)
          Creates a collection member.
 java.util.Set<java.util.Map.Entry<java.lang.String,T>> entrySet()
          
 boolean equals(java.lang.Object o)
          
 T get(java.lang.Object key)
          Gets the value of a given key, if it exists within this collection.
 T get(java.lang.Object key, Args namespace)
          Gets a the value of a scoped, namespace-constrained key, if it exists within this collection.
 int hashCode()
           
 boolean isEmpty()
          
protected  java.lang.String itemKey(AtomEntry entry)
          Returns the value to use as the key from a given Atom entry.
protected  java.lang.String itemPath(AtomEntry entry)
          Returns the value to use as the member's path from a given Atom entry.
 java.util.Set<java.lang.String> keySet()
          
 ResponseMessage list()
          Issues an HTTP request to list the contents of the collection resource.
 T put(java.lang.String key, T value)
          
 void putAll(java.util.Map<? extends java.lang.String,? extends T> map)
          Copies all mappings from a given map to this map (unsupported).
 ResourceCollection refresh()
          Refreshes the local state of this resource.
 T remove(java.lang.Object key)
          
 int size()
          
 ResourceCollection<T> validate()
          Ensures that the local state of the resource is current, calling refresh if necessary.
 java.util.Collection<T> values()
          
 int valueSize(java.lang.Object key)
          Returns the number of values that a specific key represents.
 
Methods inherited from class com.splunk.Resource
getName, getPath, getService, getTitle, invalidate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

protected java.util.LinkedHashMap<java.lang.String,java.util.LinkedList<T extends Resource>> items

itemClass

protected java.lang.Class itemClass
Method Detail

clear

public void clear()

Specified by:
clear in interface java.util.Map<java.lang.String,T extends Resource>

containsKey

public boolean containsKey(java.lang.Object key)

Specified by:
containsKey in interface java.util.Map<java.lang.String,T extends Resource>

containsKey

public boolean containsKey(java.lang.Object key,
                           Args namespace)
Determines whether a scoped, namespace-constrained key exists within this collection.

Parameters:
key - The key to look up.
namespace - The namespace to constrain the search to.
Returns:
true if the key exists, false if not.

containsValue

public boolean containsValue(java.lang.Object value)

Specified by:
containsValue in interface java.util.Map<java.lang.String,T extends Resource>

createItem

protected T createItem(java.lang.Class itemClass,
                       java.lang.String path,
                       Args namespace)
Creates a collection member.

Parameters:
itemClass - The class of the member to create.
path - The path to the member resource.
namespace - The namespace.
Returns:
The new member.

createItem

protected T createItem(AtomEntry entry)
Creates a collection member corresponding to a given Atom entry. This base implementation uses the class object that was passed in when the generic ResourceCollection was created. Subclasses may override this method to provide alternative means of instantiating collection members.

Parameters:
entry - The AtomEntry corresponding to the member to instantiate.
Returns:
The new member.

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,T>> entrySet()

Specified by:
entrySet in interface java.util.Map<java.lang.String,T extends Resource>

equals

public boolean equals(java.lang.Object o)

Specified by:
equals in interface java.util.Map<java.lang.String,T extends Resource>
Overrides:
equals in class java.lang.Object

get

public T get(java.lang.Object key)
Gets the value of a given key, if it exists within this collection.

Specified by:
get in interface java.util.Map<java.lang.String,T extends Resource>
Parameters:
key - The key to look up.
Returns:
The value indexed by the key, or null if it doesn't exist.
Throws:
SplunkException - The exception to throw if there is more than one value represented by this key.

get

public T get(java.lang.Object key,
             Args namespace)
Gets a the value of a scoped, namespace-constrained key, if it exists within this collection.

Parameters:
key - The key to look up.
namespace - The namespace to constrain the search to.
Returns:
The value indexed by the key, or null if it doesn't exist.

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map<java.lang.String,T extends Resource>
Overrides:
hashCode in class java.lang.Object

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Map<java.lang.String,T extends Resource>

itemKey

protected java.lang.String itemKey(AtomEntry entry)
Returns the value to use as the key from a given Atom entry. Subclasses may override this value for collections that use something other than "title" as the key.

Parameters:
entry - The AtomEntry corresponding to the collection member.
Returns:
The value to use as the member's key.

itemPath

protected java.lang.String itemPath(AtomEntry entry)
Returns the value to use as the member's path from a given Atom entry. Subclasses may override this value to support alternative methods of determining a member's path.

Parameters:
entry - The AtomEntry corresponding to the collection member.
Returns:
The value to use as the member's path.

keySet

public java.util.Set<java.lang.String> keySet()

Specified by:
keySet in interface java.util.Map<java.lang.String,T extends Resource>

list

public ResponseMessage list()
Issues an HTTP request to list the contents of the collection resource.

Returns:
The list response message.

put

public T put(java.lang.String key,
             T value)

Specified by:
put in interface java.util.Map<java.lang.String,T extends Resource>

putAll

public void putAll(java.util.Map<? extends java.lang.String,? extends T> map)
Copies all mappings from a given map to this map (unsupported).

Specified by:
putAll in interface java.util.Map<java.lang.String,T extends Resource>
Parameters:
map - The set of mappings to copy into this map.

refresh

public ResourceCollection refresh()
Refreshes the local state of this resource.

Specified by:
refresh in class Resource
Returns:
The current Resource instance.

remove

public T remove(java.lang.Object key)

Specified by:
remove in interface java.util.Map<java.lang.String,T extends Resource>

size

public int size()

Specified by:
size in interface java.util.Map<java.lang.String,T extends Resource>

validate

public ResourceCollection<T> validate()
Ensures that the local state of the resource is current, calling refresh if necessary.

Overrides:
validate in class Resource
Returns:
The current Resource instance.

values

public java.util.Collection<T> values()

Specified by:
values in interface java.util.Map<java.lang.String,T extends Resource>

valueSize

public int valueSize(java.lang.Object key)
Returns the number of values that a specific key represents.

Parameters:
key - The key to look up.
Returns:
The number of entity values represented by the key.