Class ImmutableCompletePreferenceImpl
- java.lang.Object
-
- io.github.oliviercailloux.j_voting.preferences.classes.ImmutableCompletePreferenceImpl
-
- All Implemented Interfaces:
ImmutableCompletePreference
,ImmutablePreference
,Preference
- Direct Known Subclasses:
ImmutableLinearPreferenceImpl
public class ImmutableCompletePreferenceImpl extends Object implements ImmutableCompletePreference
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ImmutableCompletePreferenceImpl(Voter voter, List<? extends Set<Alternative>> equivalenceClasses)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ImmutableCompletePreference
asCompletePreference(Voter voter, List<? extends Set<Alternative>> equivalenceClasses)
ImmutableList<ImmutableSet<Alternative>>
asEquivalenceClasses()
ImmutableGraph<Alternative>
asGraph()
In the graph : a relation from a to b means "a is at least as good as b".boolean
equals(Object obj)
ImmutableSet<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.ImmutableSet<Alternative>
getAlternatives(int rank)
int
getRank(Alternative a)
The rank of an alternative is one plus the number of alternatives strictly preferred to it.Voter
getVoter()
int
hashCode()
boolean
isStrict()
OldLinearPreferenceImpl
toStrictPreference()
-
-
-
Constructor Detail
-
ImmutableCompletePreferenceImpl
protected ImmutableCompletePreferenceImpl(Voter voter, List<? extends Set<Alternative>> equivalenceClasses) throws EmptySetException, DuplicateValueException
- Parameters:
equivalenceClasses
-not null
voter
-not null
- Throws:
EmptySetException
- if a Set is emptyDuplicateValueException
- if an Alternative is duplicate
-
-
Method Detail
-
asCompletePreference
public static ImmutableCompletePreference asCompletePreference(Voter voter, List<? extends Set<Alternative>> equivalenceClasses) throws DuplicateValueException, EmptySetException
- Parameters:
equivalenceClasses
-not null
the best equivalence class must be in first position. An alternative must be uniquevoter
-not null
- Returns:
- new CompletePreference
- Throws:
DuplicateValueException
- if an Alternative is duplicateEmptySetException
- if a Set is empty
-
getAlternatives
public ImmutableSet<Alternative> getAlternatives()
Description copied from interface:ImmutablePreference
The returned set reads through this object: if this object is mutable, any modification to this object modifies the returned set, and conversely. This set is immutable.- Specified by:
getAlternatives
in interfaceImmutablePreference
- Specified by:
getAlternatives
in interfacePreference
- Returns:
- alternatives's set
-
getVoter
public Voter getVoter()
- Specified by:
getVoter
in interfacePreference
- Returns:
Voter
instance of the preference, Returns the voter 0 if no specific voter is associated to this preference
-
getRank
public int getRank(Alternative a)
Description copied from interface:ImmutableCompletePreference
The rank of an alternative is one plus the number of alternatives strictly preferred to it.- Specified by:
getRank
in interfaceImmutableCompletePreference
- Parameters:
a
- is anAlternative
- Returns:
- the rank of this alternative (a number between 1 and n) where
n is the total number of
Alternative
instances.
-
getAlternatives
public ImmutableSet<Alternative> getAlternatives(int rank)
- Specified by:
getAlternatives
in interfaceImmutableCompletePreference
- Parameters:
rank
- at least 1.- Returns:
- the
Aternative
set at this rank. Empty set id there is no alternative at this rank.
-
asEquivalenceClasses
public ImmutableList<ImmutableSet<Alternative>> asEquivalenceClasses()
- Specified by:
asEquivalenceClasses
in interfaceImmutableCompletePreference
- Returns:
- Same data but in an Immutable list object A set of alternative is strictly prefered to next sets. All the alternatives in a set are considered ex-aequo.
-
asGraph
public ImmutableGraph<Alternative> asGraph()
Description copied from interface:ImmutablePreference
In 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. This graph is immutable.- Specified by:
asGraph
in interfaceImmutablePreference
- Specified by:
asGraph
in interfacePreference
- Returns:
- the Graph corresponding to the Preference.
-
isStrict
public boolean isStrict()
- Returns:
- true if the Preference is Strict (without several alternatives having the same rank)
-
toStrictPreference
public OldLinearPreferenceImpl toStrictPreference()
- Returns:
- the StrictPreference built from the preference if the preference is strict. If the preference is not strict it throws an IllegalArgumentException.
-
-