Class Weights

java.lang.Object
io.helidon.common.Weights

public final class Weights extends Object
Weight utilities.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    find(Class<?> aClass, double defaultWeight)
    Find weight from class annotation, or return default if none found.
    static double
    find(Object anObject, double defaultWeight)
    Find weight for an instance.
    static void
    sort(List<?> list)
    Sort the list based on weights.
    static <S> Comparator<S>
    Returns a comparator for two objects, the classes for which are implementations of Weighted, and/or optionally annotated with Weight and which applies a specified default weight if either or both classes lack the annotation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • find

      public static double find(Class<?> aClass, double defaultWeight)
      Find weight from class annotation, or return default if none found.
      Parameters:
      aClass - class to analyzed
      defaultWeight - default weight of this class
      Returns:
      weight from Weight or the default provided
    • find

      public static double find(Object anObject, double defaultWeight)
      Find weight for an instance. First checks if instance is Weighted. If so, uses the value from it. Then checks for Weight annotation. If none of the above is found, returns the default weight.
      Parameters:
      anObject - object to find weight for
      defaultWeight - default weight to use
      Returns:
      weight of the object or default provided
    • sort

      public static void sort(List<?> list)
      Sort the list based on weights.
      • If element implements Weighted, uses its weight.
      • If element is a class and has annotation Weight, uses its weight
      • If element is any object and its class has annotation Weight, uses its weight
      Parameters:
      list - list to sort
    • weightComparator

      public static <S> Comparator<S> weightComparator()
      Returns a comparator for two objects, the classes for which are implementations of Weighted, and/or optionally annotated with Weight and which applies a specified default weight if either or both classes lack the annotation.
      Type Parameters:
      S - type of object being compared
      Returns:
      comparator