Class MutableLinearPreferenceImpl

    • 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: MutableLinearPreference
        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.
        Specified by:
        changeOrder in interface MutableLinearPreference
        Parameters:
        alternative - that we're going to move in the preference
        rank - 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: MutableLinearPreference
        Removes the specified alternative from this preference if it is present.
        Specified by:
        removeAlternative in interface MutableLinearPreference
        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: MutableLinearPreference
        Adds the specified alternative at the last rank of this preference if it is not already present.
        Specified by:
        addAlternative in interface MutableLinearPreference
        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: Preference
        The returned set reads through this object: if this object is mutable, any modification to this object modifies the returned set, and conversely.
        Specified by:
        getAlternatives in interface Preference
        Returns:
        alternatives's set
      • getVoter

        public Voter getVoter()
        Specified by:
        getVoter in interface Preference
        Returns:
        Voter instance 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: Preference
        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.
        Specified by:
        asGraph in interface Preference
        Returns:
        the Graph corresponding to the Preference
      • swap

        public boolean swap​(Alternative alternative1,
                            Alternative alternative2)
        Description copied from interface: MutableLinearPreference
        This method enables to swap 2 alternatives of the preference. (If the specified alternatives are equal, invoking this method leaves the preference unchanged.)
        Specified by:
        swap in interface MutableLinearPreference
        Parameters:
        alternative1 - that will change places with alternative2
        alternative2 - 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object