diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:43:13 -0400 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-04-13 18:43:13 -0400 |
| commit | f51f6da7319787348c38b875652b5c0e9f88c8aa (patch) | |
| tree | 943888fc724da2d2dedd89abec99dcbfcc089fd0 /src/main/java/bjc/data/Option.java | |
| parent | 9052ed6da37af23ea82588d248f409e60a33c6cb (diff) | |
Cleanup pass
Pass to do some cleanups
Diffstat (limited to 'src/main/java/bjc/data/Option.java')
| -rw-r--r-- | src/main/java/bjc/data/Option.java | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/src/main/java/bjc/data/Option.java b/src/main/java/bjc/data/Option.java index a180ef9..b5d6d5e 100644 --- a/src/main/java/bjc/data/Option.java +++ b/src/main/java/bjc/data/Option.java @@ -9,7 +9,7 @@ import java.util.function.UnaryOperator; * @author ben * * @param <ContainedType> - * The type of the value that may or may not be held. + * The type of the value that may or may not be held. */ public class Option<ContainedType> implements IHolder<ContainedType> { private ContainedType held; @@ -18,36 +18,40 @@ public class Option<ContainedType> implements IHolder<ContainedType> { * Create a new optional, using the given initial value. * * @param seed - * The initial value for the optional. + * The initial value for the optional. */ public Option(final ContainedType seed) { held = seed; } @Override - public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) { - if(held == null) return new Option<>(null); + public <BoundType> IHolder<BoundType> + bind(final Function<ContainedType, IHolder<BoundType>> binder) { + if (held == null) + return new Option<>(null); return binder.apply(held); } @Override - public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) { - return val -> { - return new Option<>(func.apply(val)); - }; + public <NewType> Function<ContainedType, IHolder<NewType>> + lift(final Function<ContainedType, NewType> func) { + return val -> new Option<>(func.apply(val)); } @Override - public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) { - if(held == null) return new Option<>(null); + public <MappedType> IHolder<MappedType> + map(final Function<ContainedType, MappedType> mapper) { + if (held == null) + return new Option<>(null); return new Option<>(mapper.apply(held)); } @Override - public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) { - if(held != null) { + public IHolder<ContainedType> + transform(final UnaryOperator<ContainedType> transformer) { + if (held != null) { held = transformer.apply(held); } @@ -55,8 +59,10 @@ public class Option<ContainedType> implements IHolder<ContainedType> { } @Override - public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) { - if(held == null) return null; + public <UnwrappedType> UnwrappedType + unwrap(final Function<ContainedType, UnwrappedType> unwrapper) { + if (held == null) + return null; return unwrapper.apply(held); } @@ -78,15 +84,20 @@ public class Option<ContainedType> implements IHolder<ContainedType> { @Override public boolean equals(final Object obj) { - if(this == obj) return true; - if(obj == null) return false; - if(!(obj instanceof Option<?>)) return false; + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Option<?>)) + return false; final 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; } |
