org.decisiondeck.jmcda.structure.sorting.assignment
Class OrderedAssignments

java.lang.Object
  extended by org.decisiondeck.jmcda.structure.sorting.assignment.OrderedAssignments
All Implemented Interfaces:
IAssignmentsRead, IAssignmentsToMultipleRead, IOrderedAssignments, IOrderedAssignmentsRead, IOrderedAssignmentsToMultipleRead, IOrderedAssignmentsWriteable

public class OrderedAssignments
extends Object
implements IOrderedAssignments


Constructor Summary
OrderedAssignments()
           
 
Method Summary
 boolean clear()
           
 boolean equals(Object obj)
           Indicates whether the given object is equal to this one.
 Set<Alternative> getAlternatives()
          Retrieves a read-only view of the assigned alternatives.
 Set<Alternative> getAlternatives(Category category)
           Retrieves a read-only view, or copy, of the alternatives that are assigned to the given category, or to a set of categories including the given category.
 NavigableSet<Category> getCategories()
           Retrieves a (possibly read-only) copy of a set containing at least all the categories to which at least one alternative is assigned.
 NavigableSet<Category> getCategories(Alternative alternative)
          Retrieves, if it exists, the category to which an alternative is assigned as a singleton set.
 Category getCategory(Alternative alternative)
           
 int hashCode()
           
 boolean setCategories(SortedSet<Category> categories)
           Sets the categories and the order of the categories in this object.
 boolean setCategory(Alternative alternative, Category category)
          Sets, replaces, or removes the assignment of an alternative.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OrderedAssignments

public OrderedAssignments()
Method Detail

getCategory

public Category getCategory(Alternative alternative)
Specified by:
getCategory in interface IAssignmentsRead
Parameters:
alternative - not null.
Returns:
the category to which this alternative is assigned, or null iff this alternative is not assigned.

getAlternatives

public Set<Alternative> getAlternatives()
Description copied from interface: IAssignmentsToMultipleRead
Retrieves a read-only view of the assigned alternatives.

Specified by:
getAlternatives in interface IAssignmentsToMultipleRead
Returns:
not null.

getCategories

public NavigableSet<Category> getCategories()
Description copied from interface: IAssignmentsToMultipleRead

Retrieves a (possibly read-only) copy of a set containing at least all the categories to which at least one alternative is assigned. Depending on the implementing object, the returned set may be larger than this. It may for example contain all the categories that are available in some context, even when the alternatives assignments do not cover the whole set of possibilities.

The returned set is a copy: if the assignment related to the given alternative later change, this change is not reflected to the object this method returns.

Specified by:
getCategories in interface IAssignmentsToMultipleRead
Specified by:
getCategories in interface IOrderedAssignmentsToMultipleRead
Returns:
a set, not null, empty iff no alternatives are assigned.

getCategories

public NavigableSet<Category> getCategories(Alternative alternative)
Description copied from interface: IOrderedAssignmentsRead
Retrieves, if it exists, the category to which an alternative is assigned as a singleton set. This method provides compatibility with the IOrderedAssignmentsToMultipleRead interface. The method IAssignmentsRead.getCategory(Alternative) is functionally equivalent and should be preferred over this one as it is clearer.

Specified by:
getCategories in interface IAssignmentsRead
Specified by:
getCategories in interface IAssignmentsToMultipleRead
Specified by:
getCategories in interface IOrderedAssignmentsRead
Specified by:
getCategories in interface IOrderedAssignmentsToMultipleRead
Parameters:
alternative - not null.
Returns:
a set containing exactly one element, namely the category to which the given alternative is assigned, or null iff the alternative is not assigned. The returned set is immutable (if the assignment related to the given alternative later change, this change is not reflected to the object this method returns).

setCategories

public boolean setCategories(SortedSet<Category> categories)
Description copied from interface: IOrderedAssignmentsWriteable

Sets the categories and the order of the categories in this object.

Caution should be used when using this method on a non empty object. The simple case is when the given categories ordering is compatible with the ordering already used. If on the countrary the given categories order is not compatible with the already given ordered assignments, the assignments will be changed to reflect the new order. The user should check whether the order is compatible before using this method if she does not want this to happen.

Specified by:
setCategories in interface IOrderedAssignmentsWriteable
Parameters:
categories - null to remove the associated categories (all the orderings are lost), authorized only when no assignments are contained in this object. Must be a superset of the categories already used.
Returns:
true iff the categories changed.

setCategory

public boolean setCategory(Alternative alternative,
                           Category category)
Description copied from interface: IOrderedAssignments
Sets, replaces, or removes the assignment of an alternative. The given category position in the ordering must have been defined.

Specified by:
setCategory in interface IOrderedAssignments
Parameters:
alternative - not null.
category - null or empty to assign the alternative to no category, i.e., to remove the assignment of the given alternative. Otherwise, must be contained in the categories returned by IAssignmentsToMultipleRead.getCategories().
Returns:
true iff the call changed the assignments, i.e. true if the given alternative was assigned and the assignment has been removed, or was assigned to a different category, or was not assigned and has been.

getAlternatives

public Set<Alternative> getAlternatives(Category category)
Description copied from interface: IAssignmentsToMultipleRead

Retrieves a read-only view, or copy, of the alternatives that are assigned to the given category, or to a set of categories including the given category.

If the given category is not in the set returned by IAssignmentsToMultipleRead.getCategories(), the returned set is empty.

Specified by:
getAlternatives in interface IAssignmentsToMultipleRead
Parameters:
category - not null.
Returns:
not null.

clear

public boolean clear()
Specified by:
clear in interface IOrderedAssignmentsWriteable

equals

public boolean equals(Object obj)
Description copied from interface: IAssignmentsToMultipleRead

Indicates whether the given object is equal to this one. Supposing this object does not implement IAssignmentsWithCredibilitiesRead nor IOrderedAssignmentsToMultipleRead, this is true iff the given object is a IAssignmentsToMultipleRead, does not implement any of these mentioned interfaces either, and contains the same alternatives assigned to the same categories and the same set of overall categories as this object.

Other cases are more subtle. Objects implementing IAssignmentsToMultipleRead may be categorized, according to their capabilities, into four classes: objects having no credibilities and no ordered assignments, objects having credibilities but no ordered assignments, objects having ordered assignments but no credibilities, and objects having both credibilities and ordered assignments. It is meaningless to compare objects belonging to different classes of capabilities and the equality test between objects which are non homogeneous in that sense return false. If this object and the compared object both have credibilities, a supplementary condition is added for the objects to be equal, namely that the assignments must be associated with the same credibilities to the same categories. If this object and the compared object both are ordered, the added condition is that the set of categories contained in the objects must have the same order. Both supplementary conditions are required if the objects being tested for equality are ordered and have credibilities.

Specified by:
equals in interface IAssignmentsToMultipleRead
Specified by:
equals in interface IOrderedAssignmentsToMultipleRead
Overrides:
equals in class Object
Parameters:
obj - may be null.
Returns:
true iff both objects are considered equal.

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2011. All Rights Reserved.