Skip to content

Commit 0bb2a8d

Browse files
CopilotCopilot
andcommitted
Add JavaDoc comments to undocumented non-private members in ClassUtils
Add JavaDoc with Example Usage sections to the following items in ClassUtils.java that were missing documentation: - PRIMITIVE_TYPES: immutable set of all Java primitive types - WRAPPER_TYPES: immutable set of all Java primitive wrapper types - PRIMITIVE_ARRAY_TYPES: immutable set of all Java primitive array types - concreteClassCache: synchronized weak-key map for concrete class caching - getSimpleName(Class, String): extracts simple name handling nested classes - isAsciiDigit(char): checks if a character is an ASCII digit Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a118e1e commit 0bb2a8d

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

microsphere-java-core/src/main/java/io/microsphere/util/ClassUtils.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,58 @@ public abstract class ClassUtils implements Utils {
132132
Double.class
133133
);
134134

135+
/**
136+
* An immutable {@link Set} containing all Java primitive types:
137+
* {@code void}, {@code boolean}, {@code byte}, {@code char}, {@code short},
138+
* {@code int}, {@code long}, {@code float}, and {@code double}.
139+
*
140+
* <h3>Example Usage</h3>
141+
* <pre>{@code
142+
* boolean isPrimitive = ClassUtils.PRIMITIVE_TYPES.contains(int.class); // true
143+
* boolean isNotPrimitive = ClassUtils.PRIMITIVE_TYPES.contains(Integer.class); // false
144+
* int count = ClassUtils.PRIMITIVE_TYPES.size(); // 9 (includes void)
145+
* }</pre>
146+
*
147+
* @since 1.0.0
148+
*/
135149
@Nonnull
136150
@Immutable
137151
public static final Set<Class<?>> PRIMITIVE_TYPES = ofSet(PRIMITIVE_TYPES_ARRAY);
138152

153+
/**
154+
* An immutable {@link Set} containing all Java primitive wrapper types:
155+
* {@link Void}, {@link Boolean}, {@link Byte}, {@link Character}, {@link Short},
156+
* {@link Integer}, {@link Long}, {@link Float}, and {@link Double}.
157+
*
158+
* <h3>Example Usage</h3>
159+
* <pre>{@code
160+
* boolean isWrapper = ClassUtils.WRAPPER_TYPES.contains(Integer.class); // true
161+
* boolean isNotWrapper = ClassUtils.WRAPPER_TYPES.contains(int.class); // false
162+
* for (Class<?> wrapperType : ClassUtils.WRAPPER_TYPES) {
163+
* System.out.println(wrapperType.getSimpleName());
164+
* }
165+
* }</pre>
166+
*
167+
* @since 1.0.0
168+
*/
139169
@Nonnull
140170
@Immutable
141171
public static final Set<Class<?>> WRAPPER_TYPES = ofSet(WRAPPER_TYPES_ARRAY);
142172

173+
/**
174+
* An immutable {@link Set} containing all Java primitive array types:
175+
* {@code boolean[]}, {@code char[]}, {@code byte[]}, {@code short[]},
176+
* {@code int[]}, {@code long[]}, {@code float[]}, and {@code double[]}.
177+
*
178+
* <h3>Example Usage</h3>
179+
* <pre>{@code
180+
* boolean isPrimArray = ClassUtils.PRIMITIVE_ARRAY_TYPES.contains(int[].class); // true
181+
* boolean isNotPrimArray = ClassUtils.PRIMITIVE_ARRAY_TYPES.contains(Integer[].class); // false
182+
* int count = ClassUtils.PRIMITIVE_ARRAY_TYPES.size(); // 8
183+
* }</pre>
184+
*
185+
* @since 1.0.0
186+
*/
143187
@Nonnull
144188
@Immutable
145189
public static final Set<Class<?>> PRIMITIVE_ARRAY_TYPES = ofSet(
@@ -251,6 +295,20 @@ public abstract class ClassUtils implements Utils {
251295
NAME_TO_TYPE_PRIMITIVE_MAP = unmodifiableMap(primitiveTypeNameMap);
252296
}
253297

298+
/**
299+
* A synchronized {@link WeakHashMap}-backed cache that stores whether a given {@link Class}
300+
* is a concrete class. Weak keys allow entries to be garbage-collected when the class is
301+
* no longer strongly reachable.
302+
*
303+
* <h3>Example Usage</h3>
304+
* <pre>{@code
305+
* // Internal cache used by isConcreteClass(Class):
306+
* boolean concrete = ClassUtils.isConcreteClass(String.class); // true, result cached
307+
* boolean abstractType = ClassUtils.isConcreteClass(Number.class); // false, result cached
308+
* }</pre>
309+
*
310+
* @since 1.0.0
311+
*/
254312
static final Map<Class<?>, Boolean> concreteClassCache = synchronizedMap(new WeakHashMap<>());
255313

256314
private static final FileExtensionFilter JAR_FILE_EXTENSION_FILTER = of(JAR_EXTENSION);
@@ -1873,6 +1931,28 @@ private static String getSimpleName(Class<?> type, boolean array) {
18731931
return getSimpleName(type, type.getName());
18741932
}
18751933

1934+
/**
1935+
* Extracts the simple name of a class from its fully qualified class name, handling
1936+
* top-level, nested, inner, and anonymous classes. For top-level classes, the portion
1937+
* after the last dot is returned. For enclosed classes, the leading enclosing class
1938+
* name and any numeric prefix (used for anonymous classes) are stripped.
1939+
*
1940+
* <h3>Example Usage</h3>
1941+
* <pre>{@code
1942+
* String name1 = ClassUtils.getSimpleName(String.class, "java.lang.String");
1943+
* // Returns: "String"
1944+
*
1945+
* // For an inner class like java.util.Map.Entry:
1946+
* String name2 = ClassUtils.getSimpleName(Map.Entry.class, "java.util.Map$Entry");
1947+
* // Returns: "Entry"
1948+
* }</pre>
1949+
*
1950+
* @param type the class whose simple name is to be extracted, must not be {@code null}
1951+
* @param className the fully qualified name of the class
1952+
* @return the simple name of the class, or an empty string for anonymous classes
1953+
* @throws InternalError if the class name is malformed for an enclosed class
1954+
* @since 1.0.0
1955+
*/
18761956
static String getSimpleName(Class<?> type, String className) {
18771957
String simpleName = className;
18781958
Class<?> enclosingClass = type.getEnclosingClass();
@@ -1896,6 +1976,21 @@ static String getSimpleName(Class<?> type, String className) {
18961976
return simpleName;
18971977
}
18981978

1979+
/**
1980+
* Checks whether the specified character is an ASCII digit ({@code '0'} through {@code '9'}).
1981+
*
1982+
* <h3>Example Usage</h3>
1983+
* <pre>{@code
1984+
* boolean digit = ClassUtils.isAsciiDigit('5'); // true
1985+
* boolean notDigit = ClassUtils.isAsciiDigit('a'); // false
1986+
* boolean zero = ClassUtils.isAsciiDigit('0'); // true
1987+
* boolean nine = ClassUtils.isAsciiDigit('9'); // true
1988+
* }</pre>
1989+
*
1990+
* @param c the character to check
1991+
* @return {@code true} if the character is an ASCII digit, {@code false} otherwise
1992+
* @since 1.0.0
1993+
*/
18991994
static boolean isAsciiDigit(char c) {
19001995
return '0' <= c && c <= '9';
19011996
}

0 commit comments

Comments
 (0)