| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A foundational Java library providing essential utilities and components for the CodeLibs project ecosystem. Built with Java 21 and optimized for modern Java development patterns including pattern matching, switch expressions, and sequenced collections.
<dependency>
<groupId>org.codelibs</groupId>
<artifactId>corelib</artifactId>
<version>0.7.0</version>
</dependency>implementation 'org.codelibs:corelib:0.7.0'import org.codelibs.core.beans.*;
import org.codelibs.core.beans.factory.BeanDescFactory;
import org.codelibs.core.beans.util.BeanUtil;
import org.codelibs.core.beans.util.CopyOptions;
// Bean metadata introspection
BeanDesc beanDesc = BeanDescFactory.getBeanDesc(MyBean.class);
PropertyDesc nameProperty = beanDesc.getPropertyDesc("name");
nameProperty.setValue(bean, "John Doe");
// Bean copying with flexible options
BeanUtil.copyBeanToBean(source, destination);
BeanUtil.copyBeanToBean(source, destination, options ->
options.exclude("password", "internalId"));
// Convert between beans and maps
Map<String, Object> map = BeanUtil.copyBeanToNewMap(bean);
MyBean newBean = BeanUtil.copyMapToNewBean(map, MyBean.class);import org.codelibs.core.convert.*;
// Safe type conversions with null handling
Integer value = IntegerConversionUtil.toInteger("123"); // Returns 123
Integer nullValue = IntegerConversionUtil.toInteger(null); // Returns null
Boolean flag = BooleanConversionUtil.toBoolean("true"); // Returns true
Date date = DateConversionUtil.toDate("2023-12-25", "yyyy-MM-dd");
// Primitive conversions with default values
int primitiveInt = IntegerConversionUtil.toPrimitiveInt(value, "0"); // Default to 0 if nullimport org.codelibs.core.collection.CollectionsUtil;
import java.util.SequencedCollection;
// Enhanced collection creation
List<String> list = CollectionsUtil.newArrayList();
Map<String, Object> map = CollectionsUtil.newLinkedHashMap();
Set<String> caseInsensitiveSet = new CaseInsensitiveSet<>();
// Java 21 Sequenced Collections support
SequencedCollection<String> sequenced = CollectionsUtil.newLinkedHashSet();
String first = CollectionsUtil.getFirst(sequenced);
String last = CollectionsUtil.getLast(sequenced);
SequencedCollection<String> reversed = CollectionsUtil.reversed(sequenced);
// Specialized collections
LruHashMap<String, Object> lruCache = new LruHashMap<>(100); // LRU cache with max 100 entries
CaseInsensitiveMap<String> configMap = new CaseInsensitiveMap<>();import org.codelibs.core.io.*;
// Resource loading and management
URL resource = ResourceUtil.getResource("config.properties");
Properties props = PropertiesUtil.load(resource);
// File operations with proper resource handling
try (InputStream input = ResourceUtil.getResourceAsStream("data.txt")) {
String content = InputStreamUtil.getUTF8String(input);
}
// Resource traversal for processing multiple files
ResourceTraversalUtil.forEach("META-INF", (resource, is) -> {
// Process each resource in the META-INF directory
System.out.println("Processing: " + resource);
});import org.codelibs.core.text.*;
// JSON utilities with proper escaping
String escaped = JsonUtil.escape("Hello \"World\" with special chars");
String unescaped = JsonUtil.unescape(escaped);
// Text tokenization
Tokenizer tokenizer = new Tokenizer("field1,field2,field3", ",");
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
// Process each token
}
// Decimal formatting
DecimalFormat format = DecimalFormatUtil.getDecimalFormat("###,###.00");import org.codelibs.core.exception.*;
// Runtime exception wrappers eliminate try-catch boilerplate
try {
// Code that might throw checked exceptions
return ClassUtil.newInstance(className); // Wraps checked exceptions automatically
} catch (ClassNotFoundRuntimeException e) {
// Handle the wrapped exception
logger.error("Class not found: " + className, e);
}CoreLib follows a utility-class pattern where most functionality is exposed through static methods:
# Clone the repository
git clone https://github.com/codelibs/corelib.git
cd corelib
# Compile the project
mvn clean compile
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=BeanUtilTest
# Run specific test method
mvn test -Dtest=BeanUtilTest#testCopyBeanToBean# Format code according to project standards
mvn formatter:format
# Apply license headers to source files
mvn license:format
# Build JAR with all verifications
mvn clean package
# Generate test coverage report
mvn verify
# Coverage report available at: target/site/jacoco/index.htmlcorelib/ ├── src/main/java/org/codelibs/core/ │ ├── beans/ # Bean manipulation and introspection │ ├── collection/ # Enhanced collection utilities │ ├── convert/ # Type conversion utilities │ ├── exception/ # Runtime exception wrappers │ ├── io/ # I/O and resource management │ ├── lang/ # Reflection and language utilities │ ├── log/ # Logging abstraction │ ├── text/ # Text processing utilities │ ├── xml/ # XML processing utilities │ └── ... # Additional utility packages └── src/test/java/ # Comprehensive test suite
CoreLib 0.7.0 includes significant performance improvements through Java 21 optimizations:
CoreLib supports multiple logging frameworks. Configure your preferred logger:
// Use with SLF4J (add slf4j-api dependency)
Logger logger = Logger.getLogger(MyClass.class);
// Use with Commons Logging (add commons-logging dependency)
Logger logger = Logger.getLogger(MyClass.class);
// Use with Java Util Logging (built-in)
Logger logger = Logger.getLogger(MyClass.class.getName());// Configure bean copying behavior
CopyOptions options = new CopyOptions()
.exclude("password", "internalId") // Exclude specific fields
.includeNull(false) // Skip null values
.converter("dateField", new DateConverter("yyyy-MM-dd"));
BeanUtil.copyBeanToBean(source, dest, options);We welcome contributions! Please see our contributing guidelines for details.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
| Back | FazBrowse Home | New Git URL |