Interface MutableLinearPreference
-
- All Superinterfaces:
Preference
- All Known Implementing Classes:
MutableLinearPreferenceImpl
,MutableStrictProfile.MutableLinearPreferenceDecorator
public interface MutableLinearPreference extends Preference
A mutable linear preference is a mutable antisymmetric complete preference. A mutable linear preference represents a linear order, or equivalently an antisymmetric complete order, or equivalently, the reduction of a weak-order. In this preference, it is possible to add alternatives and reorder them
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
addAlternative(Alternative alternative)
Adds the specified alternative at the last rank of this preference if it is not already present.boolean
changeOrder(Alternative alternative, int rank)
Moves an existing alternative to the desired rank in the preference.boolean
removeAlternative(Alternative alternative)
Removes the specified alternative from this preference if it is present.boolean
swap(Alternative alternative1, Alternative alternative2)
This method enables to swap 2 alternatives of the preference.-
Methods inherited from interface io.github.oliviercailloux.j_voting.preferences.Preference
asGraph, getAlternatives, getVoter
-
-
-
-
Method Detail
-
changeOrder
boolean changeOrder(Alternative alternative, int rank)
Moves an existing alternative to the desired rank in the preference. All the intermediate alternatives shift. More precisely, the given alternative is swapped with its neighbor until it reaches the given rank.- Parameters:
alternative
- that we're going to move in the preferencerank
- is the new rank where the alternative will be. The first alternative is at the rank 1. The rank must be less than 1 or greater than the rank of the last alternative.- Returns:
- true if the preference has changed after this call. In other words, if the alternative was not already at this rank.
-
removeAlternative
boolean removeAlternative(Alternative alternative)
Removes the specified alternative from this preference if it is present.- Parameters:
alternative
- to be removed from this preference, if present- Returns:
- true if this set contained the specified alternative
-
addAlternative
boolean addAlternative(Alternative alternative)
Adds the specified alternative at the last rank of this preference if it is not already present.- Parameters:
alternative
- to be added to this preference- Returns:
- true if this preference did not already contain the specified alternative
-
swap
boolean swap(Alternative alternative1, Alternative alternative2)
This method enables to swap 2 alternatives of the preference. (If the specified alternatives are equal, invoking this method leaves the preference unchanged.)- Parameters:
alternative1
- that will change places with alternative2alternative2
- that will change places with alternative1- Returns:
- true if the preference has changed after this call (and, thus, the alternatives are contained in this preference). Or equivalently, false if the specified alternatives are equal and contained in this preference.
-
-