Package org.savantbuild.parser.groovy
Class GroovyTools
java.lang.Object
org.savantbuild.parser.groovy.GroovyTools
Groovy helpers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanattributesValid(Map<String, Object> attributes, Collection<String> possibleAttributes, Collection<String> requiredAttributes, Map<String, Class<?>> types) Ensures that the attributes are valid.static booleanChecks if the given attributes Map has all the given attribute names.static booleanhasAttributes(Map<String, Object> attributes, String... attributeNames) Checks if the given attributes Map has all the given attribute names.static booleanChecks if the given attributes Map has the correct types.static voidPuts all the values from the defaults map into the main map if they are absent.toListOfStrings(Object value) Converts the object to a List of Strings.static StringSafely converts an attribute to a String.
-
Constructor Details
-
GroovyTools
public GroovyTools()
-
-
Method Details
-
attributesValid
public static boolean attributesValid(Map<String, Object> attributes, Collection<String> possibleAttributes, Collection<String> requiredAttributes, Map<String, Class<?>> types) Ensures that the attributes are valid. This checks if the attributes are null and there are no required attributes. If this is the case, it returns true. Otherwise, the attributes must be a Map and must contain the required attributes and have the correct attribute types.- Parameters:
attributes- The attributes object.possibleAttributes- The list of possible attributes. If an attributes is specified that doesn't exist in this Collection, false will be returned.requiredAttributes- A list of required attributes.types- The attribute types.- Returns:
- True if the attributes are valid, false otherwise.
-
hasAttributeTypes
Checks if the given attributes Map has the correct types. This handles the GString case since that is a Groovy special class that is converted to String dynamically.- Parameters:
attributes- The attributes map.types- The types.- Returns:
- True if the map contains the correct types, false otherwise.
-
hasAttributes
Checks if the given attributes Map has all the given attribute names. The values for the attribute names must be non-null.- Parameters:
attributes- The attributes map.attributeNames- The attribute names.- Returns:
- True if the map contains all the attribute names, false otherwise.
-
hasAttributes
Checks if the given attributes Map has all the given attribute names. The values for the attribute names must be non-null and non-empty.- Parameters:
attributes- The attributes map.attributeNames- The attribute names.- Returns:
- True if the map contains all the attribute names, false otherwise.
-
putDefaults
Puts all the values from the defaults map into the main map if they are absent. This is a good way to set up default values.- Parameters:
map- The main map.defaults- The defaults map.
-
toListOfStrings
Converts the object to a List of Strings. If the object is a List, this converts all non-null items to Strings and deletes null values. If it isn't a List, it returns a single element List with the value of object.toString().- Parameters:
value- The value to convert.- Returns:
- The List of Strings.
-
toString
Safely converts an attribute to a String.- Parameters:
attributes- The attributes.key- The key of the attribute to convert.- Returns:
- Null if the object is null, otherwise the result of calling toString.
-