AV
- type of every element in the bagpublic class Bag<AV extends AttributeValue> extends Object implements Value, Iterable<AV>
All implementations of this interface must override all the methods of this class except the final ones (this class only throws UnsupportedOperationException
for these), and guarantee the
immutability of their bag instances. In particular, iterator()
must return an immutable Iterator
( not supported
. It is required to
ensure that values of a given attribute remain constant during an evaluation of a request, as mandated by the XACML spec, section 7.3.5:
"Regardless of any dynamic modifications of the request context during policy evaluation, the PDP SHALL behave as if each bag of attribute values is fully populated in the context before it is first tested, and is thereafter immutable during evaluation. (That is, every subsequent test of that attribute shall use the same bag of values that was initially tested.)"
equals(Object)
are implemented according to the mathematical definition of bag/multiset, and hashCode()
accordingly. Note that multiplicity matters in multisets, therefore this is
different from XACML set-equals function which ignores duplicates.
NB for developers: we could make this class abstract and let subclasses implement methods except the ones with 'final' modifier. However, we need a common Bag superclass (esp. for internal
subclasses in Bags
) that is concrete, in order to use it as the Class
instance returned by Object.getClass()
and be able to use it in BagDatatype.cast(Value)
to
cast any bag instance.
Modifier and Type | Class and Description |
---|---|
static interface |
Bag.Validator
Bag content validator
|
Modifier | Constructor and Description |
---|---|
protected |
Bag(Datatype<AV> elementDatatype,
com.google.common.collect.ImmutableMultiset<AV> elements)
Constructor
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(AV v)
Returns true if this bag contains the specified element.
|
com.google.common.collect.Multiset<AV> |
elements()
Get all elements in the bag.
|
boolean |
equals(Object other)
equals(Object) compares the element datatypes, and calls equals(Object) on the results of elements() , therefore Multiset.equals(Object) , which complies with
the mathematical definition of multisets and XACML spec for bags. |
Datatype<AV> |
getElementDatatype()
Get this bag's element datatype (datatype of every element in the bag)
|
IndeterminateEvaluationException |
getReasonWhyEmpty()
Get the reason why
isEmpty() returns true iff it does; or null if it doesn't or if reason is unknown. |
AV |
getSingleElement()
Get the single element in the bag if it is a singleton
|
int |
hashCode()
Override Object#hashCode() to apply XACML spec §7.3.2: "The values in a bag are not ordered, and some of the values may be duplicates"
|
boolean |
isEmpty()
Returns true iff the bag contains no value
|
Iterator<AV> |
iterator() |
int |
size()
Get bag size
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public final Datatype<AV> getElementDatatype()
public final boolean equals(Object other)
equals(Object)
compares the element datatypes, and calls equals(Object)
on the results of elements()
, therefore Multiset.equals(Object)
, which complies with
the mathematical definition of multisets and XACML spec for bags. Note that this is different from XACML set-equals function which does not consider the multiplicity of elements like multisets.public final int hashCode()
public final boolean isEmpty()
public final int size()
public final boolean contains(AV v)
v
- element whose presence in this bag is to be testedpublic final Iterator<AV> iterator()
iterator
in interface Iterable<AV extends AttributeValue>
public final com.google.common.collect.Multiset<AV> elements()
Beware the non-null: implementations must return an empty multiset and not null if the bag is empty.
public AV getSingleElement()
public IndeterminateEvaluationException getReasonWhyEmpty()
isEmpty()
returns true iff it does; or null if it doesn't or if reason is unknown.Copyright © 2012–2020. All rights reserved.