Class OldCompletePreferenceImpl
- java.lang.Object
-
- io.github.oliviercailloux.j_voting.OldCompletePreferenceImpl
-
- Direct Known Subclasses:
OldLinearPreferenceImpl
public class OldCompletePreferenceImpl extends Object
Immutable class. A Preference represents a list of alternatives, sorted by order of preference. Two alternatives can be equally ranked. There cannot be twice the same alternative.
-
-
Field Summary
Fields Modifier and Type Field Description protected List<Set<Alternative>>
preference
-
Constructor Summary
Constructors Modifier Constructor Description protected
OldCompletePreferenceImpl(List<Set<Alternative>> preference)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(Alternative alter)
static OldCompletePreferenceImpl
createCompletePreferenceImpl(List<Set<Alternative>> preference)
Factory method for CompletePreferenceImplboolean
equals(Object o)
Alternative
getAlternative(Integer position)
int
getAlternativeRank(Alternative alter)
List<Set<Alternative>>
getPreferencesNonStrict()
int
hashCode()
boolean
hasSameAlternatives(OldCompletePreferenceImpl p)
boolean
isIncludedIn(OldCompletePreferenceImpl p)
boolean
isStrict()
int
size()
static int
size(List<Set<Alternative>> list)
static Set<Alternative>
toAlternativeSet(List<Set<Alternative>> preference)
OldLinearPreferenceImpl
toStrictPreference()
String
toString()
-
-
-
Field Detail
-
preference
protected List<Set<Alternative>> preference
-
-
Constructor Detail
-
OldCompletePreferenceImpl
protected OldCompletePreferenceImpl(List<Set<Alternative>> preference)
- Parameters:
preferences
-not null
a list of sets of alternatives. In a set, the alternatives are equally ranked. The sets are sorted by preference in the list. If an alternative is present several times, an IllegalArgumentException is thrown.
-
-
Method Detail
-
getAlternative
public Alternative getAlternative(Integer position) throws IndexOutOfBoundsException
- Parameters:
position
- notnull
- Returns:
- the alternative at the position given in the strict preference
- Throws:
IndexOutOfBoundsException
-
getPreferencesNonStrict
public List<Set<Alternative>> getPreferencesNonStrict()
- Returns:
- the preference of alternatives
-
size
public int size()
- Returns:
- the size of the Preference, i.e. the number of alternatives in the Preference
-
contains
public boolean contains(Alternative alter)
- Parameters:
alter
-not null
- Returns:
- whether the preference contains the alternative given as parameter
-
hasSameAlternatives
public boolean hasSameAlternatives(OldCompletePreferenceImpl p)
- Parameters:
p
-not null
- Returns:
- whether the preferences are about the same alternatives exactly (not necessarily in the same order).
-
isIncludedIn
public boolean isIncludedIn(OldCompletePreferenceImpl p)
- Parameters:
p
-not null
- Returns:
- whether the parameter preference contains all the alternatives in the calling preference
-
getAlternativeRank
public int getAlternativeRank(Alternative alter)
- Parameters:
alter
- notnull
. If the alternative is not in the preference, it throws an IllegalArgumentException.- Returns:
- the rank of the alternative given in the Preference.
-
toAlternativeSet
public static Set<Alternative> toAlternativeSet(List<Set<Alternative>> preference)
- Parameters:
preferences
- notnull
a list of sets of alternatives- Returns:
- a set of alternatives containing all the alternatives of the list of set of alternative given. If an alternative appears several times in the list of sets, it appears only once in the new set.
-
size
public static int size(List<Set<Alternative>> list)
- Parameters:
list
- notnull
- Returns:
- the size of a list of alternative sets
-
createCompletePreferenceImpl
public static OldCompletePreferenceImpl createCompletePreferenceImpl(List<Set<Alternative>> preference)
Factory method for CompletePreferenceImpl- Parameters:
preference
-not null
and all alternatives differents- Returns:
- a new CompletePreferenceImpl
-
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.
-
-