public class FlagUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
FlagUtils.FlagConfigKeyAndValueRecord |
Modifier and Type | Field and Description |
---|---|
static org.slf4j.Logger |
log |
Modifier and Type | Method and Description |
---|---|
static void |
checkRequiredFields(java.lang.Object o) |
static <T> java.util.List<FlagUtils.FlagConfigKeyAndValueRecord> |
findAllFlagsAndConfigKeys(T optionalInstance,
java.lang.Class<? extends T> type,
ConfigBag input)
gets all the flags/keys in the given config bag which are applicable to the given type's config keys and flags
|
static java.lang.reflect.Field |
findFieldForFlag(java.lang.String flagName,
java.lang.Object o)
Finds the
Field on the given object annotated with the given name flag. |
static java.util.List<java.lang.Class<?>> |
getAllAssignableTypes(java.lang.Class<?> base)
returns base, superclasses, then interfaces
|
static java.util.List<java.lang.Class<?>> |
getAllAssignableTypes(java.lang.Class<?> base,
groovy.lang.Closure<java.lang.Boolean> filter) |
static java.util.List<java.lang.Class<?>> |
getAllAssignableTypes(java.lang.Class<?> base,
com.google.common.base.Predicate<java.lang.Class<?>> filter) |
static java.util.List<java.lang.reflect.Field> |
getAllFields(java.lang.Class<?> base) |
static java.util.List<java.lang.reflect.Field> |
getAllFields(java.lang.Class<?> base,
groovy.lang.Closure<java.lang.Boolean> 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<java.lang.reflect.Field> |
getAllFields(java.lang.Class<?> base,
com.google.common.base.Predicate<java.lang.reflect.Field> filter) |
static java.util.Map<ConfigKey<?>,SetFromFlag> |
getAnnotatedConfigKeys(java.lang.Class<?> type)
returns a map of all
ConfigKey fields which are annotated 'SetFromFlag', along with the annotation |
static java.util.Map<java.lang.reflect.Field,SetFromFlag> |
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.
|
static java.lang.Object |
getField(java.lang.Object objectOfField,
java.lang.reflect.Field f)
gets the value of the field.
|
static java.util.Map<java.lang.String,?> |
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<java.lang.String,java.lang.Object> |
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<java.lang.String,java.lang.Object> |
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<java.lang.String,java.lang.Object> |
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<java.lang.reflect.Field> |
getLocalFields(java.util.List<java.lang.Class<?>> classes)
returns all fields explicitly declared on the given classes
|
static java.util.List<java.lang.reflect.Field> |
getLocalFields(java.util.List<java.lang.Class<?>> classes,
groovy.lang.Closure<java.lang.Boolean> filter) |
static java.util.List<java.lang.reflect.Field> |
getLocalFields(java.util.List<java.lang.Class<?>> classes,
com.google.common.base.Predicate<java.lang.reflect.Field> filter) |
static void |
setAllConfigKeys(Configurable o,
ConfigBag bag)
Deprecated.
since 0.7.0 use
setAllConfigKeys(Configurable, ConfigBag, boolean) |
static void |
setAllConfigKeys(Configurable o,
ConfigBag bag,
boolean includeFlags)
sets _all_ accessible _
ConfigKey _ and ConfigKey.HasConfigKey fields on the given object,
using the indicated flags/config-bag |
static java.util.Map<java.lang.String,?> |
setAllConfigKeys(java.util.Map<java.lang.String,?> flagsOrConfig,
Configurable instance)
Deprecated.
since 0.7.0 use
setAllConfigKeys(Map, Configurable, boolean) |
static java.util.Map<java.lang.String,?> |
setAllConfigKeys(java.util.Map<java.lang.String,?> flagsOrConfig,
Configurable instance,
boolean includeFlags)
sets _all_ accessible _
ConfigKey _ and ConfigKey.HasConfigKey fields on the given object,
using the indicated flags/config-bag |
static void |
setConfig(java.lang.Object objectOfField,
ConfigKey<?> key,
java.lang.Object value,
SetFromFlag optionalAnnotation) |
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)
|
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, ConfigBag) , but allowing control over whether default values should be set |
static void |
setFieldsFromFlagsWithBag(java.lang.Object o,
java.util.Map<?,?> flags,
ConfigBag configBag,
boolean setDefaultVals)
as
setFieldsFromFlags(Object, ConfigBag) , but specifying a subset of flags to use |
static java.util.Map<?,?> |
setPublicFieldsFromFlags(java.util.Map<?,?> flags,
java.lang.Object o)
|
public static java.util.Map<?,?> setPublicFieldsFromFlags(java.util.Map<?,?> flags, java.lang.Object o)
public static java.util.Map<?,?> setFieldsFromFlags(java.util.Map<?,?> flags, java.lang.Object o)
public static void setFieldsFromFlags(java.lang.Object o, ConfigBag configBag)
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 argumentpublic static void setFieldsFromFlags(java.lang.Object o, ConfigBag configBag, boolean setDefaultVals)
setFieldsFromFlags(Object, ConfigBag)
, but allowing control over whether default values should be setpublic static void setFieldsFromFlagsWithBag(java.lang.Object o, java.util.Map<?,?> flags, ConfigBag configBag, boolean setDefaultVals)
setFieldsFromFlags(Object, ConfigBag)
, but specifying a subset of flags to usepublic static boolean setFieldFromFlag(java.lang.Object o, java.lang.String flagName, java.lang.Object fieldVal)
java.lang.IllegalArgumentException
- If fieldVal is null and the SetFromFlag annotation set nullable=falsepublic static java.util.Map<java.lang.String,?> getFieldsWithFlags(java.lang.Object o)
public static java.lang.reflect.Field findFieldForFlag(java.lang.String flagName, java.lang.Object o)
Field
on the given object annotated with the given name flag.public static java.util.Map<java.lang.String,java.lang.Object> getFieldsWithFlagsExcludingModifiers(java.lang.Object o, int excludingModifiers)
public static java.util.Map<java.lang.String,java.lang.Object> getFieldsWithFlagsWithModifiers(java.lang.Object o, int requiredModifiers)
public static java.util.Map<java.lang.String,?> setAllConfigKeys(java.util.Map<java.lang.String,?> flagsOrConfig, Configurable instance)
setAllConfigKeys(Map, Configurable, boolean)
ConfigKey
_ and ConfigKey.HasConfigKey
fields on the given object,
using the indicated flags/config-bagpublic static java.util.Map<java.lang.String,?> setAllConfigKeys(java.util.Map<java.lang.String,?> flagsOrConfig, Configurable instance, boolean includeFlags)
ConfigKey
_ and ConfigKey.HasConfigKey
fields on the given object,
using the indicated flags/config-bagpublic static void setAllConfigKeys(Configurable o, ConfigBag bag)
setAllConfigKeys(Configurable, ConfigBag, boolean)
ConfigKey
_ and ConfigKey.HasConfigKey
fields on the given object,
using the indicated flags/config-bagpublic static void setAllConfigKeys(Configurable o, ConfigBag bag, boolean includeFlags)
ConfigKey
_ and ConfigKey.HasConfigKey
fields on the given object,
using the indicated flags/config-bagpublic static <T> java.util.List<FlagUtils.FlagConfigKeyAndValueRecord> findAllFlagsAndConfigKeys(T optionalInstance, java.lang.Class<? extends T> type, ConfigBag input)
public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class<?> base, groovy.lang.Closure<java.lang.Boolean> filter)
public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class<?> base)
public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class<?> base, com.google.common.base.Predicate<java.lang.reflect.Field> filter)
public static java.util.List<java.lang.reflect.Field> getLocalFields(java.util.List<java.lang.Class<?>> classes)
public static java.util.List<java.lang.reflect.Field> getLocalFields(java.util.List<java.lang.Class<?>> classes, groovy.lang.Closure<java.lang.Boolean> filter)
public static java.util.List<java.lang.reflect.Field> getLocalFields(java.util.List<java.lang.Class<?>> classes, com.google.common.base.Predicate<java.lang.reflect.Field> filter)
public static java.util.List<java.lang.Class<?>> getAllAssignableTypes(java.lang.Class<?> base)
public static java.util.List<java.lang.Class<?>> getAllAssignableTypes(java.lang.Class<?> base, groovy.lang.Closure<java.lang.Boolean> filter)
public static java.util.List<java.lang.Class<?>> getAllAssignableTypes(java.lang.Class<?> base, com.google.common.base.Predicate<java.lang.Class<?>> filter)
public static void setConfig(java.lang.Object objectOfField, ConfigKey<?> key, java.lang.Object value, SetFromFlag optionalAnnotation)
public static void setField(java.lang.Object objectOfField, java.lang.reflect.Field f, java.lang.Object value, SetFromFlag optionalAnnotation)
public static java.lang.Object getField(java.lang.Object objectOfField, java.lang.reflect.Field f)
public static java.lang.Object getDefaultValueForType(java.lang.Class<?> t)
public static java.util.Map<java.lang.reflect.Field,SetFromFlag> getAnnotatedFields(java.lang.Class<?> type)
public static java.util.Map<ConfigKey<?>,SetFromFlag> getAnnotatedConfigKeys(java.lang.Class<?> type)
ConfigKey
fields which are annotated 'SetFromFlag', along with the annotationpublic static java.util.Map<java.lang.String,java.lang.Object> getFieldsWithValues(java.lang.Object o)
public static void checkRequiredFields(java.lang.Object o)
an
- IllegalStateException if there are fields required (nullable=false) which are unsetwrapped
- IllegalAccessException