Uploaded image for project: 'Kylin'
  1. Kylin
  2. KYLIN-4327

TOPN Comparator may violate its general contract

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • v3.1.0, v3.0.1
    • None
    • None

    Description

      in current TopN, it should save top(k) result and keep it in double value, just like this:
      ```
      public class Counter<T> implements Serializable

      { ... protected T item; protected double count; ... }

      ```
      But its Comparator method use "==" directly to compare the result, it may cause the error "violate its general contract" when calling it.
      ```
      private static final Comparator ASC_COMPARATOR = new Comparator<Counter>() {
      @Override
      public int compare(Counter o1, Counter o2)

      { return o1.getCount() > o2.getCount() ? 1 : o1.getCount() == o2.getCount() ? 0 : -1; }

      };

      ```

      Attachments

        Issue Links

          Activity

            People

              Yifei_Wu94 Yifei Wu
              Yifei_Wu94 Yifei Wu
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: