/** * <p>Gets the canonical name for an {@code Object}.</p> * * @param object the object for which to get the canonical class name; may be null * @return the canonical name of the object, or the empty String * @since 3.7 * @see Class#getCanonicalName() */ public static String getCanonicalName(final Object object) { return getCanonicalName(object, StringUtils.EMPTY); }
/** * <p>Gets the canonical class name for a {@code Class}.</p> * * @param cls the class for which to get the canonical class name; may be null * @return the canonical name of the class, or the empty String * @since 3.7 * @see Class#getCanonicalName() */ public static String getCanonicalName(final Class<?> cls) { return getCanonicalName(cls, StringUtils.EMPTY); }
/** * <p>Gets the canonical name minus the package name from a String.</p> * * <p>The string passed in is assumed to be a canonical name - it is not checked.</p> * * @param canonicalName the class name to get the short name for * @return the canonical name of the class without the package name or an empty string * @since 2.4 */ public static String getShortCanonicalName(final String canonicalName) { return getShortClassName(getCanonicalName(canonicalName)); }
/** * <p>Gets the package name from the canonical name. </p> * * <p>The string passed in is assumed to be a canonical name - it is not checked.</p> * <p>If the class is unpackaged, return an empty string.</p> * * @param canonicalName the canonical name to get the package name for, may be {@code null} * @return the package name or an empty string * @since 2.4 */ public static String getPackageCanonicalName(final String canonicalName) { return getPackageName(getCanonicalName(canonicalName)); }
@Test public void test_getCanonicalName_Class_String() { assertEquals("org.apache.commons.lang3.ClassUtils", ClassUtils.getCanonicalName(ClassUtils.class, "X")); assertEquals("java.util.Map.Entry", ClassUtils.getCanonicalName(Map.Entry.class, "X")); assertEquals("X", ClassUtils.getCanonicalName((Class<?>) null, "X")); assertEquals("java.lang.String[]", ClassUtils.getCanonicalName(String[].class, "X")); assertEquals("java.util.Map.Entry[]", ClassUtils.getCanonicalName(Map.Entry[].class, "X")); assertEquals("boolean", ClassUtils.getCanonicalName(boolean.class, "X")); assertEquals("byte", ClassUtils.getCanonicalName(byte.class, "X")); assertEquals("char", ClassUtils.getCanonicalName(char.class, "X")); assertEquals("short", ClassUtils.getCanonicalName(short.class, "X")); assertEquals("int", ClassUtils.getCanonicalName(int.class, "X")); assertEquals("long", ClassUtils.getCanonicalName(long.class, "X")); assertEquals("float", ClassUtils.getCanonicalName(float.class, "X")); assertEquals("double", ClassUtils.getCanonicalName(double.class, "X")); assertEquals("boolean[]", ClassUtils.getCanonicalName(boolean[].class, "X")); assertEquals("byte[]", ClassUtils.getCanonicalName(byte[].class, "X")); assertEquals("char[]", ClassUtils.getCanonicalName(char[].class, "X")); assertEquals("short[]", ClassUtils.getCanonicalName(short[].class, "X")); assertEquals("int[]", ClassUtils.getCanonicalName(int[].class, "X")); assertEquals("long[]", ClassUtils.getCanonicalName(long[].class, "X")); assertEquals("float[]", ClassUtils.getCanonicalName(float[].class, "X")); assertEquals("double[]", ClassUtils.getCanonicalName(double[].class, "X")); assertEquals("java.lang.String[][]", ClassUtils.getCanonicalName(String[][].class, "X")); assertEquals("java.lang.String[][][]", ClassUtils.getCanonicalName(String[][][].class, "X")); assertEquals("java.lang.String[][][][]", ClassUtils.getCanonicalName(String[][][][].class, "X"));
@Test public void test_getCanonicalName_Class() { assertEquals("org.apache.commons.lang3.ClassUtils", ClassUtils.getCanonicalName(ClassUtils.class)); assertEquals("java.util.Map.Entry", ClassUtils.getCanonicalName(Map.Entry.class)); assertEquals("", ClassUtils.getCanonicalName((Class<?>) null)); assertEquals("java.lang.String[]", ClassUtils.getCanonicalName(String[].class)); assertEquals("java.util.Map.Entry[]", ClassUtils.getCanonicalName(Map.Entry[].class)); assertEquals("boolean", ClassUtils.getCanonicalName(boolean.class)); assertEquals("byte", ClassUtils.getCanonicalName(byte.class)); assertEquals("char", ClassUtils.getCanonicalName(char.class)); assertEquals("short", ClassUtils.getCanonicalName(short.class)); assertEquals("int", ClassUtils.getCanonicalName(int.class)); assertEquals("long", ClassUtils.getCanonicalName(long.class)); assertEquals("float", ClassUtils.getCanonicalName(float.class)); assertEquals("double", ClassUtils.getCanonicalName(double.class)); assertEquals("boolean[]", ClassUtils.getCanonicalName(boolean[].class)); assertEquals("byte[]", ClassUtils.getCanonicalName(byte[].class)); assertEquals("char[]", ClassUtils.getCanonicalName(char[].class)); assertEquals("short[]", ClassUtils.getCanonicalName(short[].class)); assertEquals("int[]", ClassUtils.getCanonicalName(int[].class)); assertEquals("long[]", ClassUtils.getCanonicalName(long[].class)); assertEquals("float[]", ClassUtils.getCanonicalName(float[].class)); assertEquals("double[]", ClassUtils.getCanonicalName(double[].class)); assertEquals("java.lang.String[][]", ClassUtils.getCanonicalName(String[][].class)); assertEquals("java.lang.String[][][]", ClassUtils.getCanonicalName(String[][][].class)); assertEquals("java.lang.String[][][][]", ClassUtils.getCanonicalName(String[][][][].class));
/** * <p>Gets the canonical class name for a {@code Class}.</p> * * @param cls the class for which to get the canonical class name; may be null * @return the canonical name of the class, or the empty String * @since 3.7 * @see Class#getCanonicalName() */ public static String getCanonicalName(final Class<?> cls) { return getCanonicalName(cls, StringUtils.EMPTY); }
/** * <p>Gets the canonical class name for a {@code Class}.</p> * * @param cls the class for which to get the canonical class name; may be null * @return the canonical name of the class, or the empty String * @since 3.7 * @see Class#getCanonicalName() */ public static String getCanonicalName(final Class<?> cls) { return getCanonicalName(cls, StringUtils.EMPTY); }
/** * <p>Gets the canonical name for an {@code Object}.</p> * * @param object the object for which to get the canonical class name; may be null * @return the canonical name of the object, or the empty String * @since 3.7 * @see Class#getCanonicalName() */ public static String getCanonicalName(final Object object) { return getCanonicalName(object, StringUtils.EMPTY); }
/** * <p>Gets the canonical name for an {@code Object}.</p> * * @param object the object for which to get the canonical class name; may be null * @return the canonical name of the object, or the empty String * @since 3.7 * @see Class#getCanonicalName() */ public static String getCanonicalName(final Object object) { return getCanonicalName(object, StringUtils.EMPTY); }
/** * <p>Gets the canonical name for an {@code Object}.</p> * * @param object the object for which to get the canonical class name; may be null * @return the canonical name of the object, or the empty String * @since 3.7 * @see Class#getCanonicalName() */ public static String getCanonicalName(final Object object) { return getCanonicalName(object, StringUtils.EMPTY); }
/** * <p>Gets the canonical class name for a {@code Class}.</p> * * @param cls the class for which to get the canonical class name; may be null * @return the canonical name of the class, or the empty String * @since 3.7 * @see Class#getCanonicalName() */ public static String getCanonicalName(final Class<?> cls) { return getCanonicalName(cls, StringUtils.EMPTY); }
/** * <p>Gets the canonical name minus the package name from a String.</p> * * <p>The string passed in is assumed to be a canonical name - it is not checked.</p> * * @param canonicalName the class name to get the short name for * @return the canonical name of the class without the package name or an empty string * @since 2.4 */ public static String getShortCanonicalName(final String canonicalName) { return getShortClassName(getCanonicalName(canonicalName)); }
/** * <p>Gets the canonical name minus the package name from a String.</p> * * <p>The string passed in is assumed to be a canonical name - it is not checked.</p> * * @param canonicalName the class name to get the short name for * @return the canonical name of the class without the package name or an empty string * @since 2.4 */ public static String getShortCanonicalName(final String canonicalName) { return getShortClassName(getCanonicalName(canonicalName)); }
/** * <p>Gets the canonical name minus the package name from a String.</p> * * <p>The string passed in is assumed to be a canonical name - it is not checked.</p> * * @param canonicalName the class name to get the short name for * @return the canonical name of the class without the package name or an empty string * @since 2.4 */ public static String getShortCanonicalName(final String canonicalName) { return getShortClassName(getCanonicalName(canonicalName)); }
/** * <p>Gets the package name from the canonical name. </p> * * <p>The string passed in is assumed to be a canonical name - it is not checked.</p> * <p>If the class is unpackaged, return an empty string.</p> * * @param canonicalName the canonical name to get the package name for, may be {@code null} * @return the package name or an empty string * @since 2.4 */ public static String getPackageCanonicalName(final String canonicalName) { return getPackageName(getCanonicalName(canonicalName)); }
/** * <p>Gets the package name from the canonical name. </p> * * <p>The string passed in is assumed to be a canonical name - it is not checked.</p> * <p>If the class is unpackaged, return an empty string.</p> * * @param canonicalName the canonical name to get the package name for, may be {@code null} * @return the package name or an empty string * @since 2.4 */ public static String getPackageCanonicalName(final String canonicalName) { return getPackageName(getCanonicalName(canonicalName)); }
/** * <p>Gets the package name from the canonical name. </p> * * <p>The string passed in is assumed to be a canonical name - it is not checked.</p> * <p>If the class is unpackaged, return an empty string.</p> * * @param canonicalName the canonical name to get the package name for, may be {@code null} * @return the package name or an empty string * @since 2.4 */ public static String getPackageCanonicalName(final String canonicalName) { return getPackageName(getCanonicalName(canonicalName)); }