From bf8e3832292f408a8884cba59a2f264a4be71ae0 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 21 Jun 2018 18:59:31 +0100 Subject: [PATCH] Move Maybe into maybe package --- .../net/kemitix/mon/{ => maybe}/Just.java | 4 +-- .../net/kemitix/mon/{ => maybe}/Maybe.java | 3 +- .../net/kemitix/mon/{ => maybe}/Nothing.java | 6 ++-- .../net/kemitix/mon/maybe/package-info.java | 30 +++++++++++++++++++ src/test/java/net/kemitix/mon/MaybeTest.java | 7 +++-- 5 files changed, 41 insertions(+), 9 deletions(-) rename src/main/java/net/kemitix/mon/{ => maybe}/Just.java (97%) rename src/main/java/net/kemitix/mon/{ => maybe}/Maybe.java (98%) rename src/main/java/net/kemitix/mon/{ => maybe}/Nothing.java (93%) create mode 100644 src/main/java/net/kemitix/mon/maybe/package-info.java diff --git a/src/main/java/net/kemitix/mon/Just.java b/src/main/java/net/kemitix/mon/maybe/Just.java similarity index 97% rename from src/main/java/net/kemitix/mon/Just.java rename to src/main/java/net/kemitix/mon/maybe/Just.java index 9437bc7..cc42450 100644 --- a/src/main/java/net/kemitix/mon/Just.java +++ b/src/main/java/net/kemitix/mon/maybe/Just.java @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package net.kemitix.mon; +package net.kemitix.mon.maybe; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; @@ -39,7 +39,7 @@ import java.util.function.Supplier; * @author Paul Campbell (pcampbell@kemitix.net) */ @RequiredArgsConstructor(access = AccessLevel.PROTECTED) -public final class Just implements Maybe { +final class Just implements Maybe { private final T value; diff --git a/src/main/java/net/kemitix/mon/Maybe.java b/src/main/java/net/kemitix/mon/maybe/Maybe.java similarity index 98% rename from src/main/java/net/kemitix/mon/Maybe.java rename to src/main/java/net/kemitix/mon/maybe/Maybe.java index 3211d0c..a313242 100644 --- a/src/main/java/net/kemitix/mon/Maybe.java +++ b/src/main/java/net/kemitix/mon/maybe/Maybe.java @@ -19,9 +19,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package net.kemitix.mon; +package net.kemitix.mon.maybe; import lombok.NonNull; +import net.kemitix.mon.Functor; import java.util.Optional; import java.util.function.Consumer; diff --git a/src/main/java/net/kemitix/mon/Nothing.java b/src/main/java/net/kemitix/mon/maybe/Nothing.java similarity index 93% rename from src/main/java/net/kemitix/mon/Nothing.java rename to src/main/java/net/kemitix/mon/maybe/Nothing.java index f484b1f..ded76e6 100644 --- a/src/main/java/net/kemitix/mon/Nothing.java +++ b/src/main/java/net/kemitix/mon/maybe/Nothing.java @@ -19,7 +19,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package net.kemitix.mon; +package net.kemitix.mon.maybe; import java.util.Optional; import java.util.function.Consumer; @@ -34,9 +34,9 @@ import java.util.function.Supplier; * * @author Paul Campbell (pcampbell@kemitix.net) */ -public final class Nothing implements Maybe { +final class Nothing implements Maybe { - protected static final Maybe INSTANCE = new Nothing<>(); + static final Maybe INSTANCE = new Nothing<>(); @Override public Maybe map(final Function f) { diff --git a/src/main/java/net/kemitix/mon/maybe/package-info.java b/src/main/java/net/kemitix/mon/maybe/package-info.java new file mode 100644 index 0000000..3c1cb93 --- /dev/null +++ b/src/main/java/net/kemitix/mon/maybe/package-info.java @@ -0,0 +1,30 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 Paul Campbell + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies + * or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * An experiment in creating something similar to a Type-Alias in Java. + * + *

Ideas initially lifted from the Design with Types series at https://fsharpforfunandprofit.com/

+ * + * @author Paul Campbell (pcampbell@kemitix.net) + */ + +package net.kemitix.mon.maybe; diff --git a/src/test/java/net/kemitix/mon/MaybeTest.java b/src/test/java/net/kemitix/mon/MaybeTest.java index f8e7e33..9382940 100644 --- a/src/test/java/net/kemitix/mon/MaybeTest.java +++ b/src/test/java/net/kemitix/mon/MaybeTest.java @@ -1,5 +1,6 @@ package net.kemitix.mon; +import net.kemitix.mon.maybe.Maybe; import org.junit.Test; import java.util.Objects; @@ -7,9 +8,9 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; -import static net.kemitix.mon.Maybe.just; -import static net.kemitix.mon.Maybe.maybe; -import static net.kemitix.mon.Maybe.nothing; +import static net.kemitix.mon.maybe.Maybe.just; +import static net.kemitix.mon.maybe.Maybe.maybe; +import static net.kemitix.mon.maybe.Maybe.nothing; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatNullPointerException;