Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9945867
Update pom.xml
mercyblitz Aug 10, 2025
8634cc5
Add iterate and forEach utility methods to IterableUtils
mercyblitz Aug 23, 2025
68773f3
Add tests for IterableUtils iterate and forEach methods
mercyblitz Aug 23, 2025
79266a8
Add addAll method for Iterable to CollectionUtils
mercyblitz Aug 23, 2025
e9c7f06
Refactor and expand addAll tests in CollectionUtilsTest
mercyblitz Aug 23, 2025
0b1343b
Add ArrayStack implementation
mercyblitz Aug 24, 2025
eb2de34
Add unit tests for ArrayStack class
mercyblitz Aug 24, 2025
6e42b98
Merge pull request #5 from mercyblitz/main
mercyblitz Aug 24, 2025
2a2c7c3
Make buildSignature public and improve documentation
mercyblitz Aug 24, 2025
1174780
Add tests for buildSignature method
mercyblitz Aug 24, 2025
355c613
Add system properties copy and retrieval methods
mercyblitz Aug 24, 2025
211ca93
Add tests for system properties copy/reset in SystemUtilsTest
mercyblitz Aug 24, 2025
427ed53
Support loading primitive classes by name
mercyblitz Aug 24, 2025
6a95e65
Add tests for doLoadClass method in ClassLoaderUtilsTest
mercyblitz Aug 24, 2025
8d525e0
Add support for banning methods via system property
mercyblitz Aug 24, 2025
bed735b
Update MethodUtilsTest.java
mercyblitz Aug 24, 2025
d9a7526
Refactor banned methods initialization and add utility
mercyblitz Aug 24, 2025
3509970
Add tests for addBannedMethod in MethodUtilsTest
mercyblitz Aug 24, 2025
1af3240
Update ConfigurationPropertyAnnotationProcessorTest.java
mercyblitz Aug 24, 2025
44f4be2
Update configuration properties and add banned-methods
mercyblitz Aug 24, 2025
5d04eeb
Update ConfigurationPropertiesJSONReaderTest.java
mercyblitz Aug 24, 2025
13b5038
Update MetadataResourceConfigurationPropertyLoaderTest.java
mercyblitz Aug 24, 2025
25d963e
Add JSON string escape utility to JSONUtils
mercyblitz Aug 25, 2025
e208464
Add unit tests for JSONUtils.escape method
mercyblitz Aug 25, 2025
28e4830
Enhance description resolution for config properties
mercyblitz Aug 25, 2025
d30b4c9
Update configuration-properties.json
mercyblitz Aug 25, 2025
4cfa79c
Update JSONUtils.java
mercyblitz Aug 25, 2025
e1218cd
Update ConfigurationPropertyJSONElementVisitor.java
mercyblitz Aug 25, 2025
f784b8f
Merge pull request #185 from mercyblitz/dev
mercyblitz Aug 25, 2025
1c0340c
Update microsphere-java-core/src/main/java/io/microsphere/util/System…
mercyblitz Aug 25, 2025
8b93fd3
Update SystemUtils.java
mercyblitz Aug 25, 2025
32a40a6
Update JSONUtils.java
mercyblitz Aug 25, 2025
0dc042a
Add braces to if statements in JSONUtils
mercyblitz Aug 25, 2025
493be2d
Rename addBannedMethod to banMethod in MethodUtils
mercyblitz Aug 25, 2025
0bf80c0
Fix type in copySystemProperties for Properties map
mercyblitz Aug 25, 2025
8bdbdaf
Rename addBannedMethod to banMethod in tests
mercyblitz Aug 25, 2025
c3b365d
Update MethodUtils.java
mercyblitz Aug 25, 2025
2cb817e
Update SystemUtils.java
mercyblitz Aug 25, 2025
751774c
Update SystemUtils.java
mercyblitz Aug 25, 2025
3365afe
Merge branch 'dev' into dev
mercyblitz Aug 25, 2025
37cfab4
Add more unit tests for StopWatch.Task equality and hashCode
mercyblitz Aug 25, 2025
1b79456
Update Converter.java
mercyblitz Aug 25, 2025
f223d36
Merge pull request #187 from mercyblitz/dev
mercyblitz Aug 25, 2025
339f77d
Merge pull request #186 from microsphere-projects/dev
mercyblitz Aug 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static io.microsphere.annotation.processor.util.TypeUtils.getTypeName;
import static io.microsphere.constants.SymbolConstants.COMMA_CHAR;
import static io.microsphere.util.ServiceLoaderUtils.loadFirstService;
import static io.microsphere.util.StringUtils.isBlank;

/**
* {@link ConfigurationProperty @ConfigurationProperty}'s {@link AnnotatedElementJSONElementVisitor} based on
Expand Down Expand Up @@ -84,7 +85,7 @@ public Boolean visitVariableAsField(VariableElement field, StringBuilder jsonBui
boolean required = (boolean) annotationValue.getValue();
configurationProperty.setRequired(required);
} else if ("description".equals(attributeName)) {
String description = resolveStringValue(attributeMethod, annotationValue);
String description = resolveDescription(field, attributeMethod, annotationValue);
configurationProperty.setDescription(description);
} else if ("source".equals(attributeName)) {
setSources(configurationProperty, annotationValue);
Expand Down Expand Up @@ -116,6 +117,14 @@ private String resolveType(VariableElement field, ExecutableElement attributeMet
return getTypeName(type);
}

private String resolveDescription(VariableElement field, ExecutableElement attributeMethod, AnnotationValue annotationValue) {
String description = resolveStringValue(attributeMethod, annotationValue);
if (isBlank(description)) {
description = elements.getDocComment(field);
}
return description;
}

private String resolveStringValue(ExecutableElement attributeMethod, AnnotationValue annotationValue) {
Object value = matchesDefaultAttributeValue(attributeMethod, annotationValue) ? null : annotationValue.getValue();
return (String) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.microsphere.classloading.ManifestArtifactResourceResolver;
import io.microsphere.io.IOUtils;
import io.microsphere.io.StandardFileWatchService;
import io.microsphere.reflect.MethodUtils;
import io.microsphere.reflect.TypeUtils;
import io.microsphere.util.ServiceLoaderUtils;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -51,6 +52,7 @@ protected void addCompiledClasses(Set<Class<?>> compiledClasses) {
compiledClasses.add(StandardFileWatchService.class);
compiledClasses.add(TypeUtils.class);
compiledClasses.add(ServiceLoaderUtils.class);
compiledClasses.add(MethodUtils.class);
compiledClasses.add(ConfigurationProperty.class);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/

package io.microsphere.collection;

import java.util.ArrayList;
import java.util.EmptyStackException;
import java.util.Stack;

/**
* The {@code Stack} class represents a last-in-first-out
* (LIFO) stack of objects. It extends class {@code Vector} with five
* operations that allow a vector to be treated as a stack. The usual
* {@code push} and {@code pop} operations are provided, as well as a
* method to {@code peek} at the top item on the stack, a method to test
* for whether the stack is {@code empty}, and a method to {@code search}
* the stack for an item and discover how far it is from the top.
* <p>
* The non thread-safe version of {@link Stack}.
*
* @param <E> Type of component elements
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see ArrayList
* @see Stack
* @since 1.0.0
*/
public class ArrayStack<E> extends ArrayList<E> {

private static final long serialVersionUID = -1417040223081465932L;

/**
* Creates an empty Stack.
*/
public ArrayStack() {
this(0);
}

/**
* Constructs a new, empty stack with the specified initial
* capacity.
*
* @param initialCapacity the initial capacity of the stack.
* @throws IllegalArgumentException if the specified initial capacity
* is negative
*/
public ArrayStack(int initialCapacity) {
super(initialCapacity);
}

/**
* Pushes an item onto the top of this stack. This has exactly
* the same effect as: {@link #add(Object)}
*
* @param item the item to be pushed onto this stack.
* @return the {@code item} argument.
* @see ArrayList#add(Object)
*/
public E push(E item) {
super.add(item);
return item;
}

/**
* Removes the object at the top of this stack and returns that
* object as the value of this function.
*
* @return The object at the top of this stack (the last item
* of the {@code ArrayList} object).
* @throws EmptyStackException if this stack is empty.
*/
public E pop() {
E obj;
int len = super.size();

obj = this.peek();
super.remove(len - 1);
return obj;
}

/**
* Looks at the object at the top of this stack without removing it
* from the stack.
*
* @return the object at the top of this stack (the last item
* of the {@code ArrayList} object).
* @throws EmptyStackException if this stack is empty.
*/
public E peek() throws EmptyStackException {
int len = super.size();
if (len == 0)
throw new EmptyStackException();
Comment on lines +104 to +105
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing braces around single-statement if block. Add braces for consistency with project style: if (len == 0) { throw new EmptyStackException(); }.

Suggested change
if (len == 0)
throw new EmptyStackException();
if (len == 0) {
throw new EmptyStackException();
}

Copilot uses AI. Check for mistakes.
return super.get(len - 1);
}

/**
* Tests if this stack is empty.
*
* @return {@code true} if and only if this stack contains
* no items; {@code false} otherwise.
*/
public boolean empty() {
return super.isEmpty();
}

/**
* Returns the 1-based position where an object is on this stack.
* If the object {@code o} occurs as an item in this stack, this
* method returns the distance from the top of the stack of the
* occurrence nearest the top of the stack; the topmost item on the
* stack is considered to be at distance {@code 1}. The {@code equals}
* method is used to compare {@code o} to the
* items in this stack.
*
* @param o the desired object.
* @return the 1-based position from the top of the stack where
* the object is located; the return value {@code -1}
* indicates that the object is not on the stack.
*/
public int search(Object o) {
int i = super.lastIndexOf(o);

if (i >= 0) {
return super.size() - i;
}
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public static boolean equals(@Nullable Collection<?> one, @Nullable Collection<?
* </p>
*
* @param collection the collection to which elements are to be added, may be null or empty
* @param values the array of elements to add, may be null
* @param newValues the array of elements to add, may be null
* @param <T> the type of elements in the collection and array
* @return the number of elements successfully added to the collection
*
Expand All @@ -449,21 +449,61 @@ public static boolean equals(@Nullable Collection<?> one, @Nullable Collection<?
* int count4 = CollectionUtils.addAll(emptyCollection, "x"); // returns 0
* }</pre>
*/
public static <T> int addAll(@Nullable Collection<T> collection, T... values) {

public static <T> int addAll(@Nullable Collection<T> collection, T... newValues) {
if (collection == null) {
return 0;
}

int size = length(values);

int size = length(newValues);
if (size < 1) {
return 0;
}

int effectedCount = 0;
for (int i = 0; i < size; i++) {
if (collection.add(values[i])) {
if (collection.add(newValues[i])) {
effectedCount++;
}
}

return effectedCount;
}

/**
* Adds all the elements in the specified {@link Iterable} to the given collection.
*
* <p>
* If the provided collection is null or empty, no elements are added, and 0 is returned.
* If the iterable is null or has no elements, 0 is also returned.
* </p>
*
* @param collection the collection to which elements are to be added, may be null or empty
* @param newValues the {@link Iterable} of elements to add, may be null
* @param <T> the type of elements in the collection and iterable
* @return the number of elements successfully added to the collection
*
* <h3>Example Usage</h3>
* <pre>{@code
* Collection<String> collection = new ArrayList<>();
* Iterable<String> values = Arrays.asList("a", "b", "c");
* int count1 = CollectionUtils.addAll(collection, values); // returns 3
*
* int count2 = CollectionUtils.addAll(null, values); // returns 0
*
* int count3 = CollectionUtils.addAll(collection, (Iterable<String>) null); // returns 0
*
* Collection<String> emptyCollection = Collections.emptyList();
* int count4 = CollectionUtils.addAll(emptyCollection, values); // returns 0
* }</pre>
*/
public static <T> int addAll(@Nullable Collection<T> collection, @Nullable Iterable<T> newValues) {
if (collection == null || newValues == null) {
return 0;
}

int effectedCount = 0;
for (T newValue : newValues) {
if (collection.add(newValue)) {
effectedCount++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ static <S, T> Converter<S, T> getConverter(Class<S> sourceType, Class<T> targetT
* @return the converted object of type {@code T}, or {@code null} if no suitable converter is found
*/
static <T> T convertIfPossible(Object source, Class<T> targetType) {
Converter converter = getConverter(source.getClass(), targetType);
Converter<Object, T> converter = (Converter<Object, T>) getConverter(source.getClass(), targetType);
if (converter != null) {
return (T) converter.convert(source);
return converter.convert(source);
}
return null;
}
Expand Down
Loading