I have a class
private class TouchCommand {
private int action;
private int x;
private int y;
...
When the command is executed, it is necessary to verify the field values - null / not null, and depending on it to produce longitudinal action. I want to use Options from Google Guava.
Which solution is right? this:
public boolean executeCommand() {
Optional<Integer> optionalAction = Optional.fromNullable(action);
...
or:
private class TouchCommand {
private Optional<Integer> action;
private Optional<Integer> x;
private Optional<Integer> y;
...
Given that the call to parseAction may also return a null (or absent):
TouchCommand touchCommand = new TouchCommand();
touchCommand.mAction = parseAction(xmlParser.getAttributeValue(namespace, "action"));
...
Questions:
- whether or not to do so: the method parseAction (and similar) returns Optional ?
- whether or not to do so: the field of class objects Optional ?
- whether or not to do so: when checking the fields of the class (assuming that they can be null) to convert them into objects Optional ?
Thx.