CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-networknt--utility

A comprehensive utility library for Light-4J microservices framework providing string manipulation, networking, I/O, security, and configuration utilities.

Pending
Overview
Eval results
Files

data-structure-utilities.mddocs/

Data Structure Utilities

Thread-safe collections and null-safe operations for working with maps, sets, and collections. Includes concurrent data structures and utility methods for safe data manipulation in multi-threaded environments.

Capabilities

Collection Utilities

Abstract utility class providing null-safe collection operations and advanced search functionality.

/**
 * Collection manipulation utilities
 */
public abstract class CollectionUtils {
    // Null-safe empty checks
    public static boolean isEmpty(Collection<?> collection);
    public static boolean isEmpty(Map<?, ?> map);
    
    // Search operations
    public static boolean contains(Iterator<?> iterator, Object element);
    public static boolean contains(Enumeration<?> enumeration, Object element);
    public static <E> E findFirstMatch(Collection<?> source, Collection<E> candidates);
    public static <T> T findValueOfType(Collection<?> collection, Class<T> type);
    public static Object findValueOfType(Collection<?> collection, Class<?>[] types);
    
    // Specialized operations
    public static Object matchEndpointKey(String path, Map<String, Object> map);
}

Concurrent Hash Set

Thread-safe Set implementation using ConcurrentHashMap for high-performance concurrent access.

/**
 * Thread-safe Set implementation using ConcurrentHashMap
 */
public class ConcurrentHashSet<E> extends AbstractSet<E> {
    // Constructors
    public ConcurrentHashSet();
    public ConcurrentHashSet(int initialCapacity);
    
    // All standard Set methods inherited from AbstractSet
    // Thread-safe operations provided by underlying ConcurrentHashMap
}

Map Utilities

Map operations with case-insensitive key lookup and safe value extraction.

/**
 * Map operations with case-insensitive key lookup
 */
public class MapUtil {
    // Case-insensitive operations
    public static <V> Optional<V> getValueIgnoreCase(Map<String, V> map, String key);
    public static <V> Optional<V> delValueIgnoreCase(Map<String, V> map, String key);
}

Object Utilities

Abstract utility class providing null-safe object operations and array handling.

/**
 * Object manipulation utilities with null-safety
 */
public abstract class ObjectUtils {
    // Type checking
    public static boolean isArray(Object obj);
    
    // Empty checks
    public static boolean isEmpty(Object[] array);
    public static boolean isEmpty(Object obj);
    
    // Null-safe operations
    public static boolean nullSafeEquals(Object o1, Object o2);
    public static int nullSafeHashCode(Object obj);
    public static int nullSafeHashCode(Object[] array);
    public static int nullSafeHashCode(boolean[] array);
    public static int nullSafeHashCode(byte[] array);
    public static int nullSafeHashCode(char[] array);
    public static int nullSafeHashCode(double[] array);
    public static int nullSafeHashCode(float[] array);
    public static int nullSafeHashCode(int[] array);
    public static int nullSafeHashCode(long[] array);
    public static int nullSafeHashCode(short[] array);
    
    // Array conversion
    public static Object[] toObjectArray(Object source);
}

Tuple

Simple pair container for holding two related values with type safety.

/**
 * Simple pair container for two values
 */
public class Tuple<T, T2> {
    public final T first;
    public final T2 second;
    
    // Constructor
    public Tuple(T first, T2 second);
}

Usage Examples:

import com.networknt.utility.*;
import java.util.*;

// Collection utilities
List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
boolean isEmpty = CollectionUtils.isEmpty(names); // false

List<String> candidates = Arrays.asList("Bob", "David");
String match = CollectionUtils.findFirstMatch(names, candidates); // "Bob"

// Thread-safe set
ConcurrentHashSet<String> concurrentSet = new ConcurrentHashSet<>();
concurrentSet.add("item1");
concurrentSet.add("item2");
// Safe for concurrent access

// Case-insensitive map operations
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Bearer token");

Optional<String> contentType = MapUtil.getValueIgnoreCase(headers, "content-type"); // "application/json"
Optional<String> auth = MapUtil.getValueIgnoreCase(headers, "AUTHORIZATION"); // "Bearer token"

// Object utilities
Object[] array = {"a", "b", "c"};
boolean isArrayType = ObjectUtils.isArray(array); // true
boolean arrayEmpty = ObjectUtils.isEmpty(array); // false

// Null-safe operations
boolean equal = ObjectUtils.nullSafeEquals(null, null); // true
int hashCode = ObjectUtils.nullSafeHashCode(null); // 0

// Tuple usage
Tuple<String, Integer> userInfo = new Tuple<>("Alice", 25);
String name = userInfo.first; // "Alice"
Integer age = userInfo.second; // 25

// Endpoint matching example
Map<String, Object> endpoints = Map.of(
    "/api/users/{id}", "getUserHandler",
    "/api/orders/*", "orderHandler"
);
Object handler = CollectionUtils.matchEndpointKey("/api/users/123", endpoints);

Install with Tessl CLI

npx tessl i tessl/maven-com-networknt--utility

docs

configuration-management.md

data-structure-utilities.md

framework-integration.md

index.md

io-file-operations.md

network-operations.md

path-template-matching.md

security-cryptography.md

string-processing.md

time-date-operations.md

tile.json