Class NaturalRanking.IntDoublePair

  • All Implemented Interfaces:
    java.lang.Comparable<NaturalRanking.IntDoublePair>
    Enclosing class:
    NaturalRanking

    private static class NaturalRanking.IntDoublePair
    extends java.lang.Object
    implements java.lang.Comparable<NaturalRanking.IntDoublePair>
    Represents the position of a double value in an ordering. Comparable interface is implemented so Arrays.sort can be used to sort an array of IntDoublePairs by value. Note that the implicitly defined natural ordering is NOT consistent with equals.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int position
      Original position of the pair
      private double value
      Value of the pair
    • Constructor Summary

      Constructors 
      Constructor Description
      IntDoublePair​(double value, int position)
      Construct an IntDoublePair with the given value and position.
    • Field Detail

      • value

        private final double value
        Value of the pair
      • position

        private final int position
        Original position of the pair
    • Constructor Detail

      • IntDoublePair

        IntDoublePair​(double value,
                      int position)
        Construct an IntDoublePair with the given value and position.
        Parameters:
        value - the value of the pair
        position - the original position
    • Method Detail

      • compareTo

        public int compareTo​(NaturalRanking.IntDoublePair other)
        Compare this IntDoublePair to another pair. Only the values are compared.
        Specified by:
        compareTo in interface java.lang.Comparable<NaturalRanking.IntDoublePair>
        Parameters:
        other - the other pair to compare this to
        Returns:
        result of Double.compare(value, other.value)
      • getValue

        public double getValue()
        Returns the value of the pair.
        Returns:
        value
      • getPosition

        public int getPosition()
        Returns the original position of the pair.
        Returns:
        position