Skip to content

Commit 42f9762

Browse files
CopilotCopilot
andcommitted
Add JavaDoc comments to undocumented non-private methods
Add JavaDoc with Example Usage sections to 9 non-private methods/constructors across 3 files: - ShutdownHookUtils: clearShutdownHookCallbacks(), shutdownHookThreadsMap(Class) - PriorityComparator: compare(Object,Object), compare(Class,Class), compare(Class,Class,Class), getValue(Object) - PropertyResourceBundleControl: no-arg constructor, getFormats(String), newBundle(String,Locale,String,ClassLoader,boolean) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2ca3123 commit 42f9762

3 files changed

Lines changed: 149 additions & 0 deletions

File tree

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,69 @@ public class PriorityComparator implements Comparator<Object> {
5959
*/
6060
public static final PriorityComparator INSTANCE = new PriorityComparator();
6161

62+
/**
63+
* Compares two objects based on the value of their {@link javax.annotation.Priority} annotation.
64+
*
65+
* <h3>Example Usage</h3>
66+
* <pre>{@code
67+
* PriorityComparator comparator = PriorityComparator.INSTANCE;
68+
* int result = comparator.compare(serviceA, serviceB);
69+
* if (result < 0) {
70+
* System.out.println("serviceA has higher priority");
71+
* }
72+
* }</pre>
73+
*
74+
* @param o1 the first object to compare
75+
* @param o2 the second object to compare
76+
* @return a negative integer, zero, or a positive integer as the first object's priority
77+
* is less than, equal to, or greater than the second object's priority
78+
* @since 1.0.0
79+
*/
6280
@Override
6381
public int compare(Object o1, Object o2) {
6482
return compare(getType(o1), getType(o2));
6583
}
6684

85+
/**
86+
* Compares two classes based on the value of the default {@link javax.annotation.Priority} annotation.
87+
*
88+
* <h3>Example Usage</h3>
89+
* <pre>{@code
90+
* int result = PriorityComparator.compare(HighPriorityService.class, LowPriorityService.class);
91+
* System.out.println("Comparison result: " + result);
92+
* }</pre>
93+
*
94+
* @param type1 the first class to compare
95+
* @param type2 the second class to compare
96+
* @return a negative integer, zero, or a positive integer as the first class's priority
97+
* is less than, equal to, or greater than the second class's priority
98+
* @since 1.0.0
99+
*/
67100
static int compare(Class<?> type1, Class<?> type2) {
68101
return compare(type1, type2, PRIORITY_CLASS);
69102
}
70103

104+
/**
105+
* Compares two classes based on the value of the specified priority annotation.
106+
*
107+
* <h3>Example Usage</h3>
108+
* <pre>{@code
109+
* int result = PriorityComparator.compare(
110+
* HighPriorityService.class,
111+
* LowPriorityService.class,
112+
* javax.annotation.Priority.class
113+
* );
114+
* System.out.println("Comparison result: " + result);
115+
* }</pre>
116+
*
117+
* @param type1 the first class to compare
118+
* @param type2 the second class to compare
119+
* @param priorityClass the priority annotation class used to extract priority values
120+
* @return a negative integer, zero, or a positive integer as the first class's priority
121+
* is less than, equal to, or greater than the second class's priority;
122+
* returns {@code 0} if the classes are equal or the priority annotation class is {@code null}
123+
* @since 1.0.0
124+
*/
71125
static int compare(Class<?> type1, Class<?> type2, Class<? extends Annotation> priorityClass) {
72126
if (Objects.equals(type1, type2) || priorityClass == null) {
73127
return 0;
@@ -82,6 +136,20 @@ static int compare(Class<?> type1, Class<?> type2, Class<? extends Annotation> p
82136
return Integer.compare(priorityValue1, priorityValue2);
83137
}
84138

139+
/**
140+
* Extracts the integer priority value from a priority annotation instance.
141+
*
142+
* <h3>Example Usage</h3>
143+
* <pre>{@code
144+
* Annotation priority = HighPriorityService.class.getAnnotation(javax.annotation.Priority.class);
145+
* int value = PriorityComparator.getValue(priority);
146+
* System.out.println("Priority value: " + value);
147+
* }</pre>
148+
*
149+
* @param priority the priority annotation instance, or {@code null} if not annotated
150+
* @return the priority value, or {@code -1} if the annotation is {@code null} or the value is negative
151+
* @since 1.0.0
152+
*/
85153
static int getValue(Object priority) {
86154
int value = priority == null ? UNDEFINED_VALUE : invokeMethod(priority, "value");
87155
return value < 0 ? UNDEFINED_VALUE : value;

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ public class PropertyResourceBundleControl extends ResourceBundle.Control {
7575

7676
private final String encoding;
7777

78+
/**
79+
* Constructs a {@link PropertyResourceBundleControl} with the default encoding.
80+
*
81+
* <h3>Example Usage</h3>
82+
* <pre>{@code
83+
* PropertyResourceBundleControl control = new PropertyResourceBundleControl();
84+
* String encoding = control.getEncoding();
85+
* System.out.println("Default encoding: " + encoding);
86+
* }</pre>
87+
*
88+
* @throws UnsupportedCharsetException if the default encoding is not supported
89+
* @since 1.0.0
90+
*/
7891
protected PropertyResourceBundleControl() throws UnsupportedCharsetException {
7992
this(DEFAULT_ENCODING);
8093
}
@@ -89,13 +102,51 @@ protected PropertyResourceBundleControl(final String encoding) throws Unsupporte
89102
this.encoding = encoding;
90103
}
91104

105+
/**
106+
* Returns the list of supported formats for the given base name, restricted to properties files only.
107+
*
108+
* <h3>Example Usage</h3>
109+
* <pre>{@code
110+
* PropertyResourceBundleControl control = PropertyResourceBundleControl.DEFAULT_CONTROL;
111+
* List<String> formats = control.getFormats("my.resources.Messages");
112+
* System.out.println("Supported formats: " + formats);
113+
* }</pre>
114+
*
115+
* @param baseName the base name of the resource bundle
116+
* @return a list containing the properties format
117+
* @throws NullPointerException if {@code baseName} is {@code null}
118+
* @since 1.0.0
119+
*/
92120
public final List<String> getFormats(String baseName) {
93121
if (baseName == null) {
94122
throw new NullPointerException();
95123
}
96124
return FORMAT_PROPERTIES;
97125
}
98126

127+
/**
128+
* Creates a new {@link ResourceBundle} instance for the given parameters, reading the properties
129+
* file with the configured character encoding.
130+
*
131+
* <h3>Example Usage</h3>
132+
* <pre>{@code
133+
* PropertyResourceBundleControl control = PropertyResourceBundleControl.DEFAULT_CONTROL;
134+
* ResourceBundle bundle = control.newBundle(
135+
* "my.resources.Messages", Locale.US, "java.properties",
136+
* Thread.currentThread().getContextClassLoader(), false
137+
* );
138+
* System.out.println(bundle.getString("greeting"));
139+
* }</pre>
140+
*
141+
* @param baseName the base name of the resource bundle
142+
* @param locale the locale for which the resource bundle should be loaded
143+
* @param format the resource bundle format to be loaded
144+
* @param classLoader the class loader to use for loading the resource
145+
* @param reload whether to bypass the cache and reload the resource
146+
* @return a new {@link ResourceBundle} instance, or {@code null} if the resource is not found
147+
* @throws IOException if an I/O error occurs while reading the resource
148+
* @since 1.0.0
149+
*/
99150
public ResourceBundle newBundle(String baseName, Locale locale, String format, final ClassLoader classLoader, final boolean reload) throws IOException {
100151
String bundleName = super.toBundleName(baseName, locale);
101152
final String resourceName = super.toResourceName(bundleName, SUFFIX);

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,19 @@ public static Queue<Runnable> getShutdownHookCallbacks() {
372372
return unmodifiableQueue(shutdownHookCallbacks);
373373
}
374374

375+
/**
376+
* Clears all registered shutdown hook callbacks from the internal queue.
377+
*
378+
* <h3>Example Usage</h3>
379+
* <pre>{@code
380+
* // Clear all registered shutdown hook callbacks
381+
* ShutdownHookUtils.clearShutdownHookCallbacks();
382+
* Queue<Runnable> callbacks = ShutdownHookUtils.getShutdownHookCallbacks();
383+
* assert callbacks.isEmpty();
384+
* }</pre>
385+
*
386+
* @since 1.0.0
387+
*/
375388
static void clearShutdownHookCallbacks() {
376389
shutdownHookCallbacks.clear();
377390
}
@@ -382,6 +395,23 @@ private static Map<Thread, Thread> shutdownHookThreadsMap() {
382395
return shutdownHookThreadsMap(applicationShutdownHooksClass);
383396
}
384397

398+
/**
399+
* Retrieves the internal map of shutdown hook threads from the specified
400+
* {@code java.lang.ApplicationShutdownHooks} class via reflection.
401+
*
402+
* <h3>Example Usage</h3>
403+
* <pre>{@code
404+
* Class<?> clazz = Class.forName("java.lang.ApplicationShutdownHooks");
405+
* Map<Thread, Thread> hooksMap = ShutdownHookUtils.shutdownHookThreadsMap(clazz);
406+
* hooksMap.keySet().forEach(thread ->
407+
* System.out.println("Hook: " + thread.getName())
408+
* );
409+
* }</pre>
410+
*
411+
* @param applicationShutdownHooksClass the {@code java.lang.ApplicationShutdownHooks} class, or {@code null}
412+
* @return the map of shutdown hook threads, or an empty map if the class is {@code null}
413+
* @since 1.0.0
414+
*/
385415
static Map<Thread, Thread> shutdownHookThreadsMap(Class<?> applicationShutdownHooksClass) {
386416
return applicationShutdownHooksClass == null ? emptyMap() : getStaticFieldValue(applicationShutdownHooksClass, HOOKS_FIELD_NAME);
387417
}

0 commit comments

Comments
 (0)