Class PreferenceOrder<T>

  • Type Parameters:
    T - the generic type of objects/pairs in this preference order
    All Implemented Interfaces:
    java.lang.Iterable<Triple<T,​T,​Relation>>, java.util.Collection<Triple<T,​T,​Relation>>, java.util.Set<Triple<T,​T,​Relation>>, BinaryRelation<T>

    public class PreferenceOrder<T>
    extends java.lang.Object
    implements BinaryRelation<T>
    This class extends the BinaryRelation-class with a check for totality and transitivity
    Author:
    Bastian Wolf
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Set<Triple<T,​T,​Relation>> relations
      a given set of Triples
    • Constructor Summary

      Constructors 
      Constructor Description
      PreferenceOrder()
      Creates an empty HashSet of preference order.
      PreferenceOrder​(java.util.Collection<? extends Triple<T,​T,​Relation>> relations)
      generates a preference order with a given set of elements
    • Method Summary

      Modifier and Type Method Description
      boolean add​(Triple<T,​T,​Relation> t)
      adds a given pair of generic elements to the set.
      boolean addAll​(java.util.Collection<? extends Triple<T,​T,​Relation>> c)
      adds all given elements to the preference order
      boolean addPair​(T f, T s, Relation relation)
      adds two given (single) elements as pair into the set
      void clear()
      clears the current preference order element set
      boolean compareEqualityWith​(PreferenceOrder<T> po)
      compares this preference order to another given one whether each relation is contained in both
      boolean contains​(java.lang.Object o)
      checks whether this preference order contains a given pair
      boolean containsAll​(java.util.Collection<?> c)
      checks, whether all of the given elements are contained in the preference order
      boolean containsRelation​(T a, T b)
      checks whether this preference order contains a pair of given elements
      boolean containsTriple​(T firstElement, T secondElement, Relation relation)
      checks whether the given triple is contained
      boolean equals​(java.lang.Object obj)  
      Triple<T,​T,​Relation> get​(Triple<T,​T,​Relation> e)
      checks existence and returns a demanded pair
      java.util.Set<T> getDomainElements()
      (re-)computes a set of single elements in this preference order
      LevelingFunction<T> getLevelingFunction()
      returns the ranking function for this preference order
      Triple<T,​T,​Relation> getTriple​(T a, T b)
      returns a pair if it consists of of two given elements
      boolean isEmpty()
      returns whether the set is empty or not
      boolean isRelated​(T a, T b)
      returns whether the elements a and b are related
      boolean isTotal()
      checks whether the set is total or not
      boolean isTransitive()
      checks whether the given set is transitive or not
      boolean isValid()
      checks whether the given set represents a valid preference order
      java.util.Iterator<Triple<T,​T,​Relation>> iterator()  
      java.util.Iterator<Triple<T,​T,​Relation>> iterator​(java.util.Set<Triple<T,​T,​Relation>> s)
      returns an iterator over a set of triples
      boolean remove​(java.lang.Object o)
      removes specific pair of the set
      boolean removeAll​(java.util.Collection<?> c)
      removes all given elements from the preference order
      boolean retainAll​(java.util.Collection<?> c)  
      int size()
      returns the size of the set
      void strengthenElementInLF​(T element)
      strengthens the given element in this preference order in its leveling function
      void strengthenElementInRF​(T element)
      strengthens the given element in this preference order in its ranking function
      java.lang.Object[] toArray()
      returns an array containing all objects
      <T> T[] toArray​(T[] a)
      returns all elements in an array
      java.lang.String toString()
      returns a String with the elements of this set
      void weakenElementInLF​(T element)
      weakens the given element in this preference order in its leveling function
      void weakenElementInRF​(T element)
      weakens the given element in this preference order in its ranking function
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        hashCode, spliterator
    • Field Detail

      • relations

        private java.util.Set<Triple<T,​T,​Relation>> relations
        a given set of Triples
    • Constructor Detail

      • PreferenceOrder

        public PreferenceOrder()
        Creates an empty HashSet of preference order.
      • PreferenceOrder

        public PreferenceOrder​(java.util.Collection<? extends Triple<T,​T,​Relation>> relations)
        generates a preference order with a given set of elements
        Parameters:
        relations - the set of given element pairs
    • Method Detail

      • getLevelingFunction

        public LevelingFunction<T> getLevelingFunction()
        returns the ranking function for this preference order
        Returns:
        the ranking function for this preference order
      • add

        public boolean add​(Triple<T,​T,​Relation> t)
        adds a given pair of generic elements to the set.
        Specified by:
        add in interface BinaryRelation<T>
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.Set<T>
        Parameters:
        t - the given set
        Returns:
        true if successful, false if not
      • addPair

        public boolean addPair​(T f,
                               T s,
                               Relation relation)
        adds two given (single) elements as pair into the set
        Parameters:
        f - first element of the new pair
        s - second element of the new pair
        relation - the relation
        Returns:
        true if successful, false if not
      • getDomainElements

        public java.util.Set<T> getDomainElements()
        (re-)computes a set of single elements in this preference order
        Specified by:
        getDomainElements in interface BinaryRelation<T>
        Returns:
        a set of the single elements in this binary relation
      • remove

        public boolean remove​(java.lang.Object o)
        removes specific pair of the set
        Specified by:
        remove in interface java.util.Collection<T>
        Specified by:
        remove in interface java.util.Set<T>
        Parameters:
        o - the pair to be removed
        Returns:
        true if successful, false if not
      • isEmpty

        public boolean isEmpty()
        returns whether the set is empty or not
        Specified by:
        isEmpty in interface java.util.Collection<T>
        Specified by:
        isEmpty in interface java.util.Set<T>
        Returns:
        true if empty, false if not
      • isRelated

        public boolean isRelated​(T a,
                                 T b)
        returns whether the elements a and b are related
        Specified by:
        isRelated in interface BinaryRelation<T>
        Parameters:
        a - the first element to be checked
        b - the second element to be checked
        Returns:
        true if related, false if not.
      • iterator

        public java.util.Iterator<Triple<T,​T,​Relation>> iterator​(java.util.Set<Triple<T,​T,​Relation>> s)
        returns an iterator over a set of triples
        Parameters:
        s - a set of triples
        Returns:
        an iterator over a set of triples
      • get

        public Triple<T,​T,​Relation> get​(Triple<T,​T,​Relation> e)
        checks existence and returns a demanded pair
        Parameters:
        e - the demanded pair
        Returns:
        a pair if it exists, null otherwise
      • getTriple

        public Triple<T,​T,​Relation> getTriple​(T a,
                                                          T b)
        returns a pair if it consists of of two given elements
        Parameters:
        a - the first element
        b - the second element
        Returns:
        a pair if found, null if not
      • containsRelation

        public boolean containsRelation​(T a,
                                        T b)
        checks whether this preference order contains a pair of given elements
        Parameters:
        a - the first element
        b - the second element
        Returns:
        true if pair is in this preference order, false if not
      • contains

        public boolean contains​(java.lang.Object o)
        checks whether this preference order contains a given pair
        Specified by:
        contains in interface java.util.Collection<T>
        Specified by:
        contains in interface java.util.Set<T>
        Parameters:
        o - the given pair
        Returns:
        true if pair is in this preference order, false if not
      • containsTriple

        public boolean containsTriple​(T firstElement,
                                      T secondElement,
                                      Relation relation)
        checks whether the given triple is contained
        Parameters:
        firstElement - the first element
        secondElement - the second element
        relation - the relation
        Returns:
        true iff the given triple is contained
      • size

        public int size()
        returns the size of the set
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in interface java.util.Set<T>
        Returns:
        the size of the set
      • toString

        public java.lang.String toString()
        returns a String with the elements of this set
        Specified by:
        toString in interface BinaryRelation<T>
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String with the elements of this set
      • toArray

        public java.lang.Object[] toArray()
        returns an array containing all objects
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.Set<T>
        Returns:
        the Object[]-array
      • toArray

        public <T> T[] toArray​(T[] a)
        returns all elements in an array
        Specified by:
        toArray in interface java.util.Collection<T>
        Specified by:
        toArray in interface java.util.Set<T>
        Parameters:
        a - is a given array
        Returns:
        an array
      • isTotal

        public boolean isTotal()
        checks whether the set is total or not
        Specified by:
        isTotal in interface BinaryRelation<T>
        Returns:
        true if total, false otherwise
      • isTransitive

        public boolean isTransitive()
        checks whether the given set is transitive or not
        Specified by:
        isTransitive in interface BinaryRelation<T>
        Returns:
        true if transitive, false otherwise
      • isValid

        public boolean isValid()
        checks whether the given set represents a valid preference order
        Specified by:
        isValid in interface BinaryRelation<T>
        Returns:
        true if valid, false if not
      • clear

        public void clear()
        clears the current preference order element set
        Specified by:
        clear in interface java.util.Collection<T>
        Specified by:
        clear in interface java.util.Set<T>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> c)
        checks, whether all of the given elements are contained in the preference order
        Specified by:
        containsAll in interface java.util.Collection<T>
        Specified by:
        containsAll in interface java.util.Set<T>
        Returns:
        true iff all elements are contained, false otherwise
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        removes all given elements from the preference order
        Specified by:
        removeAll in interface java.util.Collection<T>
        Specified by:
        removeAll in interface java.util.Set<T>
        Returns:
        true if elements-set has changed, false if not
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<T>
        Specified by:
        retainAll in interface java.util.Set<T>
      • addAll

        public boolean addAll​(java.util.Collection<? extends Triple<T,​T,​Relation>> c)
        adds all given elements to the preference order
        Specified by:
        addAll in interface java.util.Collection<T>
        Specified by:
        addAll in interface java.util.Set<T>
        Returns:
        true if element-set changed, false if not
      • iterator

        public java.util.Iterator<Triple<T,​T,​Relation>> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in interface java.util.Set<T>
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Collection<T>
        Specified by:
        equals in interface java.util.Set<T>
        Overrides:
        equals in class java.lang.Object
      • compareEqualityWith

        public boolean compareEqualityWith​(PreferenceOrder<T> po)
        compares this preference order to another given one whether each relation is contained in both
        Parameters:
        po - the preference order to compare with
        Returns:
        true if both are equal, false if not
      • weakenElementInLF

        public void weakenElementInLF​(T element)
        weakens the given element in this preference order in its leveling function
        Parameters:
        element - the element to be weaken
      • strengthenElementInLF

        public void strengthenElementInLF​(T element)
        strengthens the given element in this preference order in its leveling function
        Parameters:
        element - the element to be strengthen
      • weakenElementInRF

        public void weakenElementInRF​(T element)
        weakens the given element in this preference order in its ranking function
        Parameters:
        element - the element to be weaken
      • strengthenElementInRF

        public void strengthenElementInRF​(T element)
        strengthens the given element in this preference order in its ranking function
        Parameters:
        element - the element to be strengthen