Mastering Mica-Core: Essential $ Utility Methods for Java Developers
This guide introduces the Mica-Core utility class, showcasing a comprehensive collection of shortcut methods for assertions, string manipulation, collection handling, encoding, cryptography, JSON processing, reflection, bean operations, and date-time utilities, all designed to boost Java backend development efficiency.
Introduction
The mica-core module encapsulates a large set of commonly used utility classes, most of which are extensions based on Spring core, to avoid reinventing the wheel and reduce bugs.
Background
Today we introduce the $ utility shortcut collection. In jquery you can use $ for various operations without remembering numerous utility classes, greatly improving development efficiency. Inspired by colleagues asking for various utility classes, we extracted these shortcuts into $ to reduce learning and development costs.
Tool Method List
Class name:
net.dreamlu.mica.core.utils.$Assert not null
$ .requireNotNull(Object obj);Assert not null with message
$ .requireNotNull(Object obj, String message);Assert not null with message supplier
$ .requireNotNull(Object obj, Supplier messageSupplier);Check if object is null
$ .isNull(Object obj);Check if object is not null
$ .notNull(Object obj);Convert first character to lower case
$ .firstCharToLower(String str);Convert first character to upper case
$ .firstCharToUpper(String str);Check if CharSequence is blank
$ .isBlank(CharSequence cs);Check if CharSequence is not blank
$ .isNotBlank(CharSequence cs);Check if any CharSequence is blank
$ .isAnyBlank(CharSequence... css);Check if all CharSequences are non‑blank
$ .isNoneBlank(CharSequence... css);Check if object is an array
$ .isArray(Object obj);Check if object (collection, map, list, set, string, array) is empty
$ .isEmpty(Object obj);Check if object (collection, map, list, set, string, array) is not empty
$ .isNotEmpty(Object obj);Check if array is empty
$ .isEmpty(Object array);Check if array is not empty
$ .isNotEmpty(Object[] array);Format string with map parameters
$ .format(String message, Map<String, Object> params);Log‑style format
$ .format(String message, Object... arguments);Safe equals
$ .equalsSafe(Object o1, Object o2);Check if array contains element
$ .contains(T[] array, T element);Check if iterator contains element
$ .contains(Iterator<?> iterator, Object element);Check if enumeration contains element
$ .contains(Enumeration<?> enumeration, Object element);Immutable Set
$ .ofImmutableSet(E... es);Immutable List
$ .ofImmutableList(E... es);Check if string is numeric
$ .isNumeric(CharSequence cs);String to int (default 0)
$ .toInt(String str);String to int with default value
$ .toInt(String str, int defaultValue);String to long (default 0)
$ .toLong(String str);String to long with default value
$ .toLong(String str, long defaultValue);Convert long to base‑62 string
$ .to62String(long num);Join collection with default delimiter ','
$ .join(Collection<?> coll);Join collection with custom delimiter
$ .join(Collection<?> coll, String delim);Join array with default delimiter ','
$ .join(Object[] arr);Join array with custom delimiter
$ .join(Object[] arr, String delim);Split string
$ .split(String str, String delimiter);Split string and trim common whitespace
$ .splitTrim(String str, String delimiter);Simple pattern match
$ .simpleMatch(String pattern, String str); $ .simpleMatch(String[] patterns, String str);Generate UUID
$ .getUUID();Escape HTML for safe filtering
$ .escapeHtml(String html);Random number generation
$ .random(int count); $ .random(int count, RandomType randomType);MD5 hex
$ .md5Hex(String data); $ .md5Hex(byte[] bytes);SHA‑1 hex
$ .sha1Hex(String data); $ .sha1Hex(byte[] bytes);SHA‑224 hex
$ .sha224Hex(String data); $ .sha224Hex(byte[] bytes);SHA‑256 hex
$ .sha256Hex(String data); $ .sha256Hex(byte[] bytes);SHA‑384 hex
$ .sha384Hex(String data); $ .sha384Hex(byte[] bytes);SHA‑512 hex
$ .sha512Hex(String data); $ .sha512Hex(byte[] bytes);HMAC‑MD5 hex
$ .hmacMd5Hex(String data, String key); $ .hmacMd5Hex(byte[] bytes, String key);HMAC‑SHA1 hex
$ .hmacSha1Hex(String data, String key); $ .hmacSha1Hex(byte[] bytes, String key);HMAC‑SHA224 hex
$ .hmacSha224Hex(String data, String key); $ .hmacSha224Hex(byte[] bytes, String key);HMAC‑SHA256 hex
$ .hmacSha256Hex(String data, String key); $ .hmacSha256Hex(byte[] bytes, String key);HMAC‑SHA384 hex
$ .hmacSha384Hex(String data, String key); $ .hmacSha384Hex(byte[] bytes, String key);HMAC‑SHA512 hex
$ .hmacSha512Hex(String data, String key); $ .hmacSha512Hex(byte[] bytes, String key);Encode byte array to hex
$ .encodeHex(byte[] bytes);Decode hex string to byte array
$ .decodeHex(String hexString);Base64 encode
$ .encodeBase64(String value); $ .encodeBase64(String value, Charset charset);Base64 URL‑safe encode
$ .encodeBase64UrlSafe(String value); $ .encodeBase64UrlSafe(String value, Charset charset);Base64 decode
$ .decodeBase64(String value); $ .decodeBase64(String value, Charset charset);Base64 URL‑safe decode
$ .decodeBase64UrlSafe(String value); $ .decodeBase64UrlSafe(String value, Charset charset);Date‑time formatting
$ .formatDateTime(Date date); $ .formatDateTime(TemporalAccessor temporal);Date formatting
$ .formatDate(Date date); $ .formatDate(TemporalAccessor temporal);Time formatting
$ .formatTime(Date date); $ .formatTime(TemporalAccessor temporal);Object formatting (numbers, dates, Java 8 time)
$ .format(Object object, String pattern);Parse string to Date
$ .parseDate(String dateStr, String pattern); $ .parseDate(String dateStr, DateTimeFormatter formatter); $ .parseDate(String dateStr);Parse string to Date‑time
$ .parseDateTime(String dateStr, DateTimeFormatter formatter); $ .parseDateTime(String dateStr);Parse string to Time
$ .parseTime(String dateStr, DateTimeFormatter formatter); $ .parseTime(String dateStr);Parse with ConcurrentDateFormat
$ .parse(String dateStr, ConcurrentDateFormat format);Time interval calculation
$ .between(Temporal startInclusive, Temporal endExclusive); $ .between(Date startDate, Date endDate);Object type conversion
$ .convert(Object source, Class<T> targetType); $ .convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType); $ .convert(Object source, TypeDescriptor targetType);Get method parameter information
$ .getMethodParameter(Constructor<?> constructor, int parameterIndex); $ .getMethodParameter(Method method, int parameterIndex);Get annotation
$ .getAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType); $ .getAnnotation(Method method, Class<A> annotationType); $ .getAnnotation(HandlerMethod handlerMethod, Class<A> annotationType);Instantiate object
$ .newInstance(Class<?> clazz); $ .newInstance(String clazzStr);Get bean property (supports nested paths)
$ .getProperty(Object bean, String propertyName);Set bean property (supports nested paths)
$ .setProperty(Object bean, String propertyName, Object value);Shallow clone
$ .clone(Object source);Copy object (Map or Bean)
$ .copy(Object source, Class<T> clazz); $ .copy(Object source, Object targetBean);Copy non‑null properties
$ .copyNonNull(Object source, Object targetBean);Copy with type conversion
$ .copyWithConvert(Object source, Class<T> clazz);Copy list of objects
$ .copy(Collection sourceList, Class<T> targetClazz);Copy list with conversion
$ .copyWithConvert(Collection sourceList, Class<T> targetClazz);Copy properties (Spring‑style)
$ .copyProperties(Object source, Class<T> clazz); $ .copyProperties(Collection sourceList, Class<T> targetClazz);Convert bean to map
$ .toMap(Object bean);Convert map to bean
$ .toBean(Map<String, Object> beanMap, Class<T> valueType);Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
