org.decisiondeck.jmcda.structure.sorting.assignment.utils
Class AssignmentsUtils

java.lang.Object
  extended by org.decisiondeck.jmcda.structure.sorting.assignment.utils.AssignmentsUtils

public class AssignmentsUtils
extends Object


Constructor Summary
AssignmentsUtils()
           
 
Method Summary
static boolean addToCategories(IOrderedAssignmentsToMultiple assignments, Alternative alternative, Category category)
           
static void assertEqual(IOrderedAssignmentsToMultipleRead assignments1, IOrderedAssignmentsToMultipleRead assignments2, String name1, String name2)
           
static void assertEqual(Map<DecisionMaker,? extends IOrderedAssignmentsRead> assignments1, Map<DecisionMaker,? extends IOrderedAssignmentsRead> assignments2, String name1, String name2)
           
static void assertRestriction(IOrderedAssignmentsToMultipleRead assignments, IOrderedAssignmentsToMultipleRead restriction)
           
static void completeAssignments(Set<Alternative> alternatives, IOrderedAssignmentsToMultiple assignments)
           
static void copyAssignmentsToMultipleToOrderedTarget(IAssignmentsToMultipleRead source, IOrderedAssignmentsToMultiple target)
           Copies the given source assignments into the target.
static void copyAssignmentsToMultipleToTargetSingle(IAssignmentsToMultipleRead source, IAssignments target)
           The source must have each alternative assigned to only one category.
static void copyAssignmentsToOrderedTarget(IAssignmentsRead source, IOrderedAssignments target)
           Copies the given source assignments into the target.
static void copyAssignmentsWithCredibilitiesToOrderedTarget(IAssignmentsWithCredibilitiesRead source, IOrderedAssignmentsWithCredibilities target)
           Copies the given source assignments into the target.
static boolean copyOrderedAssignmentsToMultipleToTarget(IOrderedAssignmentsToMultipleRead source, IOrderedAssignmentsToMultiple target)
          Overrides the target by replacing every information it contains with the information in the given source.
static void copyOrderedAssignmentsToMultipleToTargetSingle(IOrderedAssignmentsToMultipleRead source, IOrderedAssignments target)
           The source must have each alternative assigned to only one category.
static boolean copyOrderedAssignmentsToTarget(IOrderedAssignmentsRead source, IOrderedAssignments target)
          Overrides the target by replacing every information it contains with the information in the given source.
static boolean copyOrderedAssignmentsWithCredibilitiesToTarget(IOrderedAssignmentsWithCredibilitiesRead source, IOrderedAssignmentsWithCredibilities target)
          Overrides the target by replacing every information it contains with the information in the given source.
static void copyOrderedAssignmentsWithCredibilitiesToTargetSingle(IOrderedAssignmentsWithCredibilitiesRead source, IOrderedAssignments target)
           The source must have each alternative assigned to only one category.
static void ensuresSingle(IAssignmentsToMultipleRead assignments)
           
static void ensuresSingle(IAssignmentsWithCredibilitiesRead assignments)
           
static void ensuresToIntervals(IOrderedAssignmentsToMultiple assignments, NavigableSet<Category> categories)
          Ensures that every assigned alternative contained in the given data are assigned to an interval over the given ordered set of categories, or equivalently, that each alternative is assigned to a subset of the given categories which has no “hole”.
static boolean equivalentOrderedToMultiple(IOrderedAssignmentsToMultipleRead ordered1, IOrderedAssignmentsToMultipleRead ordered2)
           
static boolean equivalentOrderedWithCredibilities(IOrderedAssignmentsWithCredibilitiesRead ordered1, IOrderedAssignmentsWithCredibilitiesRead ordered2)
           
static boolean equivalentToMultiple(IAssignmentsToMultipleRead assignments1, IAssignmentsToMultipleRead assignments2)
           
static boolean equivalentWithCredibilities(IAssignmentsWithCredibilitiesRead assignments1, IAssignmentsWithCredibilitiesRead assignments2)
           
static Set<Category> getAllCategoriesAssignedTo(Iterable<? extends IOrderedAssignmentsToMultipleRead> allAssignments, Alternative alternative)
           
static NavigableMap<Category,Double> getCredibilitiesOrEmpty(IOrderedAssignmentsWithCredibilitiesRead assignments, Alternative alternative)
          If the given alternative is not assigned, returns a new empty map with comparator set to the comparator of the categories in the given assignments.
static NavigableMap<Category,Double> getCredibilitiesWithZeroes(IOrderedAssignmentsWithCredibilitiesRead assignments, Alternative alternative)
          Retrieves the credibilities of assignments of the given alternative to all categories contained in the given assignments.
static NavigableSet<Double> getCredibilityLevels(IAssignmentsWithCredibilitiesRead assignments)
           
static IOrderedAssignmentsToMultipleRead getEdgesView(IOrderedAssignmentsToMultipleRead delegate)
           
static Equivalence<IOrderedAssignmentsToMultipleRead> getEquivalenceRelationOrderedToMultiple()
           
static Equivalence<IOrderedAssignmentsWithCredibilitiesRead> getEquivalenceRelationOrderedWithCredibilities()
           
static Equivalence<IAssignmentsToMultipleRead> getEquivalenceRelationToMultiple()
           
static Equivalence<IAssignmentsWithCredibilitiesRead> getEquivalenceRelationWithCredibilities()
           
static IOrderedAssignments getFakeWritable(IOrderedAssignmentsRead delegateRead)
           
static IOrderedAssignmentsToMultiple getFakeWritableToMultiple(IOrderedAssignmentsToMultipleRead delegateRead)
           
static IOrderedAssignmentsWithCredibilities getFakeWriteableWithCredibilities(IOrderedAssignmentsWithCredibilitiesRead delegateRead)
           
static Map<Alternative,Set<Category>> getMapView(IAssignmentsToMultipleRead assignments)
           
static Map<Alternative,Map<Category,Double>> getMapViewOfCredibilities(IAssignmentsWithCredibilitiesRead assignments)
           
static IOrderedAssignmentsWithCredibilitiesRead getOrderedAssignmentsWithCredibilitiesView(IOrderedAssignmentsToMultipleRead assignments, double credibilityValue)
           
static IOrderedAssignmentsRead getReadView(IOrderedAssignments delegate)
           
static IOrderedAssignmentsToMultipleRead getReadView(IOrderedAssignmentsToMultiple delegate)
           
static String getShortDescription(IAssignmentsWithCredibilitiesRead assignments)
          Retrieves a description of all data contained in the given assignments object in a packed, debug, form.
static int getSize(IOrderedAssignmentsToMultipleRead assignments)
           
static IOrderedAssignmentsToMultiple getUnion(Iterable<? extends IOrderedAssignmentsToMultipleRead> allAssignments, NavigableSet<Category> categories, Set<Alternative> alternatives)
          Returns a new object containing every alternative assigned in at least one of the given assignments objects, and for each alternative, containing as an assignment the union of all categories to which the alternative is assigned across the given assignment objects.
static Set<Alternative> getUnionAssignedAlternatives(Iterable<? extends IOrderedAssignmentsToMultipleRead> allAssignments)
          Retrieves a read-only view of all the alternatives assigned in the given assignments objects at the time this method is invoked.
static boolean removeCategory(IOrderedAssignments assignments, Category toRemove)
          Removes all assignments to the given category if there is any, and removes the category from the set of categories bound to the given assignments if it exists.
static boolean removeCategory(IOrderedAssignmentsToMultiple assignments, Category toRemove)
          Removes all assignments to the given category if there is any, and removes the category from the set of categories bound to the given assignments if it exists.
static boolean removeCategory(IOrderedAssignmentsWithCredibilities assignments, Category toRemove)
          Removes all assignments to the given category if there is any, and removes the category from the set of categories bound to the given assignments if it exists.
static void renameCategory(IOrderedAssignments assignments, Category oldCategory, Category newCategory)
          Replaces all assignments to the given old category with assignments to the given new category, and replaces the old category with the new one in the set of categories bound to the given assignments object.
static void renameCategory(IOrderedAssignmentsToMultiple assignments, Category oldCategory, Category newCategory)
           
static void renameCategory(IOrderedAssignmentsWithCredibilities assignments, Category oldCategory, Category newCategory)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssignmentsUtils

public AssignmentsUtils()
Method Detail

assertRestriction

public static void assertRestriction(IOrderedAssignmentsToMultipleRead assignments,
                                     IOrderedAssignmentsToMultipleRead restriction)
                              throws IllegalStateException
Throws:
IllegalStateException

getUnionAssignedAlternatives

public static Set<Alternative> getUnionAssignedAlternatives(Iterable<? extends IOrderedAssignmentsToMultipleRead> allAssignments)
Retrieves a read-only view of all the alternatives assigned in the given assignments objects at the time this method is invoked. If the set of assignments in a given assignments object change after this method returns, the change will be reflected in the returned set, but if an assignments object is added to the iterable, the change is not reflected.

Parameters:
allAssignments - not null.
Returns:
not null.

getOrderedAssignmentsWithCredibilitiesView

public static IOrderedAssignmentsWithCredibilitiesRead getOrderedAssignmentsWithCredibilitiesView(IOrderedAssignmentsToMultipleRead assignments,
                                                                                                  double credibilityValue)

copyOrderedAssignmentsToMultipleToTarget

public static boolean copyOrderedAssignmentsToMultipleToTarget(IOrderedAssignmentsToMultipleRead source,
                                                               IOrderedAssignmentsToMultiple target)
Overrides the target by replacing every information it contains with the information in the given source.

Parameters:
source - not null.
target - not null.
Returns:
true iff the call to this method changed the contents of the given target, or equivalently, false iff the given target was equal to the given source.

equivalentOrderedWithCredibilities

public static boolean equivalentOrderedWithCredibilities(IOrderedAssignmentsWithCredibilitiesRead ordered1,
                                                         IOrderedAssignmentsWithCredibilitiesRead ordered2)

ensuresSingle

public static void ensuresSingle(IAssignmentsToMultipleRead assignments)
                          throws InvalidInputException
Throws:
InvalidInputException

renameCategory

public static void renameCategory(IOrderedAssignments assignments,
                                  Category oldCategory,
                                  Category newCategory)
Replaces all assignments to the given old category with assignments to the given new category, and replaces the old category with the new one in the set of categories bound to the given assignments object.

Parameters:
assignments - not null.
oldCategory - not null, must exist in the set of categories of the given assignments.
newCategory - not null, must not exist in the set of categories of the given assignments.

removeCategory

public static boolean removeCategory(IOrderedAssignments assignments,
                                     Category toRemove)
Removes all assignments to the given category if there is any, and removes the category from the set of categories bound to the given assignments if it exists.

Parameters:
assignments - not null.
toRemove - not null.
Returns:
true iff the call to this method changed the state of the given assignments, or equivalently, true iff the given category was contained in the given assignments.

renameCategory

public static void renameCategory(IOrderedAssignmentsToMultiple assignments,
                                  Category oldCategory,
                                  Category newCategory)

removeCategory

public static boolean removeCategory(IOrderedAssignmentsToMultiple assignments,
                                     Category toRemove)
Removes all assignments to the given category if there is any, and removes the category from the set of categories bound to the given assignments if it exists.

Parameters:
assignments - not null.
toRemove - not null.
Returns:
true iff the call to this method changed the state of the given assignments, or equivalently, true iff the given category was contained in the given assignments.

copyOrderedAssignmentsToTarget

public static boolean copyOrderedAssignmentsToTarget(IOrderedAssignmentsRead source,
                                                     IOrderedAssignments target)
Overrides the target by replacing every information it contains with the information in the given source.

Parameters:
source - not null.
target - not null.
Returns:
true iff the call to this method changed the contents of the given target, or equivalently, false iff the given target was equal to the given source.

copyOrderedAssignmentsToMultipleToTargetSingle

public static void copyOrderedAssignmentsToMultipleToTargetSingle(IOrderedAssignmentsToMultipleRead source,
                                                                  IOrderedAssignments target)
                                                           throws InvalidInputException

The source must have each alternative assigned to only one category.

Overrides the target by replacing every information it contains with the information in the given source.

Parameters:
source - not null.
target - not null.
Throws:
InvalidInputException - if the source contains at least one alternative assigned to more than one category.

getEquivalenceRelationWithCredibilities

public static Equivalence<IAssignmentsWithCredibilitiesRead> getEquivalenceRelationWithCredibilities()

getShortDescription

public static String getShortDescription(IAssignmentsWithCredibilitiesRead assignments)
Retrieves a description of all data contained in the given assignments object in a packed, debug, form. This method is suitable for use in a Object.toString() method.

Parameters:
assignments - not null.
Returns:
not null.

getEquivalenceRelationToMultiple

public static Equivalence<IAssignmentsToMultipleRead> getEquivalenceRelationToMultiple()

equivalentWithCredibilities

public static boolean equivalentWithCredibilities(IAssignmentsWithCredibilitiesRead assignments1,
                                                  IAssignmentsWithCredibilitiesRead assignments2)

getCredibilitiesWithZeroes

public static NavigableMap<Category,Double> getCredibilitiesWithZeroes(IOrderedAssignmentsWithCredibilitiesRead assignments,
                                                                       Alternative alternative)
Retrieves the credibilities of assignments of the given alternative to all categories contained in the given assignments. For each category where the alternative is not assigned, a zero credibility value is used. For example, if the given assignments object has three categories c1, c2, c3, and the credibilities of assignment of a given alternative are 2 in c1 and 4 in c3, then this method will return for that alternative a set of credibilities of, in order, 2, 0, 4.

Parameters:
assignments - not null.
alternative - not null.
Returns:
not null. The set of categories are the same as the set of categories in the given assignments. All values are positive or zero. The returned map is a copy.

getCredibilitiesOrEmpty

public static NavigableMap<Category,Double> getCredibilitiesOrEmpty(IOrderedAssignmentsWithCredibilitiesRead assignments,
                                                                    Alternative alternative)
If the given alternative is not assigned, returns a new empty map with comparator set to the comparator of the categories in the given assignments. This allows to use the returned map to add values relating to the same categories as this assignment and benefit from the same ordering of the categories. If the given alternative is assigned, this method returns the credibilities as would be returned from the assignments object.

Parameters:
assignments - not null.
alternative - not null.
Returns:
not null, a possibly read-only copy.

renameCategory

public static void renameCategory(IOrderedAssignmentsWithCredibilities assignments,
                                  Category oldCategory,
                                  Category newCategory)

removeCategory

public static boolean removeCategory(IOrderedAssignmentsWithCredibilities assignments,
                                     Category toRemove)
Removes all assignments to the given category if there is any, and removes the category from the set of categories bound to the given assignments if it exists.

Parameters:
assignments - not null.
toRemove - not null.
Returns:
true iff the call to this method changed the state of the given assignments, or equivalently, true iff the given category was contained in the given assignments.

ensuresToIntervals

public static void ensuresToIntervals(IOrderedAssignmentsToMultiple assignments,
                                      NavigableSet<Category> categories)
                               throws InvalidInputException
Ensures that every assigned alternative contained in the given data are assigned to an interval over the given ordered set of categories, or equivalently, that each alternative is assigned to a subset of the given categories which has no “hole”. The categories contained in the given assignments are not used: assignments are checked against the given categories instead.

Parameters:
assignments - not null.
categories - not null.
Throws:
InvalidInputException - if some alternatives are assigned to some categories that do not form an interval over the given set of categories.

completeAssignments

public static void completeAssignments(Set<Alternative> alternatives,
                                       IOrderedAssignmentsToMultiple assignments)

getUnion

public static IOrderedAssignmentsToMultiple getUnion(Iterable<? extends IOrderedAssignmentsToMultipleRead> allAssignments,
                                                     NavigableSet<Category> categories,
                                                     Set<Alternative> alternatives)
Returns a new object containing every alternative assigned in at least one of the given assignments objects, and for each alternative, containing as an assignment the union of all categories to which the alternative is assigned across the given assignment objects. The returned assignments object has as categories the categories given as argument. These categories must be a superset of all the categories used in the given assignments objects. This is required because otherwise this object has no means to know the total order over the union of the categories.

Parameters:
allAssignments - not null.
categories - not null, must be a superset of all categories used in the assignments objects.
alternatives - if not null, the set must be included in the set of all alternatives assigned in at least one of the given assignments. Those alternatives are the ones assigned in the returned union. The iteration order of the returned union matches that of the given set.
Returns:
not null.

getMapView

public static Map<Alternative,Set<Category>> getMapView(IAssignmentsToMultipleRead assignments)

getMapViewOfCredibilities

public static Map<Alternative,Map<Category,Double>> getMapViewOfCredibilities(IAssignmentsWithCredibilitiesRead assignments)

ensuresSingle

public static void ensuresSingle(IAssignmentsWithCredibilitiesRead assignments)
                          throws InvalidInputException
Throws:
InvalidInputException

copyOrderedAssignmentsWithCredibilitiesToTargetSingle

public static void copyOrderedAssignmentsWithCredibilitiesToTargetSingle(IOrderedAssignmentsWithCredibilitiesRead source,
                                                                         IOrderedAssignments target)
                                                                  throws InvalidInputException

The source must have each alternative assigned to only one category.

Overrides the target by replacing every information it contains with the information in the given source.

Parameters:
source - not null.
target - not null.
Throws:
InvalidInputException - if the source contains at least one alternative assigned to more than one category.

getEquivalenceRelationOrderedToMultiple

public static Equivalence<IOrderedAssignmentsToMultipleRead> getEquivalenceRelationOrderedToMultiple()

equivalentOrderedToMultiple

public static boolean equivalentOrderedToMultiple(IOrderedAssignmentsToMultipleRead ordered1,
                                                  IOrderedAssignmentsToMultipleRead ordered2)

getEquivalenceRelationOrderedWithCredibilities

public static Equivalence<IOrderedAssignmentsWithCredibilitiesRead> getEquivalenceRelationOrderedWithCredibilities()

equivalentToMultiple

public static boolean equivalentToMultiple(IAssignmentsToMultipleRead assignments1,
                                           IAssignmentsToMultipleRead assignments2)

copyAssignmentsToMultipleToTargetSingle

public static void copyAssignmentsToMultipleToTargetSingle(IAssignmentsToMultipleRead source,
                                                           IAssignments target)
                                                    throws InvalidInputException

The source must have each alternative assigned to only one category.

Overrides the target by replacing every information it contains with the information in the given source.

Parameters:
source - not null.
target - not null.
Throws:
InvalidInputException - if the source contains at least one alternative assigned to more than one category.

copyAssignmentsWithCredibilitiesToOrderedTarget

public static void copyAssignmentsWithCredibilitiesToOrderedTarget(IAssignmentsWithCredibilitiesRead source,
                                                                   IOrderedAssignmentsWithCredibilities target)
                                                            throws InvalidInputException

Copies the given source assignments into the target. The target must have a set of categories that contain all the given source assignments. The target existing assignments for alternatives not assigned in the source assignments are kept and not changed by this method. The target existing assignments for alternatives that also exist in the source are erased and replaced by the copy of the source assignments.

If the target set of categories is not a superset of the set of categories used in the source, an exception is thrown, and the given target is left unchanged.

Parameters:
source - not null.
target - not null.
Throws:
InvalidInputException - iff at least one alternative is assigned in source to a category not contained in the categories associated to the given target.

getAllCategoriesAssignedTo

public static Set<Category> getAllCategoriesAssignedTo(Iterable<? extends IOrderedAssignmentsToMultipleRead> allAssignments,
                                                       Alternative alternative)

getFakeWritable

public static IOrderedAssignments getFakeWritable(IOrderedAssignmentsRead delegateRead)

getFakeWriteableWithCredibilities

public static IOrderedAssignmentsWithCredibilities getFakeWriteableWithCredibilities(IOrderedAssignmentsWithCredibilitiesRead delegateRead)

copyAssignmentsToOrderedTarget

public static void copyAssignmentsToOrderedTarget(IAssignmentsRead source,
                                                  IOrderedAssignments target)
                                           throws InvalidInputException

Copies the given source assignments into the target. The target must have a set of categories that contain all the given source assignments. The target existing assignments for alternatives not assigned in the source assignments are kept and not changed by this method. The target existing assignments for alternatives that also exist in the source are erased and replaced by the copy of the source assignments.

If the target set of categories is not a superset of the set of categories used in the source, an exception is thrown, and the given target is left unchanged.

Parameters:
source - not null.
target - not null.
Throws:
InvalidInputException - iff at least one alternative is assigned in source to a category not contained in the categories associated to the given target.

copyAssignmentsToMultipleToOrderedTarget

public static void copyAssignmentsToMultipleToOrderedTarget(IAssignmentsToMultipleRead source,
                                                            IOrderedAssignmentsToMultiple target)
                                                     throws InvalidInputException

Copies the given source assignments into the target. The target must have a set of categories that contain all the given source assignments. The target existing assignments for alternatives not assigned in the source assignments are kept and not changed by this method. The target existing assignments for alternatives that also exist in the source are erased and replaced by the copy of the source assignments.

If the target set of categories is not a superset of the set of categories used in the source, an exception is thrown, and the given target is left unchanged.

Parameters:
source - not null.
target - not null.
Throws:
InvalidInputException - iff at least one alternative is assigned in source to a category not contained in the categories associated to the given target.

getFakeWritableToMultiple

public static IOrderedAssignmentsToMultiple getFakeWritableToMultiple(IOrderedAssignmentsToMultipleRead delegateRead)

getReadView

public static IOrderedAssignmentsRead getReadView(IOrderedAssignments delegate)

getReadView

public static IOrderedAssignmentsToMultipleRead getReadView(IOrderedAssignmentsToMultiple delegate)

getEdgesView

public static IOrderedAssignmentsToMultipleRead getEdgesView(IOrderedAssignmentsToMultipleRead delegate)

assertEqual

public static void assertEqual(IOrderedAssignmentsToMultipleRead assignments1,
                               IOrderedAssignmentsToMultipleRead assignments2,
                               String name1,
                               String name2)
                        throws IllegalStateException
Throws:
IllegalStateException

getSize

public static int getSize(IOrderedAssignmentsToMultipleRead assignments)

addToCategories

public static boolean addToCategories(IOrderedAssignmentsToMultiple assignments,
                                      Alternative alternative,
                                      Category category)

assertEqual

public static void assertEqual(Map<DecisionMaker,? extends IOrderedAssignmentsRead> assignments1,
                               Map<DecisionMaker,? extends IOrderedAssignmentsRead> assignments2,
                               String name1,
                               String name2)

getCredibilityLevels

public static NavigableSet<Double> getCredibilityLevels(IAssignmentsWithCredibilitiesRead assignments)

copyOrderedAssignmentsWithCredibilitiesToTarget

public static boolean copyOrderedAssignmentsWithCredibilitiesToTarget(IOrderedAssignmentsWithCredibilitiesRead source,
                                                                      IOrderedAssignmentsWithCredibilities target)
Overrides the target by replacing every information it contains with the information in the given source.

Parameters:
source - not null.
target - not null.
Returns:
true iff the call to this method changed the contents of the given target, or equivalently, false iff the given target was equal to the given source.


Copyright © 2011. All Rights Reserved.