public class Lang extends Object implements Serializable
Osgl is the umbrella namespace aggregates core utilities of OSGL toolkit:
F namespaceMore about function interface
Under Osgl, there are six function interfaces defined, from Func0 to Func5, where the last digit means the number of parameters the function is applied to. For example, the apply method of Func0 takes no parameter while that of Func2 takes two parameters. All these function interfaces are defined with generic type parameters, corresponding to the type of all parameters and that of the return value. For procedure (a function that does not return anything), the user application could use Void as the return value type, and return null in the apply method implementation.
For each function interface, OSGL provide a base class, from F0 to F5. Within the base class, OSGL implement several utility methods, including
Lang.Break instanceUsually user application should define their function implementation by extending the base class in order to benefit from the utility methods; however in certain cases, e.g. a function implementation already extends another base class, user implementation cannot extends the base function class, OSGL provides easy way to convert user’s implementation to corresponding base class implementation, here is one example of how to do it:
void foo(Func2<Integer, String> f) { F2<Integer, String> newF = f2(f); newF.chain(…); … } Dumb functions, for certain case where a dumb function is needed, OSGL defines dumb function instances for each function interface, say, from F0 to F5. Note the name of the dumb function instance is the same as the name of the base function class. But they belong to different concept, class and instance, so there is no conflict in the code. For each dumb function instance, a corresponding type safe version is provided, f0() to f5(), this is the same case of java.util.Collections.EMPTY_LIST and java.util.Collections.emptyList()
Utility methods
| Modifier and Type | Class and Description |
|---|---|
static class |
Lang._ConvertStage<FROM> |
static class |
Lang._IsClass |
static class |
Lang._IsModifier |
static class |
Lang._IsReflectMember |
static class |
Lang._MappingStage
A stage of object for mapping operation
|
static interface |
Lang.Bijection<X,Y>
|
static class |
Lang.Binary<LEFT,RIGHT>
Alias of
Lang.Tuple |
static class |
Lang.Break
A Break is used to shortcut a sequence of function executions
|
static class |
Lang.Comparator<T>
Adapt JDK Comparator (since 1.2) to Functional programming.
|
static class |
Lang.Conf
Namespace to configure or extend OSGL _ utilities
|
static class |
Lang.F
The namespace to aggregate predefined core functions
|
static class |
Lang.F0<R>
Default implementation for
Lang.Func0. |
static class |
Lang.F1<P1,R>
Base implementation of
Lang.Function function. |
static class |
Lang.F2<P1,P2,R>
Base implementation of
Lang.Func2 function. |
static class |
Lang.F3<P1,P2,P3,R>
Base implementation of
Lang.Func3 function. |
static class |
Lang.F4<P1,P2,P3,P4,R>
Base implementation of
Lang.Func4 function. |
static class |
Lang.F5<P1,P2,P3,P4,P5,R>
Base implementation of
Lang.Func5 function. |
static class |
Lang.Factory<T>
The class adapt traditional Factory to Function
|
static interface |
Lang.Func0<R>
Define a function that apply to no parameter (strictly this is not a function)
|
static interface |
Lang.Func1<P1,R>
Alias of
Lang.Function |
static interface |
Lang.Func2<P1,P2,R>
Define a function structure that accept two parameter
|
static interface |
Lang.Func3<P1,P2,P3,R>
Define a function structure that accept three parameter
|
static interface |
Lang.Func4<P1,P2,P3,P4,R>
Define a function structure that accept four parameter
|
static interface |
Lang.Func5<P1,P2,P3,P4,P5,R>
Define a function structure that accept five parameter
|
static class |
Lang.FuncBase
The base for all Fx function class implemention
|
static interface |
Lang.Function<T,U>
Define a function structure that accept one parameter.
|
static class |
Lang.IndexedVisitor<K,T>
An
IndexedVisitor provide a tool to iterate through a Map or indexed list
by passing the key/index and the value to the function. |
static class |
Lang.Meta<T> |
static interface |
Lang.MultiplicableFunction<P1,R>
A
Lang.Function function that support Lang.MultiplicableFunction.times(int) operation |
static class |
Lang.None<T> |
static class |
Lang.Operator<T> |
static class |
Lang.Option<T>
Defines an option of element
T. |
static class |
Lang.Pair<LEFT,RIGHT>
Alias of
Lang.Binary |
static class |
Lang.Predicate<T>
Predicate is a predefined Function<Boolean, T> typed function with a set of utilities dealing with boolean operations. |
static class |
Lang.Processor<T>
Define a processor function which applied to one parameter and return the parameter instance after processing on the parameter
|
static class |
Lang.Producer<PRODUCT>
A Producer is a provider that
Lang.Producer.produce() product |
static class |
Lang.Provider<ELEMENT>
A Provider is a function that apply to nothing and return an element
|
static class |
Lang.Quadruple<A,B,C,D> |
static class |
Lang.Quintuple<A,B,C,D,E> |
static class |
Lang.Some<T> |
static class |
Lang.T2<A,B>
Alias of
Lang.Pair |
static class |
Lang.T3<A,B,C> |
static class |
Lang.T4<A,B,C,D> |
static class |
Lang.T5<A,B,C,D,E> |
static class |
Lang.Transformer<FROM,TO>
A Transformer is literally a kind of
Lang.F1 function |
static class |
Lang.Triple<A,B,C>
A tuple with three elements
|
static class |
Lang.Tuple<A,B> |
static class |
Lang.TypeConverter<FROM,TO>
A
TypeConverter is a Lang.Transformer that convert a type to another |
static class |
Lang.V1<P1> |
static class |
Lang.V2<P1,P2> |
static class |
Lang.V3<P1,P2,P3> |
static class |
Lang.V4<P1,P2,P3,P4> |
static class |
Lang.V5<P1,P2,P3,P4,P5> |
static class |
Lang.Val<T> |
static class |
Lang.Var<T> |
static class |
Lang.Visitor<T>
Define a visitor (known as Consumer in java 8) function which applied to one parameter and without return type
|
| Modifier and Type | Field and Description |
|---|---|
static Lang.Break |
BREAK
A predefined Break instance without payload
|
static Lang.Conf |
conf |
static Object |
DUMB
A dumb object instance
|
static Lang.F0 |
F0
A dumb function for
Lang.Func0 that does nothing and return null |
static Lang.F1 |
F1
A dumb
Lang.Function implementation that does nothing and return null |
static Lang.F2 |
F2
A dumb
Lang.Func2 implementation that does nothing and return null |
static Lang.F3 |
F3
A dumb
Lang.Func3 implementation that does nothing and return null |
static Lang.F4 |
F4
A dumb
Lang.Func4 implementation that does nothing and return null |
static Lang.F5 |
F5
A dumb
Lang.Func5 implementation that does nothing and return null |
static Lang |
INSTANCE |
static boolean |
IS_64 |
static boolean |
IS_SERVER |
static int |
JAVA_VERSION |
static Lang.None |
NONE |
static OS |
OS |
static PropertyHandlerFactory |
propertyHandlerFactory |
static osgl.version.Version |
VERSION |
| Modifier | Constructor and Description |
|---|---|
protected |
Lang() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
allNull(Object o,
Object... oa)
Check if all objects in the parameter list is null
|
static Set<Class> |
allTypesOf(Class<?> type)
Returns all types that
|
static boolean |
anyNull(Object o,
Object... oa)
Check if any objects in the parameter list is null
|
static <T extends Enum<T>> |
asEnum(Class<T> enumClass,
String name)
Return an enum value from code
|
static <T extends Enum<T>> |
asEnum(Class<T> enumClass,
String name,
boolean exactMatch)
Return an enum value from code
|
static Boolean[] |
asObject(boolean[] pa) |
static Byte[] |
asObject(byte[] pa) |
static Character[] |
asObject(char[] pa) |
static Double[] |
asObject(double[] pa) |
static Float[] |
asObject(float[] pa) |
static Integer[] |
asObject(int[] pa) |
static Long[] |
asObject(long[] pa) |
static Short[] |
asObject(short[] pa) |
static boolean[] |
asPrimitive(Boolean[] oa) |
static byte[] |
asPrimitive(Byte[] oa) |
static char[] |
asPrimitive(Character[] oa) |
static double[] |
asPrimitive(Double[] oa) |
static float[] |
asPrimitive(Float[] oa) |
static int[] |
asPrimitive(Integer[] oa) |
static long[] |
asPrimitive(Long[] oa) |
static short[] |
asPrimitive(Short[] oa) |
static <T> Future<T> |
async(Lang.F0<T> callback,
int milliseconds)
Execute callback asynchronously after delay specified
|
static <A,B> Lang.T2<A,B> |
Binary(A a,
B b) |
static boolean |
bool(BigDecimal v)
Do bool evaluation on a BigDecimal value
|
static boolean |
bool(BigInteger v)
Do bool evaluation on a BigInteger value
|
static boolean |
bool(boolean v) |
static boolean |
bool(byte v)
Do bool evaluation on a byte value
|
static boolean |
bool(char v)
Do bool evaluation on a char value
|
static boolean |
bool(Collection<?> c)
Do bool evaluation on a collection.
|
static boolean |
bool(double v)
Do bool evaluation on a double value
|
static boolean |
bool(File v)
Do bool evaluation on a File instance.
|
static boolean |
bool(float v)
Do bool evaluation on a float value
|
static boolean |
bool(int v)
Do bool evaluation on a int value
|
static boolean |
bool(Lang.Func0<?> v)
Do bool evaluation on an
Lang.Func0 instance. |
static boolean |
bool(long v)
Do bool evaluation on a long value
|
static boolean |
bool(Map<?,?> m)
Do bool evaluation on a map.
|
static boolean |
bool(Object v)
Evaluate an object’s bool value.
|
static boolean |
bool(String s)
Do bool evaluation on a String.
|
static <T> Lang.Break |
breakOut(T e)
A utility method to throw out a Break with payload
|
static <T> T |
cast(Object o) |
static <T> Lang.Option<T> |
cast(Object o,
Class<T> c)
Cast an object to a type.
|
static <T> Class<T> |
classForName(String className) |
static <T> Class<T> |
classForName(String className,
ClassLoader classLoader) |
static Lang._MappingStage |
clone(Object source)
|
static boolean[] |
cloneOf(boolean[] array) |
static byte[] |
cloneOf(byte[] array) |
static char[] |
cloneOf(char[] array) |
static double[] |
cloneOf(double[] array) |
static float[] |
cloneOf(float[] array) |
static int[] |
cloneOf(int[] array) |
static long[] |
cloneOf(long[] array) |
static short[] |
cloneOf(short[] array) |
static String[] |
cloneOf(String[] array) |
static <T> T |
cloneOf(T source)
Returns clone of a given
source object. |
static <T> T |
cloneOf(T source,
Lang.Function<Class,?> instanceFactory)
Returns clone of a given
source object. |
static Class<?> |
commonSuperTypeOf(Collection<?> objects) |
static Class<?> |
commonSuperTypeOf(Object o1,
Object o2,
Object... others) |
static <T> Lang.Comparator<T> |
comparator(Comparator<? super T> c)
Adapt a jdk
Comparator into osgl Comparator |
static <T> Lang.Comparator<T> |
comparator(Lang.Func2<? super T,? super T,Integer> f)
Adapt a general
Lang.Func2 function with (T, T, Integer) type into Comparator |
static boolean[] |
concat(boolean[] a1,
boolean[] a2) |
static boolean[] |
concat(boolean[] a1,
boolean[] a2,
boolean[]... rest) |
static byte[] |
concat(byte[] a1,
byte[] a2) |
static byte[] |
concat(byte[] a1,
byte[] a2,
byte[]... rest) |
static char[] |
concat(char[] a1,
char[] a2) |
static char[] |
concat(char[] a1,
char[] a2,
char[]... rest) |
static double[] |
concat(double[] a1,
double[] a2) |
static double[] |
concat(double[] a1,
double[] a2,
double[]... rest) |
static float[] |
concat(float[] a1,
float[] a2) |
static float[] |
concat(float[] a1,
float[] a2,
float[]... rest) |
static int[] |
concat(int[] a1,
int[] a2) |
static int[] |
concat(int[] a1,
int[] a2,
int[]... rest) |
static long[] |
concat(long[] a1,
long[] a2) |
static long[] |
concat(long[] a1,
long[] a2,
long[]... rest) |
static short[] |
concat(short[] a1,
short[] a2) |
static short[] |
concat(short[] a1,
short[] a2,
short[]... rest) |
static <T> T[] |
concat(T[] a,
T t) |
static <T> T[] |
concat(T[] a1,
T[] a2) |
static <T> T[] |
concat(T[] a1,
T[] a2,
T[]... rest) |
static <T> Const<T> |
constant() |
static <T> Const<T> |
constant(T t) |
static <T> ContextLocal<T> |
contextLocal() |
static <T> ContextLocal<T> |
contextLocal(ContextLocal.InitialValueProvider<T> ivp) |
static <FROM> Lang._ConvertStage<FROM> |
convert(FROM from) |
static Lang._MappingStage |
copy(Object source)
Prepare a Mapping operation with
shallow copy semantic |
static Lang._MappingStage |
deepCopy(Object source)
Prepare a Mapping operation with
deep copy semantic |
static <T> T |
deserialize(byte[] ba) |
static <T> T |
deserialize(byte[] ba,
Class<T> c) |
static void |
echo(String msg,
Object... args) |
static <T> T |
ensureGet(T t1,
Lang.F0<T> def1) |
static <T> T |
ensureGet(T t1,
List<T> defs) |
static <T> T |
ensureGet(T t1,
T def1) |
static <T> T |
ensureGet(T t1,
T def1,
T def2) |
static <T> T |
ensureGet(T t1,
T def1,
T def2,
T def3) |
static boolean |
eq(boolean a,
boolean b)
Check if two
boolean value equals to each other |
static boolean |
eq(byte a,
byte b)
Check if two
byte value equals to each other |
static boolean |
eq(char a,
char b)
Check if two
char value equals to each other |
static boolean |
eq(double a,
double b)
Check if two
double value equals to each other |
static boolean |
eq(float a,
float b)
Check if two
float value equals to each other |
static boolean |
eq(int a,
int b)
Check if two
int value equals to each other |
static boolean |
eq(long a,
long b)
Check if two
long value equals to each other |
static boolean |
eq(Object a,
Object b)
Check if two object is equals to each other.
|
static boolean |
eq(short a,
short b)
Check if two
short value equals to each other |
static boolean |
eq2(Object a,
Object b)
Check if two objects are equals to each other.
|
boolean |
equals(Object obj) |
static void |
error(String msg,
Object... args) |
static Map<String,Object> |
evaluate(Annotation anno)
Evaluate Annotation properties
|
static <T> Lang.F0<T> |
f0()
Return a dumb function for
Lang.Func0. |
static <R> Lang.F0<R> |
f0(Lang.Func0<? extends R> f0)
Convert a general
Lang.Func0 typed function to Lang.F0 type |
static <P1,R> Lang.F1<P1,R> |
f1()
The type-safe version of
F1 |
static <X,Y> Lang.F1<X,Y> |
f1(Lang.Bijection<X,Y> f1) |
static <P1,R> Lang.F1<P1,R> |
f1(Lang.Function<? super P1,? extends R> f1)
Convert a general
Lang.Function function into a Lang.F1 typed function |
static <P1,P2,R> Lang.F2<P1,P2,R> |
f2()
The type-safe version of
F2 |
static <P1,P2,R> Lang.F2<P1,P2,R> |
f2(Lang.Func2<? super P1,? super P2,? extends R> f2)
Convert a general
Lang.Func2 function into a Lang.F2 typed function |
static <P1,P2,P3,R> |
f3()
The type-safe version of
F3 |
static <P1,P2,P3,R> |
f3(Lang.Func3<? super P1,? super P2,? super P3,? extends R> f3)
Convert a general
Lang.Func3 function into a Lang.F3 typed function |
static <P1,P2,P3,P4,R> |
f4()
The type-safe version of
F4 |
static <P1,P2,P3,P4,R> |
f4(Lang.Func4<? super P1,? super P2,? super P3,? super P4,? extends R> f4)
Convert a general
Lang.Func4 function into a Lang.F4 typed function |
static <P1,P2,P3,P4,P5,R> |
f5()
The type-safe version of
F5 |
static <P1,P2,P3,P4,P5,R> |
f5(Lang.Func5<? super P1,? super P2,? super P3,? super P4,? super P5,? extends R> f5)
Convert a general
Lang.Func5 function into a Lang.F5 typed function |
static <T> Lang.Factory<T> |
factory(Lang.Func0<T> func) |
static Field |
fieldOf(Class<?> c,
String name)
Returns non-static field of a class by name.
|
static Field |
fieldOf(Class<?> c,
String name,
boolean noStatic)
Returns field of a class by name.
|
static Field |
fieldOf(Class<?> c,
String name,
Class<?> rootClass,
boolean noStatic)
Returns field of a class by name.
|
static List<Field> |
fieldsOf(Class<?> c)
Returns all fields of a class and all super classes.
|
static List<Field> |
fieldsOf(Class<?> c,
boolean noStatic)
Returns all fields of a class and all super classes.
|
static List<Field> |
fieldsOf(Class<?> c,
Class<?> rootClass,
boolean noStatic)
Returns all fields of a class and all super classes until root class.
|
static List<Field> |
fieldsOf(Class<?> c,
Class<?> rootClass,
boolean includeRootClass,
boolean noStatic)
Returns all fields of a class and all super classes until root class.
|
static List<Field> |
fieldsOf(Class<?> c,
Class<?> rootClass,
boolean includeRootClass,
Lang.Function<Field,Boolean> filter)
Returns all fields of a class and all super classes until root class.
|
static List<Field> |
fieldsOf(Class<?> c,
Class<?> rootClass,
Lang.Function<Field,Boolean> filter)
Returns all fields of a class and all super classes until root class.
|
static List<Field> |
fieldsOf(Class<?> c,
Lang.Function<Class<?>,Boolean> classFilter,
Lang.Function<Field,Boolean> fieldFilter)
Returns all fields of a class and all super classes until classFilter not applied.
|
static List<Field> |
fieldsOf(Class<?> c,
Lang.Function<Field,Boolean> filter)
Returns all fields of a class and all super classes.
|
static void |
fill(boolean element,
boolean[] array) |
static void |
fill(byte element,
byte[] array) |
static void |
fill(char element,
char[] array) |
static void |
fill(double element,
double[] array) |
static void |
fill(float element,
float[] array) |
static void |
fill(int element,
int[] array) |
static void |
fill(long element,
long[] array) |
static void |
fill(short element,
short[] array) |
static <T> void |
fill(T element,
T[] array) |
static Lang._MappingStage |
flatCopy(Object source)
Prepare a Mapping operation with
flat
copy semantic |
static String |
fmt(String tmpl,
Object... args)
Alias of
S.fmt(String, Object...) |
static <T> Lang.Predicate<T> |
generalPredicate(Lang.Visitor<? super T> f)
Convert a general
Function<T, ?> typed function to Predicate<T> function. |
static <T> T |
getFieldValue(Object obj,
Field field)
Get value of an object field.
|
static Method |
getMethod(Class c,
String methodName,
Class... argTypes)
Returns
Method by name and argument type |
static Method |
getMethod(Class c,
String methodName,
Object... pa)
Returns
Method by name and parameter value |
static <T> T |
getProperty(CacheService cache,
Object entity,
String property) |
static <T> T |
getProperty(Object entity,
String property) |
static <T> Lang.Meta<T> |
given(T t) |
static <T> Lang.Visitor<T> |
guardedVisitor(Lang.Function<? super T,Boolean> predicate,
Lang.Visitor<? super T> visitor)
Return a composed visitor function that only applies when the guard predicate test returns
true |
int |
hashCode() |
static <T> Lang.Meta<T> |
having(T t) |
static int |
hc() |
static int |
hc(boolean o) |
static int |
hc(boolean[] oa) |
static int |
hc(byte o) |
static int |
hc(byte[] oa) |
static int |
hc(char o) |
static int |
hc(char[] oa) |
static int |
hc(double o) |
static int |
hc(double[] oa)
Calculate hashcode of double array specified
|
static int |
hc(float o) |
static int |
hc(float[] oa) |
static int |
hc(int o) |
static int |
hc(int[] oa) |
static int |
hc(long o) |
static int |
hc(long[] oa) |
static int |
hc(Object o)
Calculate hashcode of objects specified
|
static int |
hc(Object o1,
Object o2)
Calculate hashcode of objects specified
|
static int |
hc(Object o1,
Object o2,
Object o3)
Calculate hashcode of objects specified
|
static int |
hc(Object o1,
Object o2,
Object o3,
Object o4)
Calculate hashcode of objects specified
|
static int |
hc(Object o1,
Object o2,
Object o3,
Object o4,
Object o5)
Calculate hashcode of objects specified
|
static int |
hc(Object o1,
Object o2,
Object o3,
Object o4,
Object o5,
Object... args)
Calculate hashcode of objects specified
|
static int |
hc(short o) |
static int |
hc(short[] oa) |
static <T> T |
ifNullThen(T t1,
Lang.F0<T> def1) |
static <T> T |
ifNullThen(T t1,
T def1) |
static <K,T> Lang.IndexedVisitor<K,T> |
indexGuardedVisitor(Lang.Function<? super K,Boolean> guard,
Lang.Visitor<? super T> visitor) |
static void |
init() |
static Set<Class> |
interfacesOf(Class<?> type)
Returns all implemented interfaces of a give type
|
static <T,R> R |
invokeStatic(Class<T> c,
String methodName,
Object... pa)
Invoke a static method by name and parameters
|
static <T,R> R |
invokeStatic(Lang.Var<Method> methodBag,
Class<T> c,
String methodName,
Object... pa)
Invoke a static method by name and parameters.
|
static <R> R |
invokeStatic(Method method,
Object... pa)
Invoke a static method.
|
static <T,R> R |
invokeVirtual(Lang.Var<Method> methodBag,
T o,
String methodName,
Object... pa)
Invoke a virtual method by instance, method name and arguments.
|
static <T,R> R |
invokeVirtual(T o,
Method method,
Object... pa)
Invoke a virtual
method. |
static <T,R> R |
invokeVirtual(T o,
String methodName,
Object... pa)
Invoke a virtual method by instance, method name and arguments.
|
static Lang._IsClass |
is(Class<?> c) |
static Lang._IsReflectMember |
is(Member member) |
static Lang._IsClass |
is(Object t) |
static boolean |
isCollectionType(Class<?> c)
Check if a given class
c is a collection type. |
static boolean |
isImmutable(Object o)
Check if an Object or class is immutable
|
static boolean |
isNotNull(Object o)
Check if an object is not
null and not NONE |
static boolean |
isNull(Object o)
Check if an object is
null or NONE |
static boolean |
isPrimitive(Class<?> c)
Deprecated.
|
static boolean |
isPrimitiveType(Class<?> c)
Check if a given class is a primitive type.
|
static boolean |
isPrimitiveType(String name)
Check if a given string is a primitive type name.
|
static boolean |
isSimpleType(Class<?> c)
Check if a give class
c is a simple type. |
static boolean |
isWrapper(Class<?> c)
Deprecated.
|
static boolean |
isWrapperType(Class<?> c)
Check if a given class is a wrapper type of a primitive type.
|
static int |
iterableHashCode(Iterable<?> it) |
static Lang._MappingStage |
map(Object source)
Prepare a Mapping operation with
map semantic and keyword matching |
static <T> T |
materialize(byte[] ba) |
static <T> T |
materialize(byte[] ba,
Class<T> c) |
static Lang._MappingStage |
merge(Object source)
Prepare a Mapping operation with
merge semantic |
static Lang._MappingStage |
mergeMap(Object source)
Prepare a Mapping operation with
merge map semantic and keyword matching |
static <T> Lang.Meta<T> |
meta(T t) |
static long |
ms()
Return
current time millis |
static boolean |
ne(Object a,
Object b)
Check if two objects are equals to each other.
|
static boolean[] |
newArray(boolean[] model) |
static boolean[] |
newArray(boolean[] model,
int size) |
static byte[] |
newArray(byte[] model) |
static byte[] |
newArray(byte[] model,
int size) |
static char[] |
newArray(char[] model) |
static char[] |
newArray(char[] model,
int size) |
static double[] |
newArray(double[] model) |
static double[] |
newArray(double[] model,
int size) |
static float[] |
newArray(float[] model) |
static float[] |
newArray(float[] model,
int size) |
static int[] |
newArray(int[] model) |
static int[] |
newArray(int[] model,
int size) |
static long[] |
newArray(long[] model) |
static long[] |
newArray(long[] model,
int size) |
static short[] |
newArray(short[] model) |
static short[] |
newArray(short[] model,
int size) |
static <T> T[] |
newArray(T[] model)
Create an new array with specified array type and length
|
static <T> T[] |
newArray(T[] model,
int size)
Create an new array with specified type and length
|
static <T> T |
newInstance(Class<T> c) |
static <T> T |
newInstance(Class<T> c,
Object p1,
Object p2,
Object p3,
Object p4,
Object p5,
Object... pa) |
static <T,P1> T |
newInstance(Class<T> c,
P1 p1) |
static <T,P1,P2> T |
newInstance(Class<T> c,
P1 p1,
P2 p2) |
static <T,P1,P2,P3> |
newInstance(Class<T> c,
P1 p1,
P2 p2,
P3 p3) |
static <T,P1,P2,P3,P4> |
newInstance(Class<T> c,
P1 p1,
P2 p2,
P3 p3,
P4 p4) |
static <T,P1,P2,P3,P4,P5> |
newInstance(Class<T> c,
P1 p1,
P2 p2,
P3 p3,
P4 p4,
P5 p5) |
static <T> T |
newInstance(String className) |
static <T> T |
newInstance(String className,
ClassLoader cl) |
static void |
nil()
An empty method.
|
static <T> Lang.None<T> |
none() |
static boolean |
noneNull(Object o,
Object... oa) |
static boolean |
not(BigDecimal v)
Returns negative of
bool(BigDecimal) |
static boolean |
not(BigInteger v)
Returns negative of
bool(BigInteger) |
static boolean |
not(boolean v)
Returns negative of a boolean value
|
static boolean |
not(byte v)
Returns negative of
bool(byte) |
static boolean |
not(char v)
Returns negative of
bool(char) |
static boolean |
not(Collection<?> c)
Returns negative of
bool(java.util.Collection) |
static boolean |
not(double v)
Returns negative of
bool(double) |
static boolean |
not(File file)
Returns negative of
bool(File) |
static boolean |
not(float v)
Returns negative of
bool(float) |
static boolean |
not(int v)
Returns negative of
bool(int) |
static boolean |
not(Lang.Func0<?> f)
Returns negative of
bool(Func0) |
static boolean |
not(long v)
Returns negative of
bool(long) |
static boolean |
not(Map<?,?> m)
Returns negative of
bool(java.util.Map) |
static boolean |
not(Object o)
Returns negative of
bool(java.lang.Object) |
static boolean |
not(String s)
Returns negative of
bool(java.lang.String) |
static <T> T |
notNull(T o)
Deprecated.
|
static <T> T |
NPE(T o) |
static long |
ns()
Return
current nano time |
static <A,B> Lang.T2<A,B> |
Pair(A a,
B b) |
static <T> Lang.Predicate<T> |
predicate(Lang.Function<? super T,Boolean> f)
Convert a
Function<T, Boolean> typed function to Predicate<T> function. |
static <T> T |
primitiveDefaultValue(Class<T> c) |
static Class |
primitiveTypeOf(Class c) |
static boolean |
random(boolean[] a) |
static byte |
random(byte[] a) |
static <T> T |
random(C.Range<T> range)
Returns a random element picked from elements in a
range. |
static char |
random(char[] a) |
static <T extends Enum> |
random(Class<T> enumType)
Pickup a random enum value from the enum type.
|
static double |
random(double[] a) |
static float |
random(float[] a) |
static int |
random(int[] a) |
static <T> T |
random(List<T> list)
Returns a random element picked from elements in a
list. |
static long |
random(long[] a) |
static short |
random(short[] a) |
static <T> T |
random(T[] ta)
Returns a random element picked from elements in
ta. |
static <T> T |
random(T t1,
T... ta)
Returns a random element picked from
t1 and elements in ta. |
static String |
randomStr()
Alias of
S.random() |
static String |
randomStr(int len)
Alias of
S.random(int) |
static <T> List<T> |
randomSubList(List<T> list)
Create a list contains random selected elements in the
list specified. |
static <T> List<T> |
randomSubList(List<T> list,
int minSize)
Create a list contains random selected elements in the
list specified. |
static <T> T |
requireNotNull(T o)
Return the object if it is not null, otherwise throw out
NullPointerException. |
static <T> T |
requireNotNull(T o,
String errorTemplate,
Object... errorArgs)
Return the object if it is not null, otherwise throw out
NullPointerException with error message specified |
static boolean[] |
resetArray(boolean[] array) |
static byte[] |
resetArray(byte[] array) |
static char[] |
resetArray(char[] array) |
static double[] |
resetArray(double[] array) |
static float[] |
resetArray(float[] array) |
static int[] |
resetArray(int[] array) |
static long[] |
resetArray(long[] array) |
static Object |
resetArray(Object array) |
static short[] |
resetArray(short[] array) |
static <T> T[] |
resetArray(T[] array) |
static void |
resetFieldValue(Object obj,
Field field) |
static boolean[] |
reverse(boolean[] a) |
static byte[] |
reverse(byte[] a) |
static char[] |
reverse(char[] a) |
static double[] |
reverse(double[] a) |
static float[] |
reverse(float[] a) |
static int[] |
reverse(int[] a) |
static long[] |
reverse(long[] a) |
static Object[] |
reverse(Object[] a) |
static short[] |
reverse(short[] a) |
static <T> Lang.Option<Class<T>> |
safeClassForName(String className) |
static <T> Lang.Option<Class<T>> |
safeClassForName(String className,
ClassLoader classLoader) |
static <T> Lang.Option<T> |
safeNewInstance(String className) |
static <T> int |
search(T element,
T... elements)
Search an element in a array
|
static <T> T |
secureRandom(C.Range<T> range)
The secure version of
random(C.Range). |
static <T> T |
secureRandom(List<T> list)
The secure version of
random(List). |
static <T> T |
secureRandom(T[] ta)
The secure version of
random(Object[]). |
static <T> T |
secureRandom(T t1,
T... ta)
The secure version of
random(Object, Object[]). |
static <T> byte[] |
serialize(T obj) |
static void |
setField(String fieldName,
Class<?> type,
Object val)
Set value to a static field of given class
|
static <T,F> T |
setField(String fieldName,
T obj,
F val)
Set an object field value using reflection.
|
static void |
setFieldValue(Object obj,
Field field,
Object fieldValue) |
static void |
setFieldValue(String fieldName,
Class<?> type,
Object val)
Alias of
setField(String, Class, Object) |
static <T,F> T |
setFieldValue(String fieldName,
T obj,
F val)
Alias of
setField(String, Object, Object) |
static void |
setProperty(CacheService cache,
Object entity,
Object val,
String property) |
static void |
setProperty(Object entity,
Object val,
String property) |
static void |
setStaticFieldValue(Class host,
String fieldName,
Object fieldValue) |
static void |
setStaticFieldValue(Field field,
Object fieldValue) |
static void |
sleep(long ms)
A convenient shortcut for
Thread.sleep(long). |
static <T> Lang.Option<T> |
some(T a) |
static boolean[] |
subarray(boolean[] src,
int begin,
int end) |
static byte[] |
subarray(byte[] src,
int begin,
int end) |
static char[] |
subarray(char[] src,
int begin,
int end) |
static double[] |
subarray(double[] src,
int begin,
int end) |
static float[] |
subarray(float[] src,
int begin,
int end) |
static int[] |
subarray(int[] src,
int begin,
int end) |
static long[] |
subarray(long[] src,
int begin,
int end) |
static short[] |
subarray(short[] src,
int begin,
int end) |
static <T> T[] |
subarray(T[] src,
int begin,
int end) |
static List<Class> |
superClassesOf(Class<?> type)
Returns all super classes of a given type ordered by affinity.
|
static <A,B> Lang.T2<A,B> |
T2(A a,
B b) |
static <A,B,C> Lang.T3<A,B,C> |
T3(A a,
B b,
C c) |
static <A,B,C,D> Lang.T4<A,B,C,D> |
T4(A a,
B b,
C c,
D d) |
static <A,B,C,D,E> |
T5(A a,
B b,
C c,
D d,
E e) |
static <T> Lang.Meta<T> |
take(T t) |
static <T> T |
times(Lang.Function<T,T> func,
T initVal,
int n) |
String |
toString() |
static String |
toString(Object o)
Returns String representation of an object instance.
|
static String |
toString2(Object o) |
static long |
ts()
Return current time stamp in nano seconds.
|
static <P1,P2> Lang.Binary<P1,P2> |
Tuple(P1 a,
P2 b) |
static <T> Lang.Val<T> |
val(T t) |
static <T> Lang.Var<T> |
var() |
static <T> Lang.Var<T> |
var(T t) |
static <T> Lang.Visitor<T> |
visitor(Lang.Function<? super T,?> f)
Convert a
Function<? super T, Void> function into a Lang.Visitor |
static Class |
wrapperClassOf(Class c) |
public static final osgl.version.Version VERSION
public static final Lang INSTANCE
public static final Lang.F0 F0
A dumb function for Lang.Func0 that does nothing and return null
f0()public static final Lang.F1 F1
A dumb Lang.Function implementation that does nothing and return null
f1()public static final Lang.F2 F2
A dumb Lang.Func2 implementation that does nothing and return null
f2()public static final Lang.F3 F3
A dumb Lang.Func3 implementation that does nothing and return null
f3()public static final Lang.F4 F4
A dumb Lang.Func4 implementation that does nothing and return null
f4()public static final Lang.F5 F5
A dumb Lang.Func5 implementation that does nothing and return null
f5()public static final Lang.Break BREAK
A predefined Break instance without payload
public static final Lang.None NONE
public static final Object DUMB
A dumb object instance
public static PropertyHandlerFactory propertyHandlerFactory
public static final Lang.Conf conf
public static final int JAVA_VERSION
public static final boolean IS_SERVER
public static final boolean IS_64
public static final OS OS
public static <T> Lang.Factory<T> factory(Lang.Func0<T> func)
public static <T> Lang.F0<T> f0()
Return a dumb function for Lang.Func0. This is the type-safe version of F0
T - a generic type that matches whatever type required by the context of applying the functionnullpublic static <R> Lang.F0<R> f0(Lang.Func0<? extends R> f0)
Convert a general Lang.Func0 typed function to Lang.F0 type
R - the generic type of the return value when applying function f0f0 - a function of type Lang.Func0 that returns type R valueLang.F0 type that is equaivlent to function f0public static <P1,R> Lang.F1<P1,R> f1()
The type-safe version of F1
P1 - the argument typeR - the return value typeF1public static <P1,R> Lang.F1<P1,R> f1(Lang.Function<? super P1,? extends R> f1)
Convert a general Lang.Function function into a Lang.F1 typed function
P1 - the argument typeR - the return value typef1 - the function that consumes P1 and produce RRpublic static <X,Y> Lang.F1<X,Y> f1(Lang.Bijection<X,Y> f1)
public static <P1,P2,R> Lang.F2<P1,P2,R> f2()
The type-safe version of F2
P1 - the type of the first param the new function applied toP2 - the type of the second param the new function applied toR - the type of new function application resultF2public static <P1,P2,R> Lang.F2<P1,P2,R> f2(Lang.Func2<? super P1,? super P2,? extends R> f2)
Convert a general Lang.Func2 function into a Lang.F2 typed function
P1 - the type of the first param the new function applied toP2 - the type of the second param the new function applied toR - the type of new function application resultf2 - the function that takes two arguments and return type RF2 instance corresponding to the specified Func2 instancepublic static <P1,P2,P3,R> Lang.F3<P1,P2,P3,R> f3()
The type-safe version of F3
P1 - the type of first parameter this function applied toP2 - the type of second parameter this function applied toP3 - the type of thrid parameter this function applied toR - the type of the return value when this function applied to the parameter(s)F3public static <P1,P2,P3,R> Lang.F3<P1,P2,P3,R> f3(Lang.Func3<? super P1,? super P2,? super P3,? extends R> f3)
Convert a general Lang.Func3 function into a Lang.F3 typed function
P1 - type of argument 1P2 - type of argument 2P3 - type of argument 3R - return typef3 - the general function with three paramsF3 typed instance which is equivalent to f3public static <P1,P2,P3,P4,R> Lang.F4<P1,P2,P3,P4,R> f4()
The type-safe version of F4
P1 - type of first argumentP2 - type of second argumentP3 - type of third argumentP4 - type of fourth argumentR - type of return valueF4 functionpublic static <P1,P2,P3,P4,R> Lang.F4<P1,P2,P3,P4,R> f4(Lang.Func4<? super P1,? super P2,? super P3,? super P4,? extends R> f4)
Convert a general Lang.Func4 function into a Lang.F4 typed function
P1 - type of first argumentP2 - type of second argumentP3 - type of third argumentP4 - type of fourth argumentR - type of return valuef4 - the function to be convertedLang.F4 type that is equivalent to function f4public static <P1,P2,P3,P4,P5,R> Lang.F5<P1,P2,P3,P4,P5,R> f5()
The type-safe version of F5
P1 - type of first argumentP2 - type of second argumentP3 - type of third argumentP4 - type of fourth argumentP5 - type of fifth argumentR - type of return valueF5 functionpublic static <P1,P2,P3,P4,P5,R> Lang.F5<P1,P2,P3,P4,P5,R> f5(Lang.Func5<? super P1,? super P2,? super P3,? super P4,? super P5,? extends R> f5)
Convert a general Lang.Func5 function into a Lang.F5 typed function
P1 - type of first argumentP2 - type of second argumentP3 - type of third argumentP4 - type of fourth argumentP5 - type of fifth argumentR - type of return valuef5 - the function to be convertedLang.F5 type that is equivalent to function f5public static <T> Lang.Comparator<T> comparator(Lang.Func2<? super T,? super T,Integer> f)
Adapt a general Lang.Func2 function with (T, T, Integer) type into Comparator
T - the type of the parameterf - The function takes two params (the same type) and returns integerComparator instance backed by function fpublic static <T> Lang.Comparator<T> comparator(Comparator<? super T> c)
Adapt a jdk Comparator into osgl Comparator
T - the element type the comparator comparesc - the jdk compatorComparator instance backed by comparator cpublic static <T> Lang.Predicate<T> predicate(Lang.Function<? super T,Boolean> f)
Convert a Function<T, Boolean> typed function to Predicate<T> function.
If the function specified is already a Lang.Predicate, then the function itself is returned
T - the argument typef - the function to be convertedLang.Predicate type that is equivalent to function fpublic static <T> Lang.Predicate<T> generalPredicate(Lang.Visitor<? super T> f)
Convert a general Function<T, ?> typed function to Predicate<T> function. When the predicate function returned apply to a param, it will first apply the specified f1 to the param, and they call bool(java.lang.Object) to evaluate the boolean value of the return object of the application.
If the function specified is already a Lang.Predicate, then the function itself is returned
T - the argument typef - the functionLang.Predicate type that is equivalent to the function fpublic static <T> Lang.Visitor<T> visitor(Lang.Function<? super T,?> f)
Convert a Function<? super T, Void> function into a Lang.Visitor
T - the argument typef - the function to be castLang.Visitor type function that is equal with the function fpublic static <T> Lang.Visitor<T> guardedVisitor(Lang.Function<? super T,Boolean> predicate, Lang.Visitor<? super T> visitor)
Return a composed visitor function that only applies when the guard predicate test returns true
T - the type of the element be tested and visitedpredicate - the predicate to test the element been visitedvisitor - the function that visit(accept) the element if the guard tested the element successfullypublic static <T> Lang.Break breakOut(T e)
A utility method to throw out a Break with payload
T - the type of the payloade - the payload objectpublic static <K,T> Lang.IndexedVisitor<K,T> indexGuardedVisitor(Lang.Function<? super K,Boolean> guard, Lang.Visitor<? super T> visitor)
public static <FROM> Lang._ConvertStage<FROM> convert(FROM from)
public static <P1,P2> Lang.Binary<P1,P2> Tuple(P1 a, P2 b)
public static <A,B> Lang.T2<A,B> T2(A a, B b)
public static <A,B> Lang.T2<A,B> Binary(A a, B b)
public static <A,B> Lang.T2<A,B> Pair(A a, B b)
public static <A,B,C> Lang.T3<A,B,C> T3(A a, B b, C c)
public static <A,B,C,D> Lang.T4<A,B,C,D> T4(A a, B b, C c, D d)
public static <A,B,C,D,E> Lang.T5<A,B,C,D,E> T5(A a, B b, C c, D d, E e)
public static <T> Lang.Option<T> some(T a)
public static <T> Lang.None<T> none()
public static <T> Lang.Var<T> var(T t)
public static <T> Lang.Var<T> var()
public static <T> Lang.Val<T> val(T t)
public static <T> Const<T> constant(T t)
public static <T> Const<T> constant()
public static boolean eq(Object a, Object b)
Check if two object is equals to each other.
a - the first objectb - the second objecttrue if a equals to bne(Object, Object)public static boolean eq2(Object a, Object b)
Check if two objects are equals to each other. The comparison will do array equal matching if needed
a - the first objectb - the second objecttrue if the first object equals to the second objectpublic static boolean eq(boolean a,
boolean b)
Check if two boolean value equals to each other
a - boolean ab - boolean btrue if a == bpublic static boolean eq(byte a,
byte b)
Check if two byte value equals to each other
a - byte ab - byte btrue if a == bpublic static boolean eq(char a,
char b)
Check if two char value equals to each other
a - char ab - char btrue if a == bpublic static boolean eq(short a,
short b)
Check if two short value equals to each other
a - short ab - short btrue if a == bpublic static boolean eq(int a,
int b)
Check if two int value equals to each other
a - int ab - int btrue if a == bpublic static boolean eq(float a,
float b)
Check if two float value equals to each other
a - float ab - float btrue if a == bpublic static boolean eq(long a,
long b)
Check if two long value equals to each other
a - long ab - long btrue if a == bpublic static boolean eq(double a,
double b)
Check if two double value equals to each other
a - double ab - double btrue if a == bpublic static boolean ne(Object a, Object b)
Check if two objects are equals to each other.
a - the first objectb - the second objectfalse if a equals to beq(Object, Object)public static boolean bool(Object v)
Evaluate an object’s bool value. The rules are:
| case | bool value |
|---|---|
null | false |
NONE | false |
| String | S.notEmpty(v) |
| Collection | !v.isEmpty() |
| Array | length of the array > 0 |
| Byte | v != 0 |
| Char | v != 0 |
| Integer | v != 0 |
| Long | v != 0L |
| Float | Math.abs(v) > Float.MIN_NORMAL |
| Double | Math.abs(v) > Double.MIN_NORMAL |
| BigInteger | !BigInteger.ZERO.equals(v) |
| BigDecimal | !BigDecimal.ZERO.equals(v) |
| File | v.exists() |
Lang.Func0 | bool(v.apply()) |
| Other types | true |
v - the value to be evaluatedtrue if v evaluate to true, false otherwisepublic static boolean bool(boolean v)
public static boolean bool(String s)
Do bool evaluation on a String.
A String typed instance is considered to be false when
false (case insensitive mode)s - the string to be evaluatedtrue if s is not empty and s is not falseS.empty(String)public static boolean bool(Collection<?> c)
Do bool evaluation on a collection.
c - the collection to be evaluatedtrue if the collection is not emptyCollection.isEmpty()public static boolean bool(Map<?,?> m)
Do bool evaluation on a map.
m - the map to be evaluatedtrue if the map is not emptyMap.isEmpty()public static boolean bool(byte v)
Do bool evaluation on a byte value
v - the value to be evaluatedtrue if the value != 0public static boolean bool(char v)
Do bool evaluation on a char value
v - the value to be evaluatedtrue if the value != 0public static boolean bool(int v)
Do bool evaluation on a int value
v - the value to be evaluatedtrue if the value != 0public static boolean bool(long v)
Do bool evaluation on a long value
v - the value to be evaluatedtrue if the value != 0public static boolean bool(float v)
Do bool evaluation on a float value
v - the value to be evaluatedtrue if Math.abs(v) > Float.MIN_NORMALpublic static boolean bool(double v)
Do bool evaluation on a double value
v - the value to be evaluatedtrue if Math.abs(v) > Double.MIN_NORMALpublic static boolean bool(BigDecimal v)
Do bool evaluation on a BigDecimal value
v - the value to be evaluatedtrue if !BigDecimal.ZERO.equals(v)public static boolean bool(BigInteger v)
Do bool evaluation on a BigInteger value
v - the value to be evaluatedtrue if !BigInteger.ZERO.equals(v)public static boolean bool(File v)
Do bool evaluation on a File instance.
v - the file to be evaluatedtrue if v.exists()public static boolean bool(Lang.Func0<?> v)
Do bool evaluation on an Lang.Func0 instance. This will call the Lang.Func0.apply() method and continue to do bool evaluation on the return value
v - the function to be evaluatedbool(v.apply())public static boolean not(Object o)
Returns negative of bool(java.lang.Object)
o - the object to be evaluated!(bool(o))public static boolean not(boolean v)
Returns negative of a boolean value
v - the value to be evaluated!vpublic static boolean not(String s)
Returns negative of bool(java.lang.String)
s - the String to be evaluated!(bool(s))bool(String)public static boolean not(Map<?,?> m)
Returns negative of bool(java.util.Map)
m - a map to be evauated!(bool(c))bool(java.util.Map)public static boolean not(Collection<?> c)
Returns negative of bool(java.util.Collection)
c - the Collection to be evaluated!(bool(c))bool(java.util.Collection)public static boolean not(byte v)
Returns negative of bool(byte)
v - the byte to be evaluated!(bool(v))public static boolean not(char v)
Returns negative of bool(char)
v - the char to be evaluated!(bool(v))public static boolean not(int v)
Returns negative of bool(int)
v - the int to be evaluated!(bool(v))public static boolean not(long v)
Returns negative of bool(long)
v - the long to be evaluated!(bool(v))public static boolean not(float v)
Returns negative of bool(float)
v - the float to be evaluated!(bool(v))public static boolean not(double v)
Returns negative of bool(double)
v - the double to be evaluated!(bool(v))public static boolean not(BigDecimal v)
Returns negative of bool(BigDecimal)
v - the value to be evaluated!(bool(v))public static boolean not(BigInteger v)
Returns negative of bool(BigInteger)
v - the value to be evaluated!(bool(v))public static boolean not(File file)
Returns negative of bool(File)
file - the file to be evaluated!(bool(file))public static boolean not(Lang.Func0<?> f)
Returns negative of bool(Func0)
f - the function to be evaluated!(bool(f))public static boolean isNull(Object o)
Check if an object is null or NONE
o - the object to testtrue if o is null or NONE, or false otherwisepublic static boolean isNotNull(Object o)
Check if an object is not null and not NONE
o - the object to testfalse if o is null or NONE, or true otherwisepublic static boolean anyNull(Object o, Object... oa)
Check if any objects in the parameter list is null
o - the first object to be checkedoa - the array of objects to be checkedtrue if any one of the argument is nullpublic static boolean allNull(Object o, Object... oa)
Check if all objects in the parameter list is null
o - the first object to be checkedoa - the array of objects to be checkedfalse if any one of the argument is not null and not NONEpublic static String toString(Object o)
Returns String representation of an object instance. Predicate the object specified is null or NONE, then an empty string is returned
o - the object which will be converted into a stringpublic static String fmt(String tmpl, Object... args)
Alias of S.fmt(String, Object...)
tmpl - the format templateargs - the format argumentspublic static int iterableHashCode(Iterable<?> it)
public static int hc()
public static int hc(boolean o)
public static int hc(boolean[] oa)
public static int hc(short o)
public static int hc(short[] oa)
public static int hc(byte o)
public static int hc(byte[] oa)
public static int hc(char o)
public static int hc(char[] oa)
public static int hc(int o)
public static int hc(int[] oa)
public static int hc(float o)
public static int hc(float[] oa)
public static int hc(long o)
public static int hc(long[] oa)
public static int hc(double o)
public static int hc(double[] oa)
Calculate hashcode of double array specified
oa - the double arraypublic static int hc(Object o)
Calculate hashcode of objects specified
o - object on which hash code to be calculatedpublic static int hc(Object o1, Object o2)
Calculate hashcode of objects specified
o1 - object 1o2 - object 2public static int hc(Object o1, Object o2, Object o3)
Calculate hashcode of objects specified
o1 - object 1o2 - object 2o3 - object 3public static int hc(Object o1, Object o2, Object o3, Object o4)
Calculate hashcode of objects specified
o1 - object 1o2 - object 2o3 - object 3o4 - object 4public static int hc(Object o1, Object o2, Object o3, Object o4, Object o5)
Calculate hashcode of objects specified
o1 - object 1o2 - object 2o3 - object 3o4 - object 4o5 - object 5public static int hc(Object o1, Object o2, Object o3, Object o4, Object o5, Object... args)
Calculate hashcode of objects specified
o1 - object 1o2 - object 2o3 - object 3o4 - object 4o5 - object 5args - other objectspublic static long ms()
Return current time millis
public static long ns()
Return current nano time
public static long ts()
Return current time stamp in nano seconds. Alias of ns()
public static void nil()
An empty method.
public static <T extends Enum<T>> T asEnum(Class<T> enumClass, String name)
Return an enum value from code
T - the generic enum typeenumClass - the enum classname - the name of the enum value. name is case insensitivenull if there is no value has the name specifiedpublic static <T extends Enum<T>> T asEnum(Class<T> enumClass, String name, boolean exactMatch)
Return an enum value from code
T - the generic enum typeenumClass - the enum classname - the name of the enum value. name is case insensitiveexactMatch - specify whether it should do exact name lookup or keyword variable lookupnull if there is no value has the name specifiedpublic static <T> int search(T element,
T... elements)
Search an element in a array
T - the typeelement - the element to be locatedelements - the array of element to be searched-1 if not foundpublic static <T> T ifNullThen(T t1,
T def1)
public static <T> T ensureGet(T t1,
T def1)
public static <T> T ifNullThen(T t1,
Lang.F0<T> def1)
public static <T> T ensureGet(T t1,
Lang.F0<T> def1)
public static <T> T ensureGet(T t1,
T def1,
T def2)
public static <T> T ensureGet(T t1,
T def1,
T def2,
T def3)
public static <T> T ensureGet(T t1,
List<T> defs)
public static <T> T times(Lang.Function<T,T> func, T initVal, int n)
public static <T> Lang.Meta<T> meta(T t)
public static <T> Lang.Meta<T> given(T t)
public static <T> Lang.Meta<T> having(T t)
public static <T> Lang.Meta<T> take(T t)
public static Lang._IsClass is(Object t)
public static Lang._IsClass is(Class<?> c)
public static Lang._IsReflectMember is(Member member)
public static Set<Class> interfacesOf(Class<?> type)
Returns all implemented interfaces of a give type
type - a classtype implementspublic static List<Class> superClassesOf(Class<?> type)
Returns all super classes of a given type ordered by affinity. The Object.class is always the last element in the list.
type - a classtypepublic static Set<Class> allTypesOf(Class<?> type)
Returns all types that
type - public static <T> Lang.Option<T> cast(Object o, Class<T> c)
Cast an object to a type. Returns an Lang.Option describing the casted value if it can be casted to the type specified, otherwise returns NONE.
T - the type of the result option valueo - the object to be castedc - specify the type to be casted toOption describing the typed value or NONE if it cannot be castedpublic static <T> T cast(Object o)
@Deprecated public static <T> T notNull(T o)
Return the object if it is not null, otherwise throw out NullPointerException.
This method is deprecated. Please use requireNotNull(Object) instead
T - the type parameter of objecto - the objectNullPointerException - if o is nullpublic static <T> T requireNotNull(T o)
Return the object if it is not null, otherwise throw out NullPointerException.
T - the type parameter of objecto - the objectNullPointerException - if o is nullpublic static <T> T requireNotNull(T o,
String errorTemplate,
Object... errorArgs)
Return the object if it is not null, otherwise throw out NullPointerException with error message specified
T - the type parameter of objecto - the objecterrorTemplate - the error message templateerrorArgs - the error message argumentsNullPointerException - if o is nullpublic static <T,F> T setField(String fieldName, T obj, F val)
Set an object field value using reflection.
T - the type of the objectF - the type of the field valuefieldName - the name of the field to be setobj - the object on which the value will be setval - the value to be set to the fieldpublic static <T,F> T setFieldValue(String fieldName, T obj, F val)
Alias of setField(String, Object, Object)
public static void setField(String fieldName, Class<?> type, Object val)
Set value to a static field of given class
fieldName - the name of the fieldtype - the class hosts the fieldval - the value to be set on the static fieldpublic static void setFieldValue(String fieldName, Class<?> type, Object val)
Alias of setField(String, Class, Object)
public static <T> T getFieldValue(Object obj, Field field)
Get value of an object field.
T - the field typeobj - the objectfield - the fieldpublic static void setStaticFieldValue(Class host, String fieldName, Object fieldValue)
public static boolean isSimpleType(Class<?> c)
Check if a give class c is a simple type. The following classes are considered to be simple type: 1. primitive types, e.g. int.class 2. Wrapper type of primitive types, e.g. Integer.class 3. String.class 4. Any class extends Enum.class 5. Locale.class
c - the class to be checkedtrue if the give type c is simple type as described abovepublic static boolean isCollectionType(Class<?> c)
Check if a given class c is a collection type. A collection type here means java.util.Collection plus an array class.
c - the class to be checkedtrue if the given type c is a Collection or arraypublic static boolean isImmutable(Object o)
Check if an Object or class is immutable
o - the object to be checkedtrue if the object is immutable or false otherwisepublic static boolean isPrimitiveType(Class<?> c)
Check if a given class is a primitive type.
c - the classtrue if c is primitive type@Deprecated public static boolean isPrimitive(Class<?> c)
Check if a given class is a primitive type.
This method is deprecated. Please use isPrimitiveType(Class) instead
c - the classtrue if c is primitive typepublic static boolean isPrimitiveType(String name)
Check if a given string is a primitive type name.
name - the string to be testtrue if name is primitive type namepublic static boolean isWrapperType(Class<?> c)
Check if a given class is a wrapper type of a primitive type.
c - the classtrue if c is wrapper type@Deprecated public static boolean isWrapper(Class<?> c)
Check if a given class is a wrapper type of a primitive type.
This method is deprecated, please use isWrapperType(Class) instead.
c - the classtrue if c is wrapper typepublic static <T> Class<T> classForName(String className, ClassLoader classLoader)
public static <T> Lang.Option<Class<T>> safeClassForName(String className)
public static <T> Lang.Option<Class<T>> safeClassForName(String className, ClassLoader classLoader)
public static <T> T newInstance(String className)
public static <T> T newInstance(String className, ClassLoader cl)
public static <T> Lang.Option<T> safeNewInstance(String className)
public static <T> T primitiveDefaultValue(Class<T> c)
public static <T> T newInstance(Class<T> c)
public static <T,P1> T newInstance(Class<T> c, P1 p1)
public static <T,P1,P2> T newInstance(Class<T> c, P1 p1, P2 p2)
public static <T,P1,P2,P3> T newInstance(Class<T> c, P1 p1, P2 p2, P3 p3)
public static <T,P1,P2,P3,P4> T newInstance(Class<T> c, P1 p1, P2 p2, P3 p3, P4 p4)
public static <T,P1,P2,P3,P4,P5> T newInstance(Class<T> c, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
public static <T> T newInstance(Class<T> c, Object p1, Object p2, Object p3, Object p4, Object p5, Object... pa)
public static Field fieldOf(Class<?> c, String name)
Returns non-static field of a class by name. The field might be non-public declared in super classes of the supplied class
c - the classname - the name of the fieldnull if not foundpublic static Field fieldOf(Class<?> c, String name, boolean noStatic)
Returns field of a class by name. The field could be non-public field of super class of the class specified
c - the classname - the name of the fieldnoStatic - specify if static fields shall be includednull if not foundpublic static Field fieldOf(Class<?> c, String name, Class<?> rootClass, boolean noStatic)
Returns field of a class by name. The field could be non-public field of super class of the class specified
c - the classname - the name of the fieldrootClass - the class that stops of the recurive operation. Default is Object.classnoStatic - specify if static fields shall be includednull if not foundpublic static List<Field> fieldsOf(Class<?> c)
Returns all fields of a class and all super classes. Note all fields returned will be called on AccessibleObject.setAccessible(boolean) with value true
c - the classpublic static List<Field> fieldsOf(Class<?> c, Lang.Function<Field,Boolean> filter)
Returns all fields of a class and all super classes. Note all fields returned will be called on AccessibleObject.setAccessible(boolean) with value true
c - the classfilter - specify which field will be put into the list if not nullpublic static List<Field> fieldsOf(Class<?> c, boolean noStatic)
Returns all fields of a class and all super classes. Note all fields returned will be called on AccessibleObject.setAccessible(boolean) with value true
c - the classnoStatic - specify if static fields shall be included. Default: truepublic static List<Field> fieldsOf(Class<?> c, Class<?> rootClass, boolean noStatic)
Returns all fields of a class and all super classes until root class. Note all fields returned will be called on AccessibleObject.setAccessible(boolean) with value true
c - the classrootClass - the class that stops the recursive operationnoStatic - specify if static fields should be includedpublic static List<Field> fieldsOf(Class<?> c, Class<?> rootClass, boolean includeRootClass, boolean noStatic)
Returns all fields of a class and all super classes until root class. Note all fields returned will be called on AccessibleObject.setAccessible(boolean) with value true
c - the classrootClass - the class that stops the recursive operationnoStatic - specify if static fields should be includedpublic static List<Field> fieldsOf(Class<?> c, Class<?> rootClass, Lang.Function<Field,Boolean> filter)
Returns all fields of a class and all super classes until root class. Note all fields returned will be called on AccessibleObject.setAccessible(boolean) with value true.
c - the classrootClass - the class that stops the recursive lookupfilter - specify which field should be put into the list if not nullpublic static List<Field> fieldsOf(Class<?> c, Class<?> rootClass, boolean includeRootClass, Lang.Function<Field,Boolean> filter)
Returns all fields of a class and all super classes until root class. Note all fields returned will be called on AccessibleObject.setAccessible(boolean) with value true.
c - the classrootClass - the class that stops the recursive lookupincludeRootClass - specify root class itself needs to be checked or notfilter - specify which field should be put into the list if not nullpublic static List<Field> fieldsOf(Class<?> c, Lang.Function<Class<?>,Boolean> classFilter, Lang.Function<Field,Boolean> fieldFilter)
Returns all fields of a class and all super classes until classFilter not applied. Note all fields returned will be called on AccessibleObject.setAccessible(boolean) with value true.
c - the classclassFilter - the filter to check if it should break recursive callfieldFilter - specify which field should be put into the list if not nullpublic static <T,R> R invokeStatic(Class<T> c, String methodName, Object... pa)
Invoke a static method by name and parameters
T - the generic type of the classR - the generic type of the return resultc - the classmethodName - the method namepa - the parameterspublic static <T,R> R invokeStatic(Lang.Var<Method> methodBag, Class<T> c, String methodName, Object... pa)
Invoke a static method by name and parameters. After invocation it will cache the method into method bag supplied. This method will convert all checked exception into corresponding runtime exception
T - the generic type of classR - the generic type of return instancemethodBag - the method bagc - the classmethodName - the method namepa - the parameterspublic static <R> R invokeStatic(Method method, Object... pa)
Invoke a static method. This method will convert all checked exception into corresponding runtime exception
R - the generic type of the return resultmethod - the methodpa - the arguments to invoke the methodpublic static <T,R> R invokeVirtual(Lang.Var<Method> methodBag, T o, String methodName, Object... pa)
Invoke a virtual method by instance, method name and arguments. This method will convert all checked exception into corresponding runtime exception.
After invocation, the method will be cached into the method bag supplied
T - generic type of the instance objectR - generic type of the return resultmethodBag - A function to cache the method found by name and argumentso - the instance on which the virtual method will be invokedmethodName - the method namepa - the argumentspublic static <T,R> R invokeVirtual(T o,
String methodName,
Object... pa)
Invoke a virtual method by instance, method name and arguments. This method will convert all checked exception into corresponding runtime exception
T - generic type of the instance objectR - generic type of the return resulto - the instance on which the virtual method will be invokedmethodName - the method namepa - the argumentspublic static <T,R> R invokeVirtual(T o,
Method method,
Object... pa)
Invoke a virtual method. This method will convert all checked exception to corresponding runtime exception
T - generic type of the instanceR - generic type of the resulto - the instance on which the method will be invokedmethod - the methodpa - the argumentspublic static Method getMethod(Class c, String methodName, Object... pa)
Returns Method by name and parameter value
c - the classmethodName - the method namepa - the parameter used to invoke the methodnull if not foundpublic static Method getMethod(Class c, String methodName, Class... argTypes)
Returns Method by name and argument type
c - the classmethodName - the method nameargTypes - the argument typesnull if not foundpublic static <T> T getProperty(CacheService cache, Object entity, String property)
public static void setProperty(CacheService cache, Object entity, Object val, String property)
public static <T> byte[] serialize(T obj)
public static <T> T materialize(byte[] ba,
Class<T> c)
public static <T> T deserialize(byte[] ba,
Class<T> c)
public static <T> T materialize(byte[] ba)
public static <T> T deserialize(byte[] ba)
public static <T> T[] newArray(T[] model)
Create an new array with specified array type and length
T - the array component typemodel - the model arraypublic static <T> T[] newArray(T[] model,
int size)
Create an new array with specified type and length
T - the component typemodel - the model arraysize - the new array lengthpublic static int[] newArray(int[] model)
public static int[] newArray(int[] model,
int size)
public static byte[] newArray(byte[] model)
public static byte[] newArray(byte[] model,
int size)
public static char[] newArray(char[] model)
public static char[] newArray(char[] model,
int size)
public static short[] newArray(short[] model)
public static short[] newArray(short[] model,
int size)
public static long[] newArray(long[] model)
public static long[] newArray(long[] model,
int size)
public static float[] newArray(float[] model)
public static float[] newArray(float[] model,
int size)
public static double[] newArray(double[] model)
public static double[] newArray(double[] model,
int size)
public static boolean[] newArray(boolean[] model)
public static boolean[] newArray(boolean[] model,
int size)
public static boolean[] resetArray(boolean[] array)
public static byte[] resetArray(byte[] array)
public static short[] resetArray(short[] array)
public static char[] resetArray(char[] array)
public static int[] resetArray(int[] array)
public static float[] resetArray(float[] array)
public static long[] resetArray(long[] array)
public static double[] resetArray(double[] array)
public static <T> T[] resetArray(T[] array)
public static <T> T[] subarray(T[] src,
int begin,
int end)
public static boolean[] subarray(boolean[] src,
int begin,
int end)
public static byte[] subarray(byte[] src,
int begin,
int end)
public static short[] subarray(short[] src,
int begin,
int end)
public static char[] subarray(char[] src,
int begin,
int end)
public static int[] subarray(int[] src,
int begin,
int end)
public static float[] subarray(float[] src,
int begin,
int end)
public static long[] subarray(long[] src,
int begin,
int end)
public static double[] subarray(double[] src,
int begin,
int end)
public static <T> T[] concat(T[] a,
T t)
public static <T> T[] concat(T[] a1,
T[] a2)
public static <T> T[] concat(T[] a1,
T[] a2,
T[]... rest)
public static int[] concat(int[] a1,
int[] a2)
public static int[] concat(int[] a1,
int[] a2,
int[]... rest)
public static boolean[] concat(boolean[] a1,
boolean[] a2)
public static boolean[] concat(boolean[] a1,
boolean[] a2,
boolean[]... rest)
public static byte[] concat(byte[] a1,
byte[] a2)
public static byte[] concat(byte[] a1,
byte[] a2,
byte[]... rest)
public static short[] concat(short[] a1,
short[] a2)
public static short[] concat(short[] a1,
short[] a2,
short[]... rest)
public static char[] concat(char[] a1,
char[] a2)
public static char[] concat(char[] a1,
char[] a2,
char[]... rest)
public static long[] concat(long[] a1,
long[] a2)
public static long[] concat(long[] a1,
long[] a2,
long[]... rest)
public static float[] concat(float[] a1,
float[] a2)
public static float[] concat(float[] a1,
float[] a2,
float[]... rest)
public static double[] concat(double[] a1,
double[] a2)
public static double[] concat(double[] a1,
double[] a2,
double[]... rest)
public static void fill(boolean element,
boolean[] array)
public static void fill(byte element,
byte[] array)
public static void fill(char element,
char[] array)
public static void fill(short element,
short[] array)
public static void fill(int element,
int[] array)
public static void fill(float element,
float[] array)
public static void fill(long element,
long[] array)
public static void fill(double element,
double[] array)
public static <T> void fill(T element,
T[] array)
public static boolean[] reverse(boolean[] a)
public static byte[] reverse(byte[] a)
public static char[] reverse(char[] a)
public static short[] reverse(short[] a)
public static int[] reverse(int[] a)
public static float[] reverse(float[] a)
public static long[] reverse(long[] a)
public static double[] reverse(double[] a)
public static boolean[] asPrimitive(Boolean[] oa)
public static Boolean[] asObject(boolean[] pa)
public static byte[] asPrimitive(Byte[] oa)
public static Byte[] asObject(byte[] pa)
public static char[] asPrimitive(Character[] oa)
public static Character[] asObject(char[] pa)
public static short[] asPrimitive(Short[] oa)
public static Short[] asObject(short[] pa)
public static int[] asPrimitive(Integer[] oa)
public static Integer[] asObject(int[] pa)
public static long[] asPrimitive(Long[] oa)
public static Long[] asObject(long[] pa)
public static float[] asPrimitive(Float[] oa)
public static Float[] asObject(float[] pa)
public static double[] asPrimitive(Double[] oa)
public static Double[] asObject(double[] pa)
public static <T extends Enum> T random(Class<T> enumType)
Pickup a random enum value from the enum type.
T - the type parameterenumType - the enum type@SafeVarargs public static <T> T random(T t1, T... ta)
Returns a random element picked from t1 and elements in ta.
T - type parametert1 - the first elementta - the rest elementspublic static <T> T secureRandom(T t1,
T... ta)
The secure version of random(Object, Object[]).
public static int random(int[] a)
public static long random(long[] a)
public static boolean random(boolean[] a)
public static float random(float[] a)
public static double random(double[] a)
public static short random(short[] a)
public static byte random(byte[] a)
public static char random(char[] a)
public static <T> T random(T[] ta)
Returns a random element picked from elements in ta.
T - type parameterta - the elementspublic static <T> T secureRandom(T[] ta)
The secure version of random(Object[]).
public static <T> T random(List<T> list)
Returns a random element picked from elements in a list.
T - type parameterlist - the element listpublic static <T> List<T> randomSubList(List<T> list)
Create a list contains random selected elements in the list specified.
T - the type parameterlist - the listlistpublic static <T> List<T> randomSubList(List<T> list, int minSize)
Create a list contains random selected elements in the list specified.
T - the type parameterlist - the listminSize - the minimum number of elements in the result listlistpublic static <T> T secureRandom(List<T> list)
The secure version of random(List).
public static <T> T random(C.Range<T> range)
Returns a random element picked from elements in a range.
T - type parameterrange - the rangepublic static <T> T secureRandom(C.Range<T> range)
The secure version of random(C.Range).
public static String randomStr()
Alias of S.random()
public static String randomStr(int len)
Alias of S.random(int)
public static <T> T NPE(T o)
public static Class<?> commonSuperTypeOf(Collection<?> objects)
public static <T> Future<T> async(Lang.F0<T> callback, int milliseconds)
Execute callback asynchronously after delay specified
T - return typecallback - the callback function to be executedmilliseconds - the delaypublic static <T> ContextLocal<T> contextLocal()
public static <T> ContextLocal<T> contextLocal(ContextLocal.InitialValueProvider<T> ivp)
public static Map<String,Object> evaluate(Annotation anno)
Evaluate Annotation properties
anno - the annotation instancepublic static Lang._MappingStage clone(Object source)
Prepare a DataMapper.Semantic.DEEP_COPY from source to an new instance with the same time of source
source - the source objectLang._MappingStage that are ready to do deep copy to new instance of source typepublic static <T> T cloneOf(T source)
Returns clone of a given source object.
This is done by doing a DataMapper.Semantic.DEEP_COPY from source object to an new instance of source type
T - the type parameter of the object classsource - the object to be clonesourcepublic static boolean[] cloneOf(boolean[] array)
public static short[] cloneOf(short[] array)
public static byte[] cloneOf(byte[] array)
public static char[] cloneOf(char[] array)
public static int[] cloneOf(int[] array)
public static float[] cloneOf(float[] array)
public static long[] cloneOf(long[] array)
public static double[] cloneOf(double[] array)
public static <T> T cloneOf(T source,
Lang.Function<Class,?> instanceFactory)
Returns clone of a given source object.
This is done by doing a DataMapper.Semantic.DEEP_COPY from source object to an new instance of source type
T - the type parameter of the object classsource - the object to be cloneinstanceFactory - A function that is used to create new instance of the clonesourcepublic static Lang._MappingStage copy(Object source)
Prepare a Mapping operation with shallow copy semantic
source - the source objectLang._MappingStagepublic static Lang._MappingStage deepCopy(Object source)
Prepare a Mapping operation with deep copy semantic
source - the source objectLang._MappingStagepublic static Lang._MappingStage flatCopy(Object source)
Prepare a Mapping operation with flat
copy semantic
source - the source objectLang._MappingStagepublic static Lang._MappingStage merge(Object source)
Prepare a Mapping operation with merge semantic
source - the source objectLang._MappingStagepublic static Lang._MappingStage map(Object source)
Prepare a Mapping operation with map semantic and keyword matching
source - the source objectLang._MappingStagepublic static Lang._MappingStage mergeMap(Object source)
Prepare a Mapping operation with merge map semantic and keyword matching
source - the source objectLang._MappingStagepublic static void sleep(long ms)
A convenient shortcut for Thread.sleep(long). It throws an RuntimeException version of InterruptedException when current thread is interrupted: UnexpectedInterruptedException
ms - the milliseconds to sleep the current threadpublic static void init()
Copyright © 2014–2021 OSGL (Open Source General Library). All rights reserved.