Class ClusterModel
java.lang.Object
com.blackbuild.klum.ast.runtime.internal.layer3.ClusterModel
Helper class that can be used for (not only) cluster models. A cluster model provides access to
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<groovy.lang.PropertyValue>getAllPropertiesOfType(Object container, Class<?> fieldType) Returns a list of all fields of the given container with the given type.static @NotNull Stream<groovy.lang.PropertyValue>getAllPropertiesStream(Object container) Returns a stream of all properties of the given container.getAnnotatedValues(Object object, Class<? extends Annotation> annotation) static <T> Map<String,Collection<T>> getCollectionsOfType(Object container, Class<T> fieldType) Returns a Map of all collection fields with the given element type.static <T> Map<String,Collection<T>> getCollectionsOfType(Object container, Class<T> fieldType, groovy.lang.Closure<Boolean> filter) Returns a Map of all collection fields with the given element type, using the given filterstatic <T> Map<String,Collection<T>> getCollectionsOfType(Object container, Class<T> fieldType, Class<? extends Annotation> filter) Returns a Map of all collection fields with the given element type, with the given annotation.static <T> Map<String,Collection<T>> getCollectionsOfType(Object container, Class<T> fieldType, Predicate<AnnotatedElement> filter) Returns a Map of all collection fields with the given element type, using the given filterRetrieves a field from the given class by its name, searching through the class hierarchy.Retrieves a field from the given container object by its name.static <T> TgetFieldOfType(Object container, Class<T> type, String name) getFieldsAnnotatedWith(Object object, Class<? extends Annotation> annotation) getMethodBasedValues(Object object, Class<? extends Annotation> annotation) Executes all parameterless, non-void methods with the given annotation and returns the result.getMethodBasedValues(Object object, Class<? extends Annotation> annotation, Class<?> returnType) Executes all parameterless, non-void methods with the given annotation and returns the result.getNonEmptyPropertiesOfType(Object container, Class<T> fieldType) Returns a map of all fields of the given container with the given type, only including fields that are not null.getNonEmptyPropertiesOfType(Object container, Class<T> fieldType, groovy.lang.Closure<Boolean> filter) Returns a map of all fields of the given container with the given type, using the given filter, only including fields that are not null.getNonEmptyPropertiesOfType(Object container, Class<T> fieldType, Class<? extends Annotation> filter) Returns a map of all fields of the given container with the given type, and the given annotation, only including fields that are not null.getNonEmptyPropertiesOfType(Object container, Class<T> fieldType, Predicate<AnnotatedElement> filter) Returns a map of all fields of the given container with the given type, using the given filter, only including fields that are not null.getPropertiesOfType(Object container, Class<T> fieldType) Returns a map of all fields of the given container with the given type This includes null values.getPropertiesOfType(Object container, Class<T> fieldType, groovy.lang.Closure<Boolean> filter) Returns a map of all fields of the given container with the given type, using the given filter.getPropertiesOfType(Object container, Class<T> fieldType, Class<? extends Annotation> filter) Returns a map of all fields of the given container with the given type, and the given annotation.getPropertiesOfType(Object container, Class<T> fieldType, Predicate<AnnotatedElement> filter) Returns a map of all fields of the given container with the given type, using the given filter.static List<groovy.lang.PropertyValue>getSetPropertiesOfType(Object container, Class<?> fieldType) Returns a list of all fields of the given container with the given type, only including fields that are set (not null).static groovy.lang.PropertyValuegetSinglePropertyOrFail(Object container, Class<?> type) static groovy.lang.PropertyValuegetSinglePropertyOrFail(Object container, Class<?> type, groovy.lang.Closure<Boolean> filter) static groovy.lang.PropertyValuegetSinglePropertyOrFail(Object container, Class<?> type, Class<? extends Annotation> filter) static groovy.lang.PropertyValuegetSinglePropertyOrFail(Object container, Class<?> type, Predicate<AnnotatedElement> filter) static <T> TgetSingleValueOrFail(Object container, Class<T> type) static <T> TgetSingleValueOrFail(Object container, Class<T> type, groovy.lang.Closure<Boolean> filter) static <T> TgetSingleValueOrFail(Object container, Class<T> type, Class<? extends Annotation> filter) static <T> TgetSingleValueOrFail(Object container, Class<T> type, Predicate<AnnotatedElement> filter) static List<groovy.lang.PropertyValue>getUnsetPropertiesOfType(Object container, Class<?> fieldType) Returns a list of all fields of the given container with the given type, only including fields that are unset (null).static booleanChecks if the given class contains a field with the specified name.
-
Method Details
-
getPropertiesOfType
public static <T> Map<String,T> getPropertiesOfType(Object container, Class<T> fieldType, groovy.lang.Closure<Boolean> filter) Returns a map of all fields of the given container with the given type, using the given filter. This includes null values.- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returnedfilter- Filter closure on the AnnotatedElement (Method or Field)- Returns:
- A Map of property names to property values containing all properties of the given type.
-
getPropertiesOfType
Returns a map of all fields of the given container with the given type This includes null values.- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returned- Returns:
- A Map of property names to property values containing all properties of the given type.
-
getPropertiesOfType
public static <T> Map<String,T> getPropertiesOfType(Object container, Class<T> fieldType, Class<? extends Annotation> filter) Returns a map of all fields of the given container with the given type, and the given annotation. This includes null values.- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returnedfilter- Annotation type that must be present on the field- Returns:
- A Map of property names to property values containing all properties of the given type.
-
getPropertiesOfType
public static <T> Map<String,T> getPropertiesOfType(Object container, Class<T> fieldType, Predicate<AnnotatedElement> filter) Returns a map of all fields of the given container with the given type, using the given filter. This includes null values.- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returnedfilter- Filter closure on the AnnotatedElement (Method or Field)- Returns:
- A Map of property names to property values containing all properties of the given type.
-
getNonEmptyPropertiesOfType
public static <T> Map<String,T> getNonEmptyPropertiesOfType(Object container, Class<T> fieldType, groovy.lang.Closure<Boolean> filter) Returns a map of all fields of the given container with the given type, using the given filter, only including fields that are not null.- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returnedfilter- Filter closure on the AnnotatedElement (Method or Field)- Returns:
- A Map of property names to property values containing all properties of the given type.
-
getNonEmptyPropertiesOfType
public static <T> Map<String,T> getNonEmptyPropertiesOfType(Object container, Class<T> fieldType, Class<? extends Annotation> filter) Returns a map of all fields of the given container with the given type, and the given annotation, only including fields that are not null.- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returnedfilter- Annotation type that must be present on the field- Returns:
- A Map of property names to property values containing all properties of the given type.
-
getNonEmptyPropertiesOfType
Returns a map of all fields of the given container with the given type, only including fields that are not null.- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returned- Returns:
- A Map of property names to property values containing all properties of the given type.
-
getNonEmptyPropertiesOfType
public static <T> Map<String,T> getNonEmptyPropertiesOfType(Object container, Class<T> fieldType, Predicate<AnnotatedElement> filter) Returns a map of all fields of the given container with the given type, using the given filter, only including fields that are not null.- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returnedfilter- Filter closure on the AnnotatedElement (Method or Field)- Returns:
- A Map of property names to property values containing all properties of the given type.
-
getCollectionsOfType
public static <T> Map<String,Collection<T>> getCollectionsOfType(Object container, Class<T> fieldType, groovy.lang.Closure<Boolean> filter) Returns a Map of all collection fields with the given element type, using the given filter- Parameters:
container- The object to searchfieldType- The element type to look forfilter- Filter closure on the AnnotatedElement (Method or Field)- Returns:
- A Map of property names to collections of values.
-
getCollectionsOfType
public static <T> Map<String,Collection<T>> getCollectionsOfType(Object container, Class<T> fieldType, Class<? extends Annotation> filter) Returns a Map of all collection fields with the given element type, with the given annotation.- Parameters:
container- The object to searchfieldType- The element type to look forfilter- Annotation type that must be present on the field- Returns:
- A Map of property names to collections of values.
-
getCollectionsOfType
public static <T> Map<String,Collection<T>> getCollectionsOfType(Object container, Class<T> fieldType) Returns a Map of all collection fields with the given element type.- Parameters:
container- The object to searchfieldType- The element type to look for- Returns:
- A Map of property names to collections of values.
-
getCollectionsOfType
public static <T> Map<String,Collection<T>> getCollectionsOfType(Object container, Class<T> fieldType, Predicate<AnnotatedElement> filter) Returns a Map of all collection fields with the given element type, using the given filter- Parameters:
container- The object to searchfieldType- The element type to look forfilter- Filter closure on the AnnotatedElement (Method or Field)- Returns:
- A Map of property names to collections of values.
-
getAllPropertiesStream
@NotNull public static @NotNull Stream<groovy.lang.PropertyValue> getAllPropertiesStream(Object container) Returns a stream of all properties of the given container. This includes all properties, regardless of their type.- Parameters:
container- The object whose properties should be returned- Returns:
- A stream of PropertyValue objects representing all properties of the container
-
getUnsetPropertiesOfType
public static List<groovy.lang.PropertyValue> getUnsetPropertiesOfType(Object container, Class<?> fieldType) Returns a list of all fields of the given container with the given type, only including fields that are unset (null).- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returned- Returns:
- A list of PropertyValue objects representing all properties of the given type that are null
-
getSetPropertiesOfType
public static List<groovy.lang.PropertyValue> getSetPropertiesOfType(Object container, Class<?> fieldType) Returns a list of all fields of the given container with the given type, only including fields that are set (not null).- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returned- Returns:
- A list of PropertyValue objects representing all properties of the given type that are not null
-
getAllPropertiesOfType
public static List<groovy.lang.PropertyValue> getAllPropertiesOfType(Object container, Class<?> fieldType) Returns a list of all fields of the given container with the given type. This includes inherited fields.- Parameters:
container- The object whose fields should be returnedfieldType- The type of properties to be returned- Returns:
- A list of PropertyValue objects representing all properties of the given type
-
getField
Retrieves a field from the given container object by its name.- Parameters:
container- The object containing the field.fieldName- The name of the field to retrieve.- Returns:
- An Optional containing the Field if found, otherwise an empty Optional.
-
getField
Retrieves a field from the given class by its name, searching through the class hierarchy.- Parameters:
containerType- The class to search for the field.fieldName- The name of the field to retrieve.- Returns:
- An Optional containing the Field if found, otherwise an empty Optional.
-
hasField
Checks if the given class contains a field with the specified name.- Parameters:
containerType- The class to search for the field.fieldName- The name of the field to check for.- Returns:
- true if the field is present, false otherwise.
-
getSingleValueOrFail
-
getSingleValueOrFail
public static <T> T getSingleValueOrFail(Object container, Class<T> type, Class<? extends Annotation> filter) -
getSingleValueOrFail
public static <T> T getSingleValueOrFail(Object container, Class<T> type, Predicate<AnnotatedElement> filter) -
getSingleValueOrFail
-
getSinglePropertyOrFail
-
getSinglePropertyOrFail
public static groovy.lang.PropertyValue getSinglePropertyOrFail(Object container, Class<?> type, Class<? extends Annotation> filter) -
getSinglePropertyOrFail
-
getSinglePropertyOrFail
public static groovy.lang.PropertyValue getSinglePropertyOrFail(Object container, Class<?> type, Predicate<AnnotatedElement> filter) -
getFieldOfType
-
getAnnotatedValues
-
getFieldsAnnotatedWith
-
getMethodBasedValues
public static Map<String,Object> getMethodBasedValues(Object object, Class<? extends Annotation> annotation) Executes all parameterless, non-void methods with the given annotation and returns the result.- Parameters:
object- The object whose methods should be executedannotation- The annotation to look for- Returns:
- A map of method names and their return values
-
getMethodBasedValues
public static Map<String,Object> getMethodBasedValues(Object object, Class<? extends Annotation> annotation, Class<?> returnType) Executes all parameterless, non-void methods with the given annotation and returns the result.- Parameters:
object- The object whose methods should be executedannotation- The annotation to look forreturnType- only methods with this return type will be executed- Returns:
- A map of method names and their return values
-