diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index f3d4750..b45d034 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -9,6 +9,6 @@ jobs: update_draft_release: runs-on: ubuntu-latest steps: - - uses: release-drafter/release-drafter@v5.11.0 + - uses: release-drafter/release-drafter@v5.14.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/LICENSE.txt b/LICENSE.txt index 7607e05..cd251ea 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/README.org b/README.org index a6a3bdb..c89b0b3 100644 --- a/README.org +++ b/README.org @@ -1,11 +1,12 @@ * Mon -* TypeAlias, Maybe and Result for Java. +* Alias, TypeAlias, Maybe and Result for Java. [[https://oss.sonatype.org/content/repositories/releases/net/kemitix/mon][file:https://img.shields.io/nexus/r/https/oss.sonatype.org/net.kemitix/mon.svg?style=for-the-badge]] [[https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22net.kemitix%22%20AND%20a%3A%22mon%22][file:https://img.shields.io/maven-central/v/net.kemitix/mon.svg?style=for-the-badge]] [[http://i.jpeek.org/net.kemitix/mon/index.html][file:http://i.jpeek.org/net.kemitix/mon/badge.svg]] - [Maven Usage] + - [Alias] - [TypeAlias] - [Maybe] - [Result] @@ -26,7 +27,10 @@ The latest version should be shown above with the nexus and maven-central badges or can be found on [[https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22net.kemitix%22%20AND%20a%3A%22mon%22][Maven Central]]. -* TypeAlias +* Wrapper + + A simple FunctionalInterface that contains a value. Can be used to implement + a form of type-alias in Java. In Haskell it is possible to create an alias for a Type, and to then use that alias with the same behaviour as the original, except that the compiler @@ -39,20 +43,62 @@ newtype PhoneBookEntry = PhoneBookEntry (Name, PhoneNumber) newtype PhoneBook = PhoneBook [PhoneBookEntry] #+END_SRC - - In Java we don't have the ability to have that true alias, so TypeAlias is - more of a type-wrapper. It's as close as I could get to a Haskell type alias - in Java. - The benefits of using TypeAlias are: + In Java we don't have the ability to have that true alias, so Wrapper simply + wraps the value within a new type. It's as close as I could get to a Haskell + type alias in Java. + + The benefits of using Wrapper are: - encapsulation of the wrapped type when passing references through code that doesn't need to access the actual value, but only to pass it on - type-safe parameters where you would otherwise be passing Strings, Integers, Lists, or other general classes - - equality and hashcode - less verbose than implementing your own + *Wrapper Example:* + + #+BEGIN_SRC java + interface PhoneNumber extends Wrapper {} + + PhoneNumber pn = () -> "01234 567890"; + String v = pn.value(); + #+END_SRC + + *Roll your own:* + + #+BEGIN_SRC java + class PhoneNumber { + private final String value; + public PhoneNumber(final String value) { + this.value = value; + } + public String value() { + return value; + } + } + #+END_SRC + + *Lombok:* + + Using Lombok we can achieve it in 8 lines, compared to 24 for rolling your + own, or 1 for Alias: + + #+BEGIN_SRC java + @Value + @RequiredArgsConstructor(access = AccessLevel.PRIVATE) + class PhoneNumber { + private final String value; + public static PhoneNumber of(final String phoneNumber) { + return new PhoneNumber(phoneNumber); + } + } + #+END_SRC + +* TypeAlias + + Note: this is a precursor to `Wrapper` and should be considered deprecated. + *TypeAlias Example:* #+BEGIN_SRC java @@ -66,51 +112,6 @@ } #+END_SRC - *Roll your own:* - - #+BEGIN_SRC java - class PhoneNumber { - private final String value; - private PhoneNumber(final String value) { - this.value = value; - } - public static PhoneNumber of(final String phoneNumber) { - return new PhoneNumber(phoneNumber); - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - PhoneNumber that = (PhoneNumber) o; - return Objects.equals(value, that.value); - } - @Override - public int hashCode() { - return Objects.hash(value); - } - public String getValue() { - return value; - } - } - #+END_SRC - - *Lombok:* - - Although, if you are using Lombok, that can be equally terse, both it and - TypeAlias coming in at 8 lines each, compared to 24 for rolling your - own: - - #+BEGIN_SRC java - @Value - @RequiredArgsConstructor(access = AccessLevel.PRIVATE) - class PhoneNumber { - private final String value; - public static PhoneNumber of(final String phoneNumber) { - return new PhoneNumber(phoneNumber); - } - } - #+END_SRC - ** =TypeAlias= *can* be a Monad #+BEGIN_SRC java diff --git a/pom.xml b/pom.xml index b3776e3..5ec1d7a 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ mon - 2.2.1-SNAPSHOT + 2.3.0 Mon TypeAlias, Result and Maybe for Java diff --git a/src/main/java/net/kemitix/mon/Functor.java b/src/main/java/net/kemitix/mon/Functor.java index 905e0f1..0fd40c0 100644 --- a/src/main/java/net/kemitix/mon/Functor.java +++ b/src/main/java/net/kemitix/mon/Functor.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/Mon.java b/src/main/java/net/kemitix/mon/Mon.java index be85dc9..809d4c3 100644 --- a/src/main/java/net/kemitix/mon/Mon.java +++ b/src/main/java/net/kemitix/mon/Mon.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/TypeAlias.java b/src/main/java/net/kemitix/mon/TypeAlias.java index 40d1f7d..f7a22fd 100644 --- a/src/main/java/net/kemitix/mon/TypeAlias.java +++ b/src/main/java/net/kemitix/mon/TypeAlias.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/Wrapper.java b/src/main/java/net/kemitix/mon/Wrapper.java new file mode 100644 index 0000000..8efe27f --- /dev/null +++ b/src/main/java/net/kemitix/mon/Wrapper.java @@ -0,0 +1,42 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2021 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. + */ + +package net.kemitix.mon; + +/** + * A wrapper for other types. + * + *

Can be used as a form of type-alias, where the value is held in the wrapper.

+ * + * @param the type of the wrapper's value + * @author Paul Campbell (pcampbell@kemitix.net) + */ +@FunctionalInterface +public interface Wrapper { + + /** + * The wrapped value. + * + * @return the value + */ + public abstract T value(); + +} diff --git a/src/main/java/net/kemitix/mon/combinator/After.java b/src/main/java/net/kemitix/mon/combinator/After.java index 2fc4684..1893a9b 100644 --- a/src/main/java/net/kemitix/mon/combinator/After.java +++ b/src/main/java/net/kemitix/mon/combinator/After.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/combinator/Around.java b/src/main/java/net/kemitix/mon/combinator/Around.java index 0de8730..4da52d9 100644 --- a/src/main/java/net/kemitix/mon/combinator/Around.java +++ b/src/main/java/net/kemitix/mon/combinator/Around.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/combinator/Before.java b/src/main/java/net/kemitix/mon/combinator/Before.java index b29f200..29780ee 100644 --- a/src/main/java/net/kemitix/mon/combinator/Before.java +++ b/src/main/java/net/kemitix/mon/combinator/Before.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/combinator/package-info.java b/src/main/java/net/kemitix/mon/combinator/package-info.java index 30ec2ef..c0435d6 100644 --- a/src/main/java/net/kemitix/mon/combinator/package-info.java +++ b/src/main/java/net/kemitix/mon/combinator/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/experimental/BeanBuilder.java b/src/main/java/net/kemitix/mon/experimental/BeanBuilder.java index 375d8dd..46c62e9 100644 --- a/src/main/java/net/kemitix/mon/experimental/BeanBuilder.java +++ b/src/main/java/net/kemitix/mon/experimental/BeanBuilder.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/experimental/either/Either.java b/src/main/java/net/kemitix/mon/experimental/either/Either.java index 216fd1e..d8ca36e 100644 --- a/src/main/java/net/kemitix/mon/experimental/either/Either.java +++ b/src/main/java/net/kemitix/mon/experimental/either/Either.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/experimental/either/Left.java b/src/main/java/net/kemitix/mon/experimental/either/Left.java index 7946e80..b46e80c 100644 --- a/src/main/java/net/kemitix/mon/experimental/either/Left.java +++ b/src/main/java/net/kemitix/mon/experimental/either/Left.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/experimental/either/Right.java b/src/main/java/net/kemitix/mon/experimental/either/Right.java index bdffa7d..a0dfe2b 100644 --- a/src/main/java/net/kemitix/mon/experimental/either/Right.java +++ b/src/main/java/net/kemitix/mon/experimental/either/Right.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/experimental/either/package-info.java b/src/main/java/net/kemitix/mon/experimental/either/package-info.java index 3b248cf..3878cdd 100644 --- a/src/main/java/net/kemitix/mon/experimental/either/package-info.java +++ b/src/main/java/net/kemitix/mon/experimental/either/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/experimental/package-info.java b/src/main/java/net/kemitix/mon/experimental/package-info.java index e5d76b3..6784c5e 100644 --- a/src/main/java/net/kemitix/mon/experimental/package-info.java +++ b/src/main/java/net/kemitix/mon/experimental/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/lazy/Lazy.java b/src/main/java/net/kemitix/mon/lazy/Lazy.java index ebd593c..e67838f 100644 --- a/src/main/java/net/kemitix/mon/lazy/Lazy.java +++ b/src/main/java/net/kemitix/mon/lazy/Lazy.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/lazy/LazySupplier.java b/src/main/java/net/kemitix/mon/lazy/LazySupplier.java index 7460dcd..35f6440 100644 --- a/src/main/java/net/kemitix/mon/lazy/LazySupplier.java +++ b/src/main/java/net/kemitix/mon/lazy/LazySupplier.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/lazy/package-info.java b/src/main/java/net/kemitix/mon/lazy/package-info.java index 0782b4c..00b12a3 100644 --- a/src/main/java/net/kemitix/mon/lazy/package-info.java +++ b/src/main/java/net/kemitix/mon/lazy/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/maybe/Just.java b/src/main/java/net/kemitix/mon/maybe/Just.java index b16cbd8..65f6772 100644 --- a/src/main/java/net/kemitix/mon/maybe/Just.java +++ b/src/main/java/net/kemitix/mon/maybe/Just.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/maybe/Maybe.java b/src/main/java/net/kemitix/mon/maybe/Maybe.java index 1808e99..233ede4 100644 --- a/src/main/java/net/kemitix/mon/maybe/Maybe.java +++ b/src/main/java/net/kemitix/mon/maybe/Maybe.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/maybe/Nothing.java b/src/main/java/net/kemitix/mon/maybe/Nothing.java index 47f651c..1af8a71 100644 --- a/src/main/java/net/kemitix/mon/maybe/Nothing.java +++ b/src/main/java/net/kemitix/mon/maybe/Nothing.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/maybe/package-info.java b/src/main/java/net/kemitix/mon/maybe/package-info.java index 50311b9..227c487 100644 --- a/src/main/java/net/kemitix/mon/maybe/package-info.java +++ b/src/main/java/net/kemitix/mon/maybe/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/package-info.java b/src/main/java/net/kemitix/mon/package-info.java index 717727d..dec355c 100644 --- a/src/main/java/net/kemitix/mon/package-info.java +++ b/src/main/java/net/kemitix/mon/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/result/CheckedErrorResultException.java b/src/main/java/net/kemitix/mon/result/CheckedErrorResultException.java index 47a1916..4bb06b1 100644 --- a/src/main/java/net/kemitix/mon/result/CheckedErrorResultException.java +++ b/src/main/java/net/kemitix/mon/result/CheckedErrorResultException.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/result/Err.java b/src/main/java/net/kemitix/mon/result/Err.java index a6d0f04..88d70bf 100644 --- a/src/main/java/net/kemitix/mon/result/Err.java +++ b/src/main/java/net/kemitix/mon/result/Err.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/result/ErrorResultException.java b/src/main/java/net/kemitix/mon/result/ErrorResultException.java index 3ad4893..7d06b2f 100644 --- a/src/main/java/net/kemitix/mon/result/ErrorResultException.java +++ b/src/main/java/net/kemitix/mon/result/ErrorResultException.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/result/Result.java b/src/main/java/net/kemitix/mon/result/Result.java index d0942c0..d5e306c 100644 --- a/src/main/java/net/kemitix/mon/result/Result.java +++ b/src/main/java/net/kemitix/mon/result/Result.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/result/Success.java b/src/main/java/net/kemitix/mon/result/Success.java index ee8a49e..cb27699 100644 --- a/src/main/java/net/kemitix/mon/result/Success.java +++ b/src/main/java/net/kemitix/mon/result/Success.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/result/UnexpectedErrorResultException.java b/src/main/java/net/kemitix/mon/result/UnexpectedErrorResultException.java index ef67f8c..105e74d 100644 --- a/src/main/java/net/kemitix/mon/result/UnexpectedErrorResultException.java +++ b/src/main/java/net/kemitix/mon/result/UnexpectedErrorResultException.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/result/WithResultContinuation.java b/src/main/java/net/kemitix/mon/result/WithResultContinuation.java index 997072d..4786019 100644 --- a/src/main/java/net/kemitix/mon/result/WithResultContinuation.java +++ b/src/main/java/net/kemitix/mon/result/WithResultContinuation.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/result/package-info.java b/src/main/java/net/kemitix/mon/result/package-info.java index eebb7a2..b9f390a 100644 --- a/src/main/java/net/kemitix/mon/result/package-info.java +++ b/src/main/java/net/kemitix/mon/result/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/tree/GeneralisedTree.java b/src/main/java/net/kemitix/mon/tree/GeneralisedTree.java index e833b49..4d614b7 100644 --- a/src/main/java/net/kemitix/mon/tree/GeneralisedTree.java +++ b/src/main/java/net/kemitix/mon/tree/GeneralisedTree.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/tree/MutableTree.java b/src/main/java/net/kemitix/mon/tree/MutableTree.java index 9948ba8..f12f4ef 100644 --- a/src/main/java/net/kemitix/mon/tree/MutableTree.java +++ b/src/main/java/net/kemitix/mon/tree/MutableTree.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/tree/MutableTreeBuilder.java b/src/main/java/net/kemitix/mon/tree/MutableTreeBuilder.java index 0ce7ef4..767538b 100644 --- a/src/main/java/net/kemitix/mon/tree/MutableTreeBuilder.java +++ b/src/main/java/net/kemitix/mon/tree/MutableTreeBuilder.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/tree/Tree.java b/src/main/java/net/kemitix/mon/tree/Tree.java index 66ce89c..fc5191d 100644 --- a/src/main/java/net/kemitix/mon/tree/Tree.java +++ b/src/main/java/net/kemitix/mon/tree/Tree.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/tree/TreeBuilder.java b/src/main/java/net/kemitix/mon/tree/TreeBuilder.java index 6c33420..4006409 100644 --- a/src/main/java/net/kemitix/mon/tree/TreeBuilder.java +++ b/src/main/java/net/kemitix/mon/tree/TreeBuilder.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/tree/TreeMapper.java b/src/main/java/net/kemitix/mon/tree/TreeMapper.java index 6453f06..618a9da 100644 --- a/src/main/java/net/kemitix/mon/tree/TreeMapper.java +++ b/src/main/java/net/kemitix/mon/tree/TreeMapper.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/main/java/net/kemitix/mon/tree/package-info.java b/src/main/java/net/kemitix/mon/tree/package-info.java index f234a58..d7ba243 100644 --- a/src/main/java/net/kemitix/mon/tree/package-info.java +++ b/src/main/java/net/kemitix/mon/tree/package-info.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/test/java/net/kemitix/mon/Address.java b/src/test/java/net/kemitix/mon/Address.java index 4909f96..c963b5b 100644 --- a/src/test/java/net/kemitix/mon/Address.java +++ b/src/test/java/net/kemitix/mon/Address.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/test/java/net/kemitix/mon/Customer.java b/src/test/java/net/kemitix/mon/Customer.java index ff910e3..182d4c8 100644 --- a/src/test/java/net/kemitix/mon/Customer.java +++ b/src/test/java/net/kemitix/mon/Customer.java @@ -1,7 +1,7 @@ /** * The MIT License (MIT) * - * Copyright (c) 2018 Paul Campbell + * Copyright (c) 2021 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, diff --git a/src/test/java/net/kemitix/mon/WrapperTest.java b/src/test/java/net/kemitix/mon/WrapperTest.java new file mode 100644 index 0000000..32e5f7e --- /dev/null +++ b/src/test/java/net/kemitix/mon/WrapperTest.java @@ -0,0 +1,83 @@ +package net.kemitix.mon; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class WrapperTest { + + interface WrappedString extends Wrapper {} + + interface WrappedInteger extends Wrapper {} + + interface WrappedIterableString extends Wrapper> { } + + interface WrappedListInteger extends Wrapper> {} + + interface AWrapper extends Wrapper {} + + @Test + void shouldCreateAWrapperAndGetTheValue() { + //given + final String value = "value"; + //when + // - anonymous class syntax + final WrappedString wrappedString = new WrappedString() { + @Override + public String value() { + return value; + } + }; + //then + assertThat(wrappedString.value()).isSameAs(value); + } + + @Test + void shouldCreateAWrapperWithNestedGenericTypes() { + //given + final Iterable iterable = Collections.emptyList(); + //when + // - functional interface / lambda syntax + final WrappedIterableString wrappedIterableString = () -> iterable; + //then + assertThat(wrappedIterableString.value()).isSameAs(iterable); + } + + @Test + void shouldCreateAWrapperSubclassAndGetTheValue() { + //given + final String value = "value"; + //when + final AWrapper aWrapper = () -> value; + //then + assertThat(aWrapper.value()).isSameAs(value); + } + + @Test + void shouldNotBeEqualWhenValueTypesAreDifferent() { + //given + final WrappedString wrappedString = () -> "1"; + final WrappedInteger wrappedInteger = () -> 1; + //then + assertThat(wrappedString).isNotEqualTo(wrappedInteger); + } + + @Test + void shouldNotBeEqualEvenWhenValuesAreTheSame() { + //given + final String value = "value"; + final AWrapper aWrapper1 = () -> value; + final AWrapper aWrapper2 = () -> value; + //then + assertThat(aWrapper1).isNotEqualTo(aWrapper2); + // instead compare `.value()`s + assertThat(aWrapper1.value()).isEqualTo(aWrapper2.value()); + } + +}