Class MessageBodyFactory.DeclarationDistanceComparator<T>

  • Type Parameters:
    T - common super-type used for computing the declaration distance and comparing instances.
    All Implemented Interfaces:
    java.util.Comparator<T>
    Enclosing class:
    MessageBodyFactory

    private static class MessageBodyFactory.DeclarationDistanceComparator<T>
    extends java.lang.Object
    implements java.util.Comparator<T>
    Compares 2 instances implementing/inheriting the same super-type and returns which of the two instances has the super-type declaration closer in it's inheritance hierarchy tree.

    The comparator is optimized to cache results of the previous distance declaration computations.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class<T> declared  
      private java.util.Map<java.lang.Class,​java.lang.Integer> distanceMap  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(T o1, T o2)  
      private int getDistance​(T t)  
      • 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

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • declared

        private final java.lang.Class<T> declared
      • distanceMap

        private final java.util.Map<java.lang.Class,​java.lang.Integer> distanceMap
    • Constructor Detail

      • DeclarationDistanceComparator

        DeclarationDistanceComparator​(java.lang.Class<T> declared)
    • Method Detail

      • compare

        public int compare​(T o1,
                           T o2)
        Specified by:
        compare in interface java.util.Comparator<T>
      • getDistance

        private int getDistance​(T t)