Class CompileUtil
- java.lang.Object
-
- net.officefloor.compile.impl.util.CompileUtil
-
public class CompileUtil extends java.lang.ObjectUtility methods to aid in compiling.- Author:
- Daniel Sagenschneider
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisBlank(java.lang.String value)Indicates whether the inputStringis eithernullor empty.static <T> TloadType(java.lang.Class<T> type, java.lang.String sourceClassName, CompilerIssues issues, java.util.function.Supplier<T> supplier)Convenience method to load a type.static <N,T>
T[]loadTypes(java.util.Map<java.lang.String,N> nodesMap, java.util.function.Function<N,java.lang.String> sortKeyExtractor, java.util.function.Function<N,T> typeLoader, java.util.function.IntFunction<T[]> arrayGenerator)Convenience method to load a listing of types.static <N,T>
T[]loadTypes(java.util.stream.Stream<N> nodes, java.util.function.Function<N,java.lang.String> sortKeyExtractor, java.util.function.Function<N,T> typeLoader, java.util.function.IntFunction<T[]> arrayGenerator)Convenience method to load a listing of types.static <T,E>
TnewInstance(java.lang.Class<T> clazz, java.lang.Class<E> expectedType, Node node, CompilerIssues issues)Instantiates a new instance of the inputClassby its default constructor.static <T,E>
TnewInstance(java.lang.Class<T> clazz, java.lang.Class<E> expectedType, SourceIssues issues)Instantiates a new instance of the inputClassby its default constructor.static <T> TnewInstance(java.lang.String className, java.lang.Class<T> expectedType, java.util.Map<java.lang.String,java.lang.Class<?>> aliases, SourceContext context, Node node, CompilerIssues issues)Convenience method to instantiate and instance of aClassfrom its fully qualified name.static <T> java.lang.Class<? extends T>obtainClass(java.lang.String className, java.lang.Class<T> expectedType, java.util.Map<java.lang.String,java.lang.Class<?>> aliases, SourceContext context, Node node, CompilerIssues issues)Obtains theClass.static intsortCompare(java.lang.String a, java.lang.String b)Convenience method to compare two strings for sorting.static <N> booleansource(java.util.Map<java.lang.String,N> nodesMap, java.util.function.Function<N,java.lang.String> sortKeyExtractor, java.util.function.Predicate<N> sourcer)Convenience method to source a listing of subNodeinstances.
-
-
-
Method Detail
-
isBlank
public static boolean isBlank(java.lang.String value)
Indicates whether the inputStringis eithernullor empty.- Parameters:
value- Value to check.- Returns:
trueif blank.
-
sortCompare
public static int sortCompare(java.lang.String a, java.lang.String b)Convenience method to compare two strings for sorting.- Parameters:
a- First string.b- Second string.- Returns:
- Compare result for sorting.
-
obtainClass
public static <T> java.lang.Class<? extends T> obtainClass(java.lang.String className, java.lang.Class<T> expectedType, java.util.Map<java.lang.String,java.lang.Class<?>> aliases, SourceContext context, Node node, CompilerIssues issues)Obtains theClass.- Type Parameters:
T- Expected type.- Parameters:
className- Fully qualified name of theClassto obtain.expectedType- Expected type of theClassto return.aliases- Map of alias name toClass. May benull.context-SourceContext.node-Node.issues-CompilerIssues.- Returns:
Class.
-
newInstance
public static <T,E> T newInstance(java.lang.Class<T> clazz, java.lang.Class<E> expectedType, Node node, CompilerIssues issues)Instantiates a new instance of the inputClassby its default constructor. If fails to instantiate, then reports issue viaCompilerIssues.- Type Parameters:
T- Type of instance.E- Expected type.- Parameters:
clazz-Classto instantiate.expectedType- Expected type that is to be instantiated.node-Node.issues-CompilerIssues.- Returns:
- New instance or
nullif not able to instantiate.
-
newInstance
public static <T,E> T newInstance(java.lang.Class<T> clazz, java.lang.Class<E> expectedType, SourceIssues issues)Instantiates a new instance of the inputClassby its default constructor. If fails to instantiate, then reports issue viaSourceIssues.- Type Parameters:
T- Type of instance.E- Expected type.- Parameters:
clazz-Classto instantiate.expectedType- Expected type that is to be instantiated.issues-SourceIssues.- Returns:
- New instance or
nullif not able to instantiate.
-
newInstance
public static <T> T newInstance(java.lang.String className, java.lang.Class<T> expectedType, java.util.Map<java.lang.String,java.lang.Class<?>> aliases, SourceContext context, Node node, CompilerIssues issues)Convenience method to instantiate and instance of aClassfrom its fully qualified name.- Type Parameters:
T- Expected type.- Parameters:
className- Fully qualified name of theClass.expectedType- Expected type thatClassinstance must be assignable.aliases- Map of alias name toClass. May benull.context-SourceContext.node-Node.issues-CompilerIssues.- Returns:
- New instance or
nullif not able to instantiate.
-
loadType
public static <T> T loadType(java.lang.Class<T> type, java.lang.String sourceClassName, CompilerIssues issues, java.util.function.Supplier<T> supplier) throws LoadTypeErrorConvenience method to load a type.- Type Parameters:
T- Type to be loaded.- Parameters:
type- Type to be loaded.sourceClassName- SourceClassname for the type.issues-CompilerIssues.supplier-Supplierof the type.- Returns:
- Type.
- Throws:
LoadTypeError- If fails to load the type.
-
loadTypes
public static <N,T> T[] loadTypes(java.util.Map<java.lang.String,N> nodesMap, java.util.function.Function<N,java.lang.String> sortKeyExtractor, java.util.function.Function<N,T> typeLoader, java.util.function.IntFunction<T[]> arrayGenerator)Convenience method to load a listing of types.- Type Parameters:
N-Nodetype within the listing.T- Type returned from theNodeinstances within the listing.- Parameters:
nodesMap-MapofNodeinstances by their names to load types from.sortKeyExtractor-Functionto extract the sort key (to enable deterministic order of loading the types).typeLoader-Functionto load the type from theNode.arrayGenerator-Functionto generate the array of types.- Returns:
- Array of types or
nullwith issues reported to theCompilerIssues.
-
loadTypes
public static <N,T> T[] loadTypes(java.util.stream.Stream<N> nodes, java.util.function.Function<N,java.lang.String> sortKeyExtractor, java.util.function.Function<N,T> typeLoader, java.util.function.IntFunction<T[]> arrayGenerator)Convenience method to load a listing of types.- Type Parameters:
N-Nodetype within the listing.T- Type returned from theNodeinstances within the listing.- Parameters:
nodes-StreamofNodeinstances to load types from.sortKeyExtractor-Functionto extract the sort key (to enable deterministic order of loading the types).typeLoader-Functionto load the type from theNode.arrayGenerator-Functionto generate the array of types.- Returns:
- Array of types or
nullwith issues reported to theCompilerIssues.
-
source
public static <N> boolean source(java.util.Map<java.lang.String,N> nodesMap, java.util.function.Function<N,java.lang.String> sortKeyExtractor, java.util.function.Predicate<N> sourcer)Convenience method to source a listing of subNodeinstances.- Type Parameters:
N-Nodetype.- Parameters:
nodesMap-MapofNodeinstances by their names to source.sortKeyExtractor-Functionto extract the sort key (to enable deterministic order of sourcing the subNodeinstances).sourcer-Predicateto source the subNode.- Returns:
trueif all subNodeinstances sourced. Otherwise,falsewith issue reported to theCompilerIssues.
-
-