public class MetaUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
META_CLASS_FIELD_NAME |
static String |
META_CLASS_NAME |
Modifier and Type | Method and Description |
---|---|
static Set<String> |
commaSeparatedStringToSet(String commaSeparatedString) |
static String |
createCacheKey(Class<?> c,
Collection<?> args) |
static <T> T |
findClosest(Class<?> c,
Map<Class<?>,T> workerClasses,
T defaultClass)
Fetch the closest class for the passed in Class.
|
static Optional<Class<?>> |
getClassIfEnum(Class<?> c) |
static String |
getLogMessage(String methodName,
Object[] args)
Format a nice looking method signature for logging output
|
static String |
getLogMessage(String methodName,
Object[] args,
int argCharLen) |
static <K,V> V |
getValueWithDefaultForMissing(Map map,
K key,
V defaultValue) |
static <K,V> V |
getValueWithDefaultForNull(Map map,
K key,
V defaultValue) |
static int |
indexOfSmallestValue(int[] array)
Returns the index of the smallest value in an array.
|
static boolean |
isLogicalPrimitive(Class<?> c)
Legacy API that many applications consumed.
|
static boolean |
isPrimitive(Class<?> c)
Legacy API that many applications consumed.
|
static int |
length(String s)
Use this method when you don't want a length check to
throw a NullPointerException when
|
static <T> List<T> |
listOf(T... items)
For JDK1.8 support.
|
static Map<Class<?>,Set<String>> |
loadClassToSetOfStrings(String fileName)
Populates a map with a mapping of Class -> Set of Strings
|
static Map<String,String> |
loadMapDefinition(String resName)
Load in a Map-style properties file.
|
static Set<Class<?>> |
loadNonRefs()
Load the list of classes that are intended to be treated as non-referenceable, immutable classes.
|
static Map<Class<?>,Map<String,String>> |
loadNonStandardMethodNames(String fileName)
Load custom writer classes based on contents of resources/customWriters.txt.
|
static byte[] |
loadResourceAsBytes(String resourceName)
Loads resource content as a byte[].
|
static String |
loadResourceAsString(String resourceName)
Loads resource content as a String.
|
static Set<String> |
loadSetDefinition(String resName)
Load in a Set-style simple file of values.
|
static <K,V> Map<K,V> |
mapOf()
For JDK1.8 support.
|
static <K,V> Map<K,V> |
mapOf(K k,
V v) |
static <K,V> Map<K,V> |
mapOf(K k1,
V v1,
K k2,
V v2) |
static <K,V> Map<K,V> |
mapOf(K k1,
V v1,
K k2,
V v2,
K k3,
V v3) |
static List<Object> |
matchArgumentsToParameters(com.cedarsoftware.util.convert.Converter converter,
Collection<Object> values,
Parameter[] parameterTypes,
boolean useNull)
Build a List the same size of parameterTypes, where the objects in the list are ordered
to best match the parameters.
|
static Object |
newInstance(com.cedarsoftware.util.convert.Converter converter,
Class<?> c,
Collection<?> argumentValues)
Create a new instance of the passed in class c.
|
static String |
removeLeadingAndTrailingQuotes(String input)
Strip leading and trailing double quotes from the passed in String.
|
static <T> T |
safelyIgnoreException(Callable<T> callable,
T defaultValue) |
static void |
safelyIgnoreException(Runnable runnable) |
static void |
setFieldValue(Field field,
Object instance,
Object value) |
static <T> Set<T> |
setOf(T... items)
For JDK1.8 support.
|
static void |
setUseUnsafe(boolean state)
Globally turn on (or off) the 'unsafe' option of Class construction.
|
static int |
trimLength(String s)
Returns the length of the trimmed string.
|
static void |
trySetAccessible(AccessibleObject object) |
public static final String META_CLASS_FIELD_NAME
public static final String META_CLASS_NAME
public static void setUseUnsafe(boolean state)
state
- boolean true = on, false = off.@SafeVarargs public static <T> List<T> listOf(T... items)
@SafeVarargs public static <T> Set<T> setOf(T... items)
public static <K,V> Map<K,V> mapOf()
public static <K,V> Map<K,V> mapOf(K k, V v)
public static <K,V> Map<K,V> mapOf(K k1, V v1, K k2, V v2)
public static <K,V> Map<K,V> mapOf(K k1, V v1, K k2, V v2, K k3, V v3)
public static List<Object> matchArgumentsToParameters(com.cedarsoftware.util.convert.Converter converter, Collection<Object> values, Parameter[] parameterTypes, boolean useNull)
values
- A list of potential arguments. This list can be smaller than parameterTypes
or larger.parameterTypes
- A list of classes that the values will be matched against.public static int indexOfSmallestValue(int[] array)
array
- The array to search.public static String createCacheKey(Class<?> c, Collection<?> args)
public static Object newInstance(com.cedarsoftware.util.convert.Converter converter, Class<?> c, Collection<?> argumentValues)
c
- Class to instantiate.argumentValues
- List of values to supply to a constructor on 'c'. The constructor chosen on 'c'
will be the one with a combination of the most fields that are satisfied with
non-null values from the 'argumentsValues.' The method will attempt to use values
from the list as constructor arguments for the passed in class c, ordering them
to best-fit the constructor, by matching the class type of the argument values
to the class types of the parameters on 'c' constructors. It will use all
constructors exhaustively, until it is successful. If not, then it will look at
the 'unsafe' setting and attempt to use that.JsonIoException
- if it could not instantiate the passed in class. In that case, it is best to
create a ClassFactory for this specific class, and add that to the ReadOptions as an instantiator
that is associated to the class 'c'. In the ClassFactory, the JsonObject containing the data from the
associated JsonObject { } is passed in, allowing you to instantiate and load the values in one operation.
If you do that, and no further sub-objects exist, or you load the sub-objects in your ClassFactory,
make sure to return 'true' for isObjectFinal().public static String getLogMessage(String methodName, Object[] args)
public static <K,V> V getValueWithDefaultForNull(Map map, K key, V defaultValue)
public static <K,V> V getValueWithDefaultForMissing(Map map, K key, V defaultValue)
public static void trySetAccessible(AccessibleObject object)
public static <T> T safelyIgnoreException(Callable<T> callable, T defaultValue)
public static void safelyIgnoreException(Runnable runnable)
public static int length(String s)
s
- string to return length ofpublic static int trimLength(String s)
public static boolean isPrimitive(Class<?> c)
public static boolean isLogicalPrimitive(Class<?> c)
public static Map<Class<?>,Set<String>> loadClassToSetOfStrings(String fileName)
public static Set<String> commaSeparatedStringToSet(String commaSeparatedString)
public static Map<Class<?>,Map<String,String>> loadNonStandardMethodNames(String fileName)
public static Map<String,String> loadMapDefinition(String resName)
resName
- String name of the resource file.public static Set<String> loadSetDefinition(String resName)
resName
- String name of the resource file.public static String loadResourceAsString(String resourceName)
resourceName
- Name of the resource file.public static byte[] loadResourceAsBytes(String resourceName)
resourceName
- Name of the resource file.public static String removeLeadingAndTrailingQuotes(String input)
public static <T> T findClosest(Class<?> c, Map<Class<?>,T> workerClasses, T defaultClass)
c
- Class of object for which fetch a custom writerworkerClasses
- The classes to search throughdefaultClass
- the class to return when no viable class was found.Copyright © 2024. All rights reserved.