summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/Option.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@WIT-136XG42.wvu-ad.wvu.edu>2017-04-07 10:51:31 -0400
committerbjculkin <bjculkin@WIT-136XG42.wvu-ad.wvu.edu>2017-04-07 10:51:31 -0400
commit63d88eb8db1f7a6d5924ec2a8b7f462373d5ac9a (patch)
tree4a7c67b23c8e1ecb1b2f992e5dbaf3ebb48dcf6b /BJC-Utils2/src/main/java/bjc/utils/data/Option.java
parent848dc739becfa41193aff9a07c918aed91e5ef79 (diff)
Cleanup
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/Option.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/data/Option.java42
1 files changed, 20 insertions, 22 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java
index fa25b54..718ab6e 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java
@@ -26,28 +26,30 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public <BoundType> IHolder<BoundType> bind(Function<ContainedType, IHolder<BoundType>> binder) {
- if(held == null) return new Option<>(null);
+ if (held == null)
+ return new Option<>(null);
return binder.apply(held);
}
@Override
public <NewType> Function<ContainedType, IHolder<NewType>> lift(Function<ContainedType, NewType> func) {
- return (val) -> {
+ return val -> {
return new Option<>(func.apply(val));
};
}
@Override
public <MappedType> IHolder<MappedType> map(Function<ContainedType, MappedType> mapper) {
- if(held == null) return new Option<>(null);
+ if (held == null)
+ return new Option<>(null);
return new Option<>(mapper.apply(held));
}
@Override
public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer) {
- if(held != null) {
+ if (held != null) {
held = transformer.apply(held);
}
@@ -56,24 +58,15 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public <UnwrappedType> UnwrappedType unwrap(Function<ContainedType, UnwrappedType> unwrapper) {
- if(held == null) return null;
+ if (held == null)
+ return null;
return unwrapper.apply(held);
}
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
-
- builder.append("Option [");
-
- if(held != null) {
- builder.append("held=");
- builder.append(held);
- }
-
- builder.append("]");
- return builder.toString();
+ return String.format("Option [held='%s']", held);
}
@Override
@@ -88,15 +81,20 @@ public class Option<ContainedType> implements IHolder<ContainedType> {
@Override
public boolean equals(Object obj) {
- if(this == obj) return true;
- if(obj == null) return false;
- if(getClass() != obj.getClass()) return false;
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof Option<?>))
+ return false;
Option<?> other = (Option<?>) obj;
- if(held == null) {
- if(other.held != null) return false;
- } else if(!held.equals(other.held)) return false;
+ if (held == null) {
+ if (other.held != null)
+ return false;
+ } else if (!held.equals(other.held))
+ return false;
return true;
}