java.lang.Object
com.blackbuild.klum.ast.runtime.internal.layer3.ClusterModel

public class ClusterModel extends Object
Helper class that can be used for (not only) cluster models. A cluster model provides access to
  • 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 returned
      fieldType - The type of properties to be returned
      filter - 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

      public static <T> Map<String,T> getPropertiesOfType(Object container, Class<T> fieldType)
      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 returned
      fieldType - 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 returned
      fieldType - The type of properties to be returned
      filter - 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 returned
      fieldType - The type of properties to be returned
      filter - 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 returned
      fieldType - The type of properties to be returned
      filter - 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 returned
      fieldType - The type of properties to be returned
      filter - 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

      public static <T> Map<String,T> 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.
      Parameters:
      container - The object whose fields should be returned
      fieldType - 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 returned
      fieldType - The type of properties to be returned
      filter - 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 search
      fieldType - The element type to look for
      filter - 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 search
      fieldType - The element type to look for
      filter - 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 search
      fieldType - 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 search
      fieldType - The element type to look for
      filter - 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 returned
      fieldType - 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 returned
      fieldType - 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 returned
      fieldType - The type of properties to be returned
      Returns:
      A list of PropertyValue objects representing all properties of the given type
    • getField

      public static Optional<Field> getField(Object container, String fieldName)
      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

      public static Optional<Field> getField(Class<?> containerType, String fieldName)
      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

      public static boolean hasField(Class<?> containerType, String fieldName)
      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

      public static <T> T getSingleValueOrFail(Object container, Class<T> type, groovy.lang.Closure<Boolean> filter)
    • 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

      public static <T> T getSingleValueOrFail(Object container, Class<T> type)
    • getSinglePropertyOrFail

      public static groovy.lang.PropertyValue getSinglePropertyOrFail(Object container, Class<?> type, groovy.lang.Closure<Boolean> filter)
    • getSinglePropertyOrFail

      public static groovy.lang.PropertyValue getSinglePropertyOrFail(Object container, Class<?> type, Class<? extends Annotation> filter)
    • getSinglePropertyOrFail

      public static groovy.lang.PropertyValue getSinglePropertyOrFail(Object container, Class<?> type)
    • getSinglePropertyOrFail

      public static groovy.lang.PropertyValue getSinglePropertyOrFail(Object container, Class<?> type, Predicate<AnnotatedElement> filter)
    • getFieldOfType

      public static <T> T getFieldOfType(Object container, Class<T> type, String name)
    • getAnnotatedValues

      public static Map<String,Object> getAnnotatedValues(Object object, Class<? extends Annotation> annotation)
    • getFieldsAnnotatedWith

      public static Map<String,Object> getFieldsAnnotatedWith(Object object, Class<? extends Annotation> annotation)
    • 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 executed
      annotation - 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 executed
      annotation - The annotation to look for
      returnType - only methods with this return type will be executed
      Returns:
      A map of method names and their return values