Class ClassArraySorter.Key

java.lang.Object
org.bzdev.util.ClassArraySorter.Key
Enclosing class:
ClassArraySorter

public static class ClassArraySorter.Key extends Object
Class providing a key representing an array of classes. Keys used for entries in a ClassArraySorter will typically be created using the constructor Key(Class[]). The remaining constructors provide keys that may be matched against those in the sorter.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Key(Class<?>[] types)
    Constructor.
    Key(Class<?>[] types, boolean allowNull)
    Constructor with possibly null array entries.
    Key(Class<?>[] types, boolean allowNull, int[] argcount)
    Constructor with possibly null array entries and an argument-count array, but no object-map array.
    Key(Class<?>[] types, boolean allowNull, int[] argcount, ClassArraySorter.ArgCountMap[] objectMaps)
    Constructor with possibly null array entries, an argument-count array, and an object-map array.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    int
     
    boolean
    Check that each class in this Key is assignable from the corresponding class in the argument Key.
    boolean
    Check that each class in this Key is assignable from the corresponding class in the argument Key after a permissible cast.
    void
    Change primitive types to their corresponding subclasses of Number.
    int
    Get the number of classes in this key.
    Class<?>[]
    Convert this key to an array
    Class<?>[]
    toArray(Class<?>[] array)
    Convert this key to an array given an existing array.
     
    void
    Indicate that this key represents a parameter list for a method with a variable number of arguments.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Key

      public Key(Class<?>[] types)
      Constructor.
      Parameters:
      types - an array of classes that the key represents
    • Key

      public Key(Class<?>[] types, boolean allowNull)
      Constructor with possibly null array entries. If one of the types is null, that entry is assumed to match any class when the key is passed as an argument to isAssignableFrom(Key) or isAssignableFrom(Key,boolean).
      Parameters:
      types - an array of classes that the key represents
      allowNull - true if null values are allowed in the types array
    • Key

      public Key(Class<?>[] types, boolean allowNull, int[] argcount) throws IllegalArgumentException
      Constructor with possibly null array entries and an argument-count array, but no object-map array. If one of the types in the types array is null, that entry is assumed to match any class when the key is passed as an argument to isAssignableFrom(Key) or isAssignableFrom(Key,boolean). The parameter argcount is an array with the same length as the array passed in the types argument. When an element of the argcount array has a non-negative value and the key is used as an argument for isAssignableFrom(Key) or isAssignableFrom(Key,boolean), and a match for a specific element in the array would fail, an alternative test is used. For the expression key1.isAssignableFrom(key2) key1.isAssignableFrom(key2, true), or key1.isAssignableFrom(key2, false), let c1 be an element in key1's class array and let c2 be the corresponding element in key2's class array, and let cnt be the corresponding value of key2's argcount array. If c1.isAssignableFrom(c2) is true, the entries match. If c1.isAssignableFrom(c2) is false, there are several cases:
      • if key2's argcount array entry corresponding to e2 has a non-negative value, then the element also matches if c1 is a functional interface (i.e., has the annotation FunctionalInterface, and has a public instance method that is not a default method and whose number of arguments is cnt.
      • if key2's argcount array entry corresponding to c2 has the value ClassArraySorter.INTERFACE_TEST, an error will occur with this constructor as an object map is required for this case.
      • if key2's argcount array entry corresponding to e2 has the value ClassArraySorter.NO_ARGCOUNT_TEST, then the elements do not match.
      Parameters:
      types - an array of classes that the key represents
      allowNull - true if null values are allowed in the types array
      argcount - the argument-count array
      Throws:
      IllegalArgumentException - an argument was not consistent with this constructor.
    • Key

      public Key(Class<?>[] types, boolean allowNull, int[] argcount, ClassArraySorter.ArgCountMap[] objectMaps) throws IllegalArgumentException
      Constructor with possibly null array entries, an argument-count array, and an object-map array. If one of the types in the types array is null, that entry is assumed to match any class when the key is passed as an argument to isAssignableFrom(Key) or isAssignableFrom(Key,boolean). The parameter argcount is an array with the same length as the array passed in the types argument. When an element of the argcount array has a non-negative value and the key is used as an argument for isAssignableFrom(Key) or isAssignableFrom(Key,boolean), and a match for a specific element in the array would fail, an alternative test is used. For the expression key1.isAssignableFrom(key2) key1.isAssignableFrom(key2, true), or key1.isAssignableFrom(key2, false), let c1 be and element in key1's class array and let c2 be an element in key2's class array, and let cnt be the corresponding value of key2's argcount array. If c1.isAssignableFrom(c2) is true, the entries match. If c1.isAssignableFrom(c2) is false, there are several cases:
      • if key2's argcount array entry corresponding to e2 has a non-negative value, then the element also matches if c1 is a functional interface (i.e., has the annotation FunctionalInterface, and has a public instance method that is not a default method and whose number of arguments is cnt.
      • if key2's argcount array entry corresponding to c2 has the value ClassArraySorter.INTERFACE_TEST, and c1 is an interface and then the supplied map, if any, is tested against the interface's public, non-default methods. If the value in the map for such a method's name does not matches the number of arguments that method has, the test fails. Otherwise the test fails.
      • if key2's argcount array entry corresponding to e2 has the value ClassArraySorter.NO_ARGCOUNT_TEST, then the elements do not match.
      Parameters:
      types - an array of classes that the key represents
      allowNull - true if null values are allowed in the types array
      argcount - the argument-count array
      objectMaps - the object-map array, each entry of which maps the names of methods to the expected argument count for that method.
      Throws:
      IllegalArgumentException - an object map was required but not provided or the argument allowNull was false while one of the elements in the types argument was null
  • Method Details

    • varargsMode

      public void varargsMode() throws IllegalStateException
      Indicate that this key represents a parameter list for a method with a variable number of arguments. When called, the key must contain at least one class in its array and the last element must be an array.
      Throws:
      IllegalStateException - the key is not compatible with a parameter list for a method or constructor that takes a variable number of arguments
    • promotePrimitives

      public void promotePrimitives()
      Change primitive types to their corresponding subclasses of Number.
    • size

      public int size()
      Get the number of classes in this key.
      Returns:
      the number of classes in this key
    • toArray

      public Class<?>[] toArray()
      Convert this key to an array
      Returns:
      an array containing classes in the same order in which they were entered
    • toArray

      public Class<?>[] toArray(Class<?>[] array)
      Convert this key to an array given an existing array. If the existing array is as long as or longer than the array that is needed, that array will be used. Otherwise a new array will be allocated.
      Parameters:
      array - to store the values; null if a new array should be allocated
      Returns:
      an array containing classes in the same order in which they were entered
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • isAssignableFrom

      public boolean isAssignableFrom(ClassArraySorter.Key key)
      Check that each class in this Key is assignable from the corresponding class in the argument Key.
      Parameters:
      key - the argument key
      Returns:
      true if the classes in this key are assignable from the classes in the argument key; false othewise
    • isAssignableFrom

      public boolean isAssignableFrom(ClassArraySorter.Key key, boolean cast)
      Check that each class in this Key is assignable from the corresponding class in the argument Key after a permissible cast. If this key represents the parameters for a method with a variable number of arguments, the argument key should provide the classes for the arguments passed in a method call.
      Parameters:
      key - the argument key
      cast - true if the argument key's numerical types should be cast to this key's type.
      Returns:
      true if the classes in this key are assignable from the classes in the argument key; false othewise
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object