Package com.graphql_java_generator.util
Class GraphqlUtils
java.lang.Object
com.graphql_java_generator.util.GraphqlUtils
- Author:
- etienne-sf
-
Field Summary
Modifier and TypeFieldDescriptionstatic GraphqlUtils
This singleton is usable in default method, within interfacesstatic Character
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal <T> Stream<T>
concatStreams
(Class<T> clazz, boolean parallelStreams, T t1, T t2, T t3, List<? extends T>... lists) Concatenate a non limited number of lists into a stream.getCamelCase
(String name) Convert the given name, to a camel case name.getClassSimpleName
(String classFullNameParam) Extract the simple name for a class (without the package name), from its full class name (with the package name)Retrieves the getter for the given field on the given fieldgetJavaName
(String name) Returns a valid java identifier for the given name.getLastModified
(File fileOrFolder, boolean maxValue) Returns the maximum or minimum value for the lastModified of the given file, or of all the files (not folders) contained into this folder.Retrieves the asked method, from its name, class and parameters.getPackageName
(String classFullNameParam) Extract the package name for a class, from its full class name (with the package name)getPascalCase
(String name) Convert the given name, which is supposed to be in camel case (for instance: thisIsCamelCase) to a pascal case string (for instance: ThisIsCamelCase).getQuotedScanBasePackages
(String scanBasePackages) Returns the version of the runtime, that is used to check that the runtime's version is the same as the Maven or Gradle plugin's version.<T> Method
Retrieves the setter for the given field on the given fieldgetValueAsString
(graphql.language.Value<?> value) Returns the given value, as string, as it can be written into theGraphQLDirective.parameterValues()
of theGraphQLDirective
java annotation.
A str string default value will be returned as "str",a JEDI enum value will be returned as "JEDI", an object will be returned as "{name:\"specific name\",appearsIn:[NEWHOPE,EMPIRE],type:\"Human\"}"...getValueAsText
(graphql.language.Value<?> value) Returns the given value, as text, as it can be written into a generated GraphQL schema.
A str string default value will be returned as "str",a JEDI enum value will be returned as JEDI, ...invokeGetter
(Object object, String fieldName) Invoke the getter for the given field name, on the given object.invokeMethod
(Method method, Object o, Object... args) Invoke the given setter on the given object, with the given value.invokeMethod
(String methodName, Object object, Object... args) Calls the 'methodName' method on the given object.void
invokeSetter
(Object object, Field field, Object value) Invoke the setter for the given field, on the given object.void
invokeSetter
(Object object, String fieldName, Object value) Invoke the setter for theField
of the given name, on the given object.invokeStaticMethod
(String methodName, Class<?> clazz) Calls the 'methodName' method on the given class.boolean
isJavaReservedWords
(String name) Returns true if name is a reserved java keyword<I> List<I>
iterableConcreteClassToListInterface
(Iterable<? extends I> iterable) <I> List<I>
iterableToList
(Iterable<I> iterable) <T> T
optionalToObject
(Optional<T> optional) Transform anOptional
, as returned by Spring Data repositories, into a standard Java, which is null if there is no value.<T> List<T>
Reads a non ordered list, and return the same content sorted according the keys list.stringToEnumValue
(Object enumValue, Class<?> enumClass) Returns the given enumValue given as a String, into the enum value from the generated POJO of the given class.
This can not be a parameterized method as the return value may be either an enum, a list of enums...
-
Field Details
-
graphqlUtils
This singleton is usable in default method, within interfaces -
JAVA_KEYWORD_PREFIX
-
-
Constructor Details
-
GraphqlUtils
public GraphqlUtils()
-
-
Method Details
-
getRuntimeVersion
Returns the version of the runtime, that is used to check that the runtime's version is the same as the Maven or Gradle plugin's version. -
getCamelCase
Convert the given name, to a camel case name. Currently very simple : it puts the first character in lower case.- Returns:
-
getPascalCase
Convert the given name, which is supposed to be in camel case (for instance: thisIsCamelCase) to a pascal case string (for instance: ThisIsCamelCase).- Returns:
-
iterableToList
Transform anIterable
(which can be aList
), into aList
of items of the same type. It's usefull to transform the native type from Spring Data repositories (which needs concrete class to map into) into the list of relevant GraphQL interface- Type Parameters:
I
-- Parameters:
iterable
-- Returns:
-
iterableConcreteClassToListInterface
Transform anIterable
(which can be aList
) of a concrete class, into aList
of the I interface or superclass. It's usefull to transform the native type from Spring Data repositories (which needs concrete class to map into) into the list of relevant GraphQL interface- Type Parameters:
I
-- Parameters:
iterable
-- Returns:
-
optionalToObject
Transform anOptional
, as returned by Spring Data repositories, into a standard Java, which is null if there is no value.- Parameters:
optional
-- Returns:
-
orderList
Reads a non ordered list, and return the same content sorted according the keys list. This method is used for batch loader method: they must return their result in the exact same order as the provided keys, so that the returned values are properly dispatched in the server's response.- Type Parameters:
T
- The type of items in these list- Parameters:
keys
- The list which ordered must be respected.unorderedList
- A list of items in any order. Each item in this list must have a key which is in the keys list.
There may be missing values (for instance if a key doesn't match an item in the database). In this case, this value is replaced by a null value.keyFieldName
- The name of the field, that contain the key, that is: the T's attribute the can be matched against the keys list. For instance: "id"- Returns:
- A list of T instances coming from the unorderedList, where the key (retrieved by the getter method) of these instances is in the exact same order as the keys list. Missing values in the unorderedList list are replaced by null.
-
getSetter
Retrieves the setter for the given field on the given field- Type Parameters:
T
-- Parameters:
t
-field
-- Returns:
-
getGetter
Retrieves the getter for the given field on the given field- Type Parameters:
T
-- Parameters:
t
-field
-- Returns:
-
invokeGetter
Invoke the getter for the given field name, on the given object. All check exceptions are hidden in aRuntimeException
- Parameters:
object
-fieldName
-- Returns:
- the field's value for the given object
- Throws:
RuntimeException
- If any exception occurs
-
invokeSetter
Invoke the setter for the given field, on the given object. All check exceptions are hidden in aRuntimeException
- Parameters:
object
-field
-value
-- Throws:
RuntimeException
- If any exception occurs
-
invokeSetter
Invoke the setter for theField
of the given name, on the given object. All check exceptions are hidden in aRuntimeException
- Parameters:
object
-fieldName
-value
-- Throws:
RuntimeException
- If any exception occurs
-
getMethod
Retrieves the asked method, from its name, class and parameters. This method hides the exception that could be thrown, into aRuntimeException
- Type Parameters:
T
-- Parameters:
t
-field
-- Returns:
- Throws:
RuntimeException
- When an exception occurs while getting the method
-
invokeMethod
Calls the 'methodName' method on the given object.- Parameters:
methodName
- The name of the method. This method should have no parameterobject
- The given object, on which the 'methodName' method is to be called- Returns:
-
invokeMethod
Invoke the given setter on the given object, with the given value. This method hides the exception that could be thrown, into aRuntimeException
- Parameters:
method
-o
-value
-- Throws:
RuntimeException
- When an exception occurs while accessing the setter
-
invokeStaticMethod
Calls the 'methodName' method on the given class.- Parameters:
methodName
- The name of the method. This method should have no parameterclazz
- The given class, on which the 'methodName' method is to be called- Returns:
-
getJavaName
Returns a valid java identifier for the given name.- Parameters:
name
-- Returns:
- If name is a default java keyword (so it is not a valid java identifier), then the return prefixed by a
JAVA_KEYWORD_PREFIX
. Otherwise (which is generally the case), the name is valid, and returned as is the given name
-
isJavaReservedWords
Returns true if name is a reserved java keyword- Parameters:
name
-- Returns:
-
getClassSimpleName
Extract the simple name for a class (without the package name), from its full class name (with the package name)- Parameters:
classFullName
- The full class name, for instance java.util.Date- Returns:
- The simple class name (in the above sample: Date)
-
getPackageName
Extract the package name for a class, from its full class name (with the package name)- Parameters:
classFullName
- The full class name, for instance java.util.Date- Returns:
- The simple class name (in the above sample: java.util)
-
concatStreams
@SafeVarargs public final <T> Stream<T> concatStreams(Class<T> clazz, boolean parallelStreams, T t1, T t2, T t3, List<? extends T>... lists) Concatenate a non limited number of lists into a stream.- Type Parameters:
T
-- Parameters:
clazz
- The T classparallelStreams
- true if the returned stream should be a parallel onet1
- An optional item, that'll be added to the returned stream (if not null)t2
- An optional item, that'll be added to the returned stream (if not null)t3
- An optional item, that'll be added to the returned stream (if not null)lists
-- Returns:
-
getValueAsText
Returns the given value, as text, as it can be written into a generated GraphQL schema.
A str string default value will be returned as "str",a JEDI enum value will be returned as JEDI, ...- Returns:
-
getValueAsString
Returns the given value, as string, as it can be written into theGraphQLDirective.parameterValues()
of theGraphQLDirective
java annotation.
A str string default value will be returned as "str",a JEDI enum value will be returned as "JEDI", an object will be returned as "{name:\"specific name\",appearsIn:[NEWHOPE,EMPIRE],type:\"Human\"}"...- Returns:
-
stringToEnumValue
Returns the given enumValue given as a String, into the enum value from the generated POJO of the given class.
This can not be a parameterized method as the return value may be either an enum, a list of enums...- Parameters:
enumValue
- May be null, a String, a list of String, a list of lists of String...enumClass
- The POJO class of the enum- Returns:
- The same kind of list, but all String representations are replaced by the relevant enum value, based on the GraphQL schema.
-
getLastModified
Returns the maximum or minimum value for the lastModified of the given file, or of all the files (not folders) contained into this folder.- Parameters:
fileOrFolder
- A file or a foldermaxValue
- If true and fileOrFolder is a folder, then this method returns the maximumFile.lastModified()
found for all its files. If false, then the minimum value is returned.- Returns:
- if fileOrFolder doesn't exist, then returns null. If fileOrFolder is a file, then returns its
File.lastModified()
value. Otherwise its a folder. Then it loops into this folder, its subfolders (and so on), and returns the maximum or the minimum (depending on the value of maxValue) lastModified date found for the files found. The date of the directories are ignored.
-
getQuotedScanBasePackages
-