com.cafesoft.cams.attr
Class BagAttributeValue

java.lang.Object
  |
  +--com.cafesoft.cams.attr.AbstractAttributeValue
        |
        +--com.cafesoft.cams.attr.BagAttributeValue
All Implemented Interfaces:
AttributeValue, Evaluatable

public class BagAttributeValue
extends AbstractAttributeValue

BagAttributeValue represents a collection of return values from Functions and AttributeDesignators. All values in the bag are of the same attribute type, but the bag may also be empty. NOTE: the bag is immutable, although its contents may not be.

Since:
4/28/2004

Constructor Summary
BagAttributeValue(URI type, Collection bag)
          Creates a new BagAttributeValue that represents a bag of AttributeValues of a specific data type.
 
Method Summary
 boolean contains(AttributeValue value)
          Returns true if this set contains the specified value.
 boolean containsAll(BagAttributeValue bag)
          Returns true if this bag contains all of the values of the specified bag.
static BagAttributeValue createEmptyBag(URI type)
          Convenience function that returns a bag with no elements
 String encode()
          Returns the String encoding of the attribute value.
 boolean isBag()
          Overrides the default method to always return true.
 boolean isEmpty()
          A convenience function that returns whether or not the bag is empty (ie, whether or not the size of the bag is zero)
 Iterator iterator()
          Returns an iterator over the bag values.
 int size()
          Returns the number of elements in this bag
 String toString()
          Converts to a String representation.
 
Methods inherited from class com.cafesoft.cams.attr.AbstractAttributeValue
evaluate, evaluatesToBag, getType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BagAttributeValue

public BagAttributeValue(URI type,
                         Collection bag)
Creates a new BagAttributeValue that represents a bag of AttributeValues of a specific data type.

Parameters:
type - the attribute type contained by this bag.
bag - a collection of AttributeValue objects, all of the same type.
Method Detail

isBag

public boolean isBag()
Overrides the default method to always return true.

Specified by:
isBag in interface AttributeValue
Overrides:
isBag in class AbstractAttributeValue
Returns:
a value of true

createEmptyBag

public static BagAttributeValue createEmptyBag(URI type)
Convenience function that returns a bag with no elements

Parameters:
type - the types contained in the bag
Returns:
a new empty bag

isEmpty

public boolean isEmpty()
A convenience function that returns whether or not the bag is empty (ie, whether or not the size of the bag is zero)

Returns:
whether or not the bag is empty

size

public int size()
Returns the number of elements in this bag

Returns:
the number of elements in this bag

contains

public boolean contains(AttributeValue value)
Returns true if this set contains the specified value. More formally, returns true if and only if this bag contains a value v such that (value==null ? v==null : value.equals(v)). Note that this will only work correctly if the AttributeValue has overridden the equals method.

Parameters:
value - the value to look for
Returns:
true if the value is in the bag

containsAll

public boolean containsAll(BagAttributeValue bag)
Returns true if this bag contains all of the values of the specified bag. Note that this will only work correctly if the AttributeValue type contained in the bag has overridden the equals method.

Parameters:
bag - the bag to compare
Returns:
true if the input is a subset of this bag

iterator

public Iterator iterator()
Returns an iterator over the bag values.


toString

public String toString()
Converts to a String representation.

Overrides:
toString in class Object
Returns:
the String representation of this attribute.

encode

public String encode()
Returns the String encoding of the attribute value.

Specified by:
encode in interface AttributeValue
Specified by:
encode in class AbstractAttributeValue
Returns:
a String form of the value


Generated on 8:41:50 AM June 06, 2005, © 1996-2005 Cafésoft LLC. All rights reserved.