Class MutableLinearPreferenceImpl
- java.lang.Object
-
- io.github.oliviercailloux.j_voting.preferences.classes.MutableLinearPreferenceImpl
-
- All Implemented Interfaces:
MutableLinearPreference,Preference
public class MutableLinearPreferenceImpl extends Object implements MutableLinearPreference
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMutableLinearPreferenceImpl.MutableLinearIteratorDecoratorstatic classMutableLinearPreferenceImpl.MutableLinearSetDecoratorIn the future, ideally, sets returned via this decorator should be protected from alteration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddAlternative(Alternative a)Adds the specified alternative at the last rank of this preference if it is not already present.Graph<Alternative>asGraph()In the graph : a relation from a to b means "a is at least as good as b".booleanchangeOrder(Alternative alternative, int rank)Moves an existing alternative to the desired rank in the preference.booleanequals(Object o2)Set<Alternative>getAlternatives()The returned set reads through this object: if this object is mutable, any modification to this object modifies the returned set, and conversely.VotergetVoter()static MutableLinearPreferencegiven(Voter voter, List<Alternative> list)inthashCode()booleanremoveAlternative(Alternative a)Removes the specified alternative from this preference if it is present.booleanswap(Alternative alternative1, Alternative alternative2)This method enables to swap 2 alternatives of the preference.StringtoString()
-
-
-
Method Detail
-
given
public static MutableLinearPreference given(Voter voter, List<Alternative> list)
- Parameters:
list- is a List of alternatives representing the preference.voter- is the Voter associated to the Preference.- Returns:
- the mutable linear preference
-
changeOrder
public boolean changeOrder(Alternative alternative, int rank)
Description copied from interface:MutableLinearPreferenceMoves 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.- Specified by:
changeOrderin interfaceMutableLinearPreference- 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
public boolean removeAlternative(Alternative a)
Description copied from interface:MutableLinearPreferenceRemoves the specified alternative from this preference if it is present.- Specified by:
removeAlternativein interfaceMutableLinearPreference- Parameters:
a- to be removed from this preference, if present- Returns:
- true if this set contained the specified alternative
-
addAlternative
public boolean addAlternative(Alternative a)
Description copied from interface:MutableLinearPreferenceAdds the specified alternative at the last rank of this preference if it is not already present.- Specified by:
addAlternativein interfaceMutableLinearPreference- Parameters:
a- to be added to this preference- Returns:
- true if this preference did not already contain the specified alternative
-
getAlternatives
public Set<Alternative> getAlternatives()
Description copied from interface:PreferenceThe returned set reads through this object: if this object is mutable, any modification to this object modifies the returned set, and conversely.- Specified by:
getAlternativesin interfacePreference- Returns:
- alternatives's set
-
getVoter
public Voter getVoter()
- Specified by:
getVoterin interfacePreference- Returns:
Voterinstance of the preference, Returns the voter 0 if no specific voter is associated to this preference
-
asGraph
public Graph<Alternative> asGraph()
Description copied from interface:PreferenceIn the graph : a relation from a to b means "a is at least as good as b". This graph can’t be modified, but is not necessarily immutable. Reflexive and transitive.- Specified by:
asGraphin interfacePreference- Returns:
- the Graph corresponding to the Preference
-
swap
public boolean swap(Alternative alternative1, Alternative alternative2)
Description copied from interface:MutableLinearPreferenceThis method enables to swap 2 alternatives of the preference. (If the specified alternatives are equal, invoking this method leaves the preference unchanged.)- Specified by:
swapin interfaceMutableLinearPreference- 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.
-
-