Class IfDefault
- All Implemented Interfaces:
If<Object,
,Object> InitializeIf
This condition tests against the default value of the field that it is placed upon, whatever that default may be. If you initialize the field with a value, this condition will use that value as the comparison. For example, if you have a class like this:
public class MyEntity { @Id Long id; @IgnoreSave(IfDefault.class) String foo = "defaultFoo"; }
The foo
field will be left unsaved when it has the value "defaultFoo".
Specifically, this conditional constructs an instance of the class in which the field is declared and stores the default field value for later comparison. Note that if you initialize the field in your default constructor, this counts!
There is one important caveat: Objectify treats each declared class in a type hierarchy separately. The class in which the field is declared have a no-arg constructor, and it alone is used to determine the default value. This will NOT work:
public class MyBase { @Id Long id; @IgnoreSave(IfDefault.class) String foo = "baseFoo"; } public class MyEntity extends MyBase { public MyEntity() { foo = "subclassFoo"; } }
In this example, the default value will be "baseFoo".
- Author:
- Jeff Schnitzer invalid input: '<'[email protected]>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
init
(ObjectifyFactory fact, Field field) Instructs the condition instance which field it lives on.boolean
matchesValue
(Object value) Test a simple property value.Methods inherited from class com.googlecode.objectify.condition.ValueIf
matchesPojo
-
Constructor Details
-
IfDefault
public IfDefault()
-
-
Method Details
-
init
Description copied from interface:InitializeIf
Instructs the condition instance which field it lives on.- Specified by:
init
in interfaceInitializeIf
- Parameters:
fact
- is just handy to have aroundfield
- is the field which has the annotation with this condition.
-
matchesValue
Description copied from interface:If
Test a simple property value.- Specified by:
matchesValue
in interfaceIf<Object,
Object> - Parameters:
value
- is the actual value of a particular field- Returns:
- true if the value matches the condition defined by an instance of this interface.
-