Class ClassUtilities

java.lang.Object
com.cedarsoftware.util.ClassUtilities

public class ClassUtilities extends Object
Useful utilities for Class work. For example, call computeInheritanceDistance(source, destination) to get the inheritance distance (number of super class steps to make it from source to destination. It will return the distance as an integer. If there is no inheritance relationship between the two, then -1 is returned. The primitives and primitive wrappers return 0 distance as if they are the same class.

Author:
John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

License

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  • Constructor Details

    • ClassUtilities

      public ClassUtilities()
  • Method Details

    • computeInheritanceDistance

      public static int computeInheritanceDistance(Class<?> source, Class<?> destination)
      Computes the inheritance distance between two classes/interfaces/primitive types.
      Parameters:
      source - The source class, interface, or primitive type.
      destination - The destination class, interface, or primitive type.
      Returns:
      The number of steps from the source to the destination, or -1 if no path exists.
    • isPrimitive

      public static boolean isPrimitive(Class<?> c)
      Parameters:
      c - Class to test
      Returns:
      boolean true if the passed in class is a Java primitive, false otherwise. The Wrapper classes Integer, Long, Boolean, etc. are considered primitives by this method.
    • forName

      public static Class<?> forName(String name, ClassLoader classLoader)
      Given the passed in String class name, return the named JVM class.
      Parameters:
      name - String name of a JVM class.
      classLoader - ClassLoader to use when searching for JVM classes.
      Returns:
      Class instance of the named JVM class or null if not found.
    • isClassFinal

      public static boolean isClassFinal(Class<?> c)
    • areAllConstructorsPrivate

      public static boolean areAllConstructorsPrivate(Class<?> c)
    • toPrimitiveWrapperClass

      public static Class<?> toPrimitiveWrapperClass(Class<?> primitiveClass)
    • doesOneWrapTheOther

      public static boolean doesOneWrapTheOther(Class<?> x, Class<?> y)