|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
com.fatwire.services.beans.response.MessageCollector<K,V>
K
- the type of the key in a message collector which will use an underlying mapping.V
- the type of the elements in the collection underlying the message collector, or the collection which is a value in the mapping underlying the message collector. It is necessary for the purposes of homogeneity that the collection and the values in the mapping have the same generic type. Where there may be mixed types, Object
can be used.K
- type of keys supported by this message collector.V
- type of values supported by this message collector.public class MessageCollector<K,V>
Implements a collector. The collector can be implemented to use a collection, a mapping, or both as required by the use case.
An example for using a collection is a simple error message collector where the underlying message collector only contains a collection of strings.
An example for using a mapping is a message collector for a service method where the underlying message collector provides feedback for each input entity. For example, if a list of asset identifiers is used as the input, the asset id can be the key, and the value can be a collection of Reason
objects providing the feedback.
Note: The mapping in a message collector does not allow null
keys.
An example of using both a collection and a mapping is a complex feedback collector where the collection is fed with checked exception messages and the mapping contains feedback for each input. For example, if such a message collector is used for a service method which provides a list of asset identifiers as input, the mapping can hold the reason why a specific asset could not be processed as expected, whereas the collection can hold a message due to any other exception (an illegal argument, for example).
MessageCollectors
, Reason
Constructor Summary | |
---|---|
MessageCollector() Default constructor. |
Method Summary | |
---|---|
void |
add(K key, java.util.Collection<V> value) Adds all elements of a value collection against the specified key in the underlying map in the collector. |
void |
add(K key, V value) Adds a value against the specified key in the underlying map in the collector. |
boolean |
add(V e) |
boolean |
addAll(java.util.Collection<? extends V> c) |
void |
addAll(java.util.Map<? extends K,? extends java.util.Collection<V>> m) Adds mapping from an existing message mapping into this message collector's map. |
void |
clear() Clears all messages collected into this message collector. |
boolean |
contains(K o) |
boolean |
containsKey(K key) |
java.util.Collection<V> |
get(K key) Returns the messages collected against the specified key if the underlying collector is a map. |
V |
getFirst() Retrieves the first value from the generic messages collection. |
V |
getFirst(K key) Retrieves the first value from the message collector. |
V |
getFirstMessage() Returns the first message from the collection or the first message from the map iff there is only one entry in the map. |
java.util.Map<K,java.util.Collection<V>> |
getMessageMap() Returns a read-only view of the messages collected as a mapping. |
java.util.Collection<V> |
getMessages() Returns a read-only view of the messages collected as a collection. |
boolean |
isEmpty() Checks if the message collector contains any messages. |
java.util.Set<K> |
keySet() |
protected java.util.Collection<V> |
newMessages() Returns the underlying Collection instance to be wrapped by this message collector. |
protected java.util.Map<K,java.util.Collection<V>> |
newMessagesMap() Returns the underlying Map instance to be wrapped by this message collector. |
boolean |
remove(int index) |
java.util.Collection<V> |
remove(K key) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
removeAll(K key, java.util.Collection<?> c) Removes all of this collector's elements that are also contained in the specified collection. |
boolean |
retainAll(java.util.Collection<?> c) |
boolean |
retainAll(K key, java.util.Collection<?> c) Retains only the elements in this collector that are contained in the specified collection. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MessageCollector()
Method Detail |
---|
protected java.util.Collection<V> newMessages()
Collection
instance to be wrapped by this message collector. The same instantiation is used for the collection objects to be used as values in the mapping.Collection
object.protected java.util.Map<K,java.util.Collection<V>> newMessagesMap()
Map
instance to be wrapped by this message collector.Map
object.public final boolean isEmpty()
true
if the collection is null
or empty as per Collection.isEmpty()
. If the underlying collector is a map, this method will return true
if the map is null
or empty as per Map.isEmpty()
.true
if the underlying collector is null
or empty, false
otherwise.public final java.util.Collection<V> get(K key)
null
. If key is null
, this returns the underlying collector as if it was a collection.key
-public final void add(K key, java.util.Collection<V> value)
null
, adds the elements of the value collection to the underlying collection, instead of adding it to the map. The addition to the collection is governed by the type of collection instantiated for the collector.key
- the key to set.value
- the value to set.public final void add(K key, V value)
null
, adds the value to the underlying collection, instead of adding it to the map. The addition to the collection is governed by the type of collection instantiated for the collector.key
- the key to set.value
- the value to set.public final java.util.Map<K,java.util.Collection<V>> getMessageMap()
null
as a key. If no messages have been collected into the map, this returns an empty map.public final java.util.Collection<V> getMessages()
public final void addAll(java.util.Map<? extends K,? extends java.util.Collection<V>> m)
#add(Object, List)
method.m
- the input map.public final void clear()
public final boolean removeAll(K key, java.util.Collection<?> c)
null
, the removal happens only from the underlying collection and not from the map.key
- the key used to retrieve the collection value from the underlying map.c
- collection containing elements to be removed from this collector.public final boolean retainAll(K key, java.util.Collection<?> c)
key
- the key used to retrieve the collection value from the underlying map.c
- the collection which is to be added as a value in the underlying map.true
if this collector changed as a result of the call.public final V getFirst()
public final V getFirst(K key)
key
is null
, retrieves the message from the underlying collection. This is equivalent to calling MessageCollector.getFirst()
. Otherwise, reads the first value from the underlying map.key
- the key against which the values are read.public V getFirstMessage()
public final boolean containsKey(K key)
public final java.util.Collection<V> remove(K key)
public final java.util.Set<K> keySet()
public final boolean contains(K o)
public final boolean add(V e)
public final boolean addAll(java.util.Collection<? extends V> c)
public final boolean removeAll(java.util.Collection<?> c)
public final boolean retainAll(java.util.Collection<?> c)
public final boolean remove(int index)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.