Brooklyn

brooklyn.util.flags
[Java] Class FlagUtils

java.lang.Object
  brooklyn.util.flags.FlagUtils

public class FlagUtils

class to help transfer values passed as named arguments to other well-known variables/fields/objects; see the test case for example usage


Field Summary
static Logger log

 
Method Summary
static void checkRequiredFields(java.lang.Object o)

@throws an IllegalStateException if there are fields required (nullable=false) which are unset

static java.lang.reflect.Field findFieldForFlag(java.lang.String flagName, java.lang.Object o)

Finds the java.lang.reflect.Field on the given object annotated with the given name flag.

static java.util.List getAllAssignableTypes(java.lang.Class base)

returns base, superclasses, then interfaces

static java.util.List getAllAssignableTypes(java.lang.Class base, groovy.lang.Closure filter)

static java.util.List getAllAssignableTypes(java.lang.Class base, Predicate filter)

static java.util.List getAllFields(java.lang.Class base, groovy.lang.Closure filter)

returns all fields on the given class, superclasses, and interfaces thereof, in that order of preference, (excluding fields on Object)

static java.util.List getAllFields(java.lang.Class base)

static java.util.List getAllFields(java.lang.Class base, Predicate filter)

static java.util.Map getAnnotatedFields(java.lang.Class type)

returns a map of all fields which are annotated 'SetFromFlag', along with the annotation

static java.lang.Object getDefaultValueForType(java.lang.Class t)

returns the default/inital value that is assigned to fields of the givien type; if the type is not primitive this value is null; for primitive types it is obvious but not AFAIK programmatically visible (e.g. 0 for int, false for boolean)

static java.lang.Object getField(java.lang.Object objectOfField, java.lang.reflect.Field f)

gets the value of the field.

static java.util.Map getFieldsWithFlags(java.lang.Object o)

get all fields (including private and static) on the given object and all supertypes, that are annotated with SetFromFlags.

static java.util.Map getFieldsWithFlagsExcludingModifiers(java.lang.Object o, int excludingModifiers)

get all fields (including private and static) and their values on the given object and all supertypes, where the field is annotated with SetFromFlags.

static java.util.Map getFieldsWithFlagsWithModifiers(java.lang.Object o, int requiredModifiers)

get all fields with the given modifiers, and their values on the given object and all supertypes, where the field is annotated with SetFromFlags.

static java.util.Map getFieldsWithValues(java.lang.Object o)

returns a map of all fields which are annotated 'SetFromFlag' with their current values; useful if you want to clone settings from one object

static java.util.List getLocalFields(java.util.List classes)

returns all fields explicitly declared on the given classes

static java.util.List getLocalFields(java.util.List classes, groovy.lang.Closure filter)

static java.util.List getLocalFields(java.util.List classes, Predicate filter)

static java.util.Map setAllConfigKeys(java.util.Map flagsOrConfig, Configurable instance)

sets _all_ accessible _ConfigKey_ and HasConfigKey fields on the given object, using the indicated flags/config-bag

static void setAllConfigKeys(Configurable o, ConfigBag bag)

sets _all_ accessible _ConfigKey_ and HasConfigKey fields on the given object, using the indicated flags/config-bag

static java.util.Map setConfigKeysFromFlags(java.util.Map flags, Configurable instance)

@deprecated since 0.5.0 use setAllConfigKeys

static void setField(java.lang.Object objectOfField, java.lang.reflect.Field f, java.lang.Object value, SetFromFlag optionalAnnotation)

sets the field to the value, after checking whether the given value can be set respecting the constraints of the annotation

static boolean setFieldFromFlag(java.lang.Object o, java.lang.String flagName, java.lang.Object fieldVal)

Sets the field with the given flag (if it exists) to the given value.

static java.util.Map setFieldsFromFlags(java.util.Map flags, java.lang.Object o)

see setFieldsFromFlags(Object o, ConfigBag)

static void setFieldsFromFlags(java.lang.Object o, ConfigBag configBag)

sets all fields (including private and static, local and inherited) annotated SetFromFlag on the given object, from the given flags map, returning just those flag-value pairs passed in which do not correspond to SetFromFlags fields annotated ConfigKey and HasConfigKey fields are _configured_ (and we assume the object in that case is Configurable); keys should be ConfigKey, HasConfigKey, or String; default values are also applied unless that is specified false on one of the variants of this method which takes such an argument

static void setFieldsFromFlags(java.lang.Object o, ConfigBag configBag, boolean setDefaultVals)

as setFieldsFromFlags(Object o, ConfigBag)

static void setFieldsFromFlagsWithBag(java.lang.Object o, java.util.Map flags, ConfigBag configBag, boolean setDefaultVals)

as setFieldsFromFlags(Object o, ConfigBag), but specifying a subset of flags to use

static java.util.Map setPublicFieldsFromFlags(java.util.Map flags, java.lang.Object o)

see setFieldsFromFlags(Object o, ConfigBag)

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

log

public static final Logger log


 
Method Detail

checkRequiredFields

public static void checkRequiredFields(java.lang.Object o)
throws:
an IllegalStateException if there are fields required (nullable=false) which are unset
throws:
wrapped IllegalAccessException


findFieldForFlag

public static java.lang.reflect.Field findFieldForFlag(java.lang.String flagName, java.lang.Object o)
Finds the java.lang.reflect.Field on the given object annotated with the given name flag.


getAllAssignableTypes

public static java.util.List getAllAssignableTypes(java.lang.Class base)
returns base, superclasses, then interfaces


getAllAssignableTypes

public static java.util.List getAllAssignableTypes(java.lang.Class base, groovy.lang.Closure filter)


getAllAssignableTypes

public static java.util.List getAllAssignableTypes(java.lang.Class base, Predicate filter)


getAllFields

public static java.util.List getAllFields(java.lang.Class base, groovy.lang.Closure filter)
returns all fields on the given class, superclasses, and interfaces thereof, in that order of preference, (excluding fields on Object)


getAllFields

public static java.util.List getAllFields(java.lang.Class base)


getAllFields

public static java.util.List getAllFields(java.lang.Class base, Predicate filter)


getAnnotatedFields

public static java.util.Map getAnnotatedFields(java.lang.Class type)
returns a map of all fields which are annotated 'SetFromFlag', along with the annotation


getDefaultValueForType

public static java.lang.Object getDefaultValueForType(java.lang.Class t)
returns the default/inital value that is assigned to fields of the givien type; if the type is not primitive this value is null; for primitive types it is obvious but not AFAIK programmatically visible (e.g. 0 for int, false for boolean)


getField

public static java.lang.Object getField(java.lang.Object objectOfField, java.lang.reflect.Field f)
gets the value of the field.


getFieldsWithFlags

public static java.util.Map getFieldsWithFlags(java.lang.Object o)
get all fields (including private and static) on the given object and all supertypes, that are annotated with SetFromFlags.


getFieldsWithFlagsExcludingModifiers

public static java.util.Map getFieldsWithFlagsExcludingModifiers(java.lang.Object o, int excludingModifiers)
get all fields (including private and static) and their values on the given object and all supertypes, where the field is annotated with SetFromFlags.


getFieldsWithFlagsWithModifiers

public static java.util.Map getFieldsWithFlagsWithModifiers(java.lang.Object o, int requiredModifiers)
get all fields with the given modifiers, and their values on the given object and all supertypes, where the field is annotated with SetFromFlags.


getFieldsWithValues

public static java.util.Map getFieldsWithValues(java.lang.Object o)
returns a map of all fields which are annotated 'SetFromFlag' with their current values; useful if you want to clone settings from one object


getLocalFields

public static java.util.List getLocalFields(java.util.List classes)
returns all fields explicitly declared on the given classes


getLocalFields

public static java.util.List getLocalFields(java.util.List classes, groovy.lang.Closure filter)


getLocalFields

public static java.util.List getLocalFields(java.util.List classes, Predicate filter)


setAllConfigKeys

public static java.util.Map setAllConfigKeys(java.util.Map flagsOrConfig, Configurable instance)
sets _all_ accessible _ConfigKey_ and HasConfigKey fields on the given object, using the indicated flags/config-bag


setAllConfigKeys

public static void setAllConfigKeys(Configurable o, ConfigBag bag)
sets _all_ accessible _ConfigKey_ and HasConfigKey fields on the given object, using the indicated flags/config-bag


setConfigKeysFromFlags

public static java.util.Map setConfigKeysFromFlags(java.util.Map flags, Configurable instance)
deprecated:
since 0.5.0 use setAllConfigKeys


setField

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void setField(java.lang.Object objectOfField, java.lang.reflect.Field f, java.lang.Object value, SetFromFlag optionalAnnotation)
sets the field to the value, after checking whether the given value can be set respecting the constraints of the annotation


setFieldFromFlag

public static boolean setFieldFromFlag(java.lang.Object o, java.lang.String flagName, java.lang.Object fieldVal)
Sets the field with the given flag (if it exists) to the given value. Will attempt to coerce the value to the required type. Will respect "nullable" on the SetFromFlag annotation.
throws:
IllegalArgumentException If fieldVal is null and the SetFromFlag annotation set nullable=false


setFieldsFromFlags

public static java.util.Map setFieldsFromFlags(java.util.Map flags, java.lang.Object o)
see setFieldsFromFlags(Object o, ConfigBag)


setFieldsFromFlags

public static void setFieldsFromFlags(java.lang.Object o, ConfigBag configBag)
sets all fields (including private and static, local and inherited) annotated SetFromFlag on the given object, from the given flags map, returning just those flag-value pairs passed in which do not correspond to SetFromFlags fields annotated ConfigKey and HasConfigKey fields are _configured_ (and we assume the object in that case is Configurable); keys should be ConfigKey, HasConfigKey, or String; default values are also applied unless that is specified false on one of the variants of this method which takes such an argument


setFieldsFromFlags

public static void setFieldsFromFlags(java.lang.Object o, ConfigBag configBag, boolean setDefaultVals)
as setFieldsFromFlags(Object o, ConfigBag)


setFieldsFromFlagsWithBag

public static void setFieldsFromFlagsWithBag(java.lang.Object o, java.util.Map flags, ConfigBag configBag, boolean setDefaultVals)
as setFieldsFromFlags(Object o, ConfigBag), but specifying a subset of flags to use


setPublicFieldsFromFlags

public static java.util.Map setPublicFieldsFromFlags(java.util.Map flags, java.lang.Object o)
see setFieldsFromFlags(Object o, ConfigBag)


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.