Package mondrian.util

Class Pair<L,​R>

  • All Implemented Interfaces:
    java.lang.Comparable<Pair<L,​R>>, java.util.Map.Entry<L,​R>
    Direct Known Subclasses:
    SchemaKey

    public class Pair<L,​R>
    extends java.lang.Object
    implements java.lang.Comparable<Pair<L,​R>>, java.util.Map.Entry<L,​R>
    Pair of values.

    Because a pair implements equals(Object), hashCode() and compareTo(Pair), it can be used in any kind of Collection.

    Since:
    Apr 19, 2007
    Author:
    jhyde
    • Field Summary

      Fields 
      Modifier and Type Field Description
      L left  
      R right  
    • Constructor Summary

      Constructors 
      Constructor Description
      Pair​(java.util.Map.Entry<? extends L,​? extends R> entry)
      Creates a pair representing the same mapping as the specified entry.
      Pair​(L left, R right)
      Creates a pair.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Pair<L,​R> that)  
      boolean equals​(java.lang.Object obj)  
      L getKey()  
      R getValue()  
      int hashCode()  
      static <L,​R>
      java.util.List<L>
      left​(java.util.List<Pair<L,​R>> list)
      Returns a list of the left elements of a list of pairs.
      static <L,​R>
      java.lang.Iterable<L>
      leftIter​(java.lang.Iterable<Pair<L,​R>> iterable)
      Returns an iterable over the left slice of an iterable.
      static <L,​R>
      Pair<L,​R>
      of​(L left, R right)
      Creates a Pair.
      static <L,​R>
      java.util.List<R>
      right​(java.util.List<Pair<L,​R>> list)
      Returns a list of the right elements of a list of pairs.
      static <L,​R>
      java.lang.Iterable<R>
      rightIter​(java.lang.Iterable<Pair<L,​R>> iterable)
      Returns an iterable over the right slice of an iterable.
      R setValue​(R value)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • left

        public L left
      • right

        public R right
    • Constructor Detail

      • Pair

        public Pair​(L left,
                    R right)
        Creates a pair.
        Parameters:
        left - Left value
        right - Right value
      • Pair

        public Pair​(java.util.Map.Entry<? extends L,​? extends R> entry)
        Creates a pair representing the same mapping as the specified entry.
        Parameters:
        entry - the entry to copy
    • Method Detail

      • of

        public static <L,​R> Pair<L,​R> of​(L left,
                                                     R right)
        Creates a Pair.
        Parameters:
        left - Left value
        right - Right value
        Returns:
        a new Pair
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Map.Entry<L,​R>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map.Entry<L,​R>
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public int compareTo​(Pair<L,​R> that)
        Specified by:
        compareTo in interface java.lang.Comparable<L>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getKey

        public L getKey()
        Specified by:
        getKey in interface java.util.Map.Entry<L,​R>
      • getValue

        public R getValue()
        Specified by:
        getValue in interface java.util.Map.Entry<L,​R>
      • setValue

        public R setValue​(R value)
        Specified by:
        setValue in interface java.util.Map.Entry<L,​R>
      • leftIter

        public static <L,​R> java.lang.Iterable<L> leftIter​(java.lang.Iterable<Pair<L,​R>> iterable)
        Returns an iterable over the left slice of an iterable.
        Type Parameters:
        L - Left type
        R - Right type
        Parameters:
        iterable - Iterable over pairs
        Returns:
        Iterable over the left elements
      • rightIter

        public static <L,​R> java.lang.Iterable<R> rightIter​(java.lang.Iterable<Pair<L,​R>> iterable)
        Returns an iterable over the right slice of an iterable.
        Type Parameters:
        L - right type
        R - Right type
        Parameters:
        iterable - Iterable over pairs
        Returns:
        Iterable over the right elements
      • left

        public static <L,​R> java.util.List<L> left​(java.util.List<Pair<L,​R>> list)
        Returns a list of the left elements of a list of pairs.
      • right

        public static <L,​R> java.util.List<R> right​(java.util.List<Pair<L,​R>> list)
        Returns a list of the right elements of a list of pairs.