edu.claflin.finder.logic.comp

## Class EdgeWeightComparator

- java.lang.Object
- - edu.claflin.finder.logic.comp.EdgeWeightComparator

- All Implemented Interfaces:
    java.util.Comparator<Edge>

      public class EdgeWeightComparator
      extends java.lang.Object
      implements java.util.Comparator<Edge>

  A simple edge weight comparator in which the edge data is considered a numeric value and used as the comparison benchmark.
  Version:
    3.0 February 4, 2016
  Author:
    Charles Allen Schultz II

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private boolean` | `ascending` Indicates if the comparator should sort elements in ascending order.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EdgeWeightComparator(boolean ascending)` Constructs an EdgeWeightComparator.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compare(Edge o1, Edge o2)` Compares the edges based on the D data held by the edge.
    `private java.math.BigDecimal` | `toNumber(java.lang.Object object)` Converts an unknown object into a BigDecimal if possible.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.util.Comparator

      `comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- - ### Field Detail

    - #### ascending

          private final boolean ascending

      Indicates if the comparator should sort elements in ascending order.

  - ### Constructor Detail

    - #### EdgeWeightComparator

          public EdgeWeightComparator(boolean ascending)

      Constructs an EdgeWeightComparator.
      Parameters:
        `ascending` - boolean indicating if edges should be sorted in ascending order.

  - ### Method Detail

    - #### compare

          public int compare(Edge o1,
                             Edge o2)

      Compares the edges based on the D data held by the edge. Assumes the data is a numeric value.
      Specified by:
        `compare` in interface `java.util.Comparator<Edge>`
      Parameters:
        `o1` - the first edge to compare.
        `o2` - the second edge to compare.
      Returns:
        -1, 0, or 1 if the first edge is ordered before, the same as, or after the second.

    - #### toNumber

          private java.math.BigDecimal toNumber(java.lang.Object object)

      Converts an unknown object into a BigDecimal if possible.
      Parameters:
        `object` - the Object to convert.
      Returns:
        the converted BigDecimal object.