From 58c1477248c41970b9df9d0910a5615f58887627 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 18 Sep 2017 20:13:35 +0100 Subject: [PATCH 01/16] version: set to 0.2.0-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e8a56ca..ab55cb9 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 3.2.4 mon - 0.1.0 + 0.2.0-SNAPSHOT From 141d508138430054a8be7251c27f84d0c5355418 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 18 Sep 2017 20:23:01 +0100 Subject: [PATCH 02/16] {Address,Customer,TypeAliasTest}: use explicit scoping --- src/test/java/net/kemitix/mon/Address.java | 2 +- src/test/java/net/kemitix/mon/Customer.java | 2 +- src/test/java/net/kemitix/mon/TypeAliasTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/net/kemitix/mon/Address.java b/src/test/java/net/kemitix/mon/Address.java index 8bfbd37..5e8b0cb 100644 --- a/src/test/java/net/kemitix/mon/Address.java +++ b/src/test/java/net/kemitix/mon/Address.java @@ -33,7 +33,7 @@ class Address { private final String street; - String getStreet() { + protected String getStreet() { return street; } } diff --git a/src/test/java/net/kemitix/mon/Customer.java b/src/test/java/net/kemitix/mon/Customer.java index 594abd7..f96f133 100644 --- a/src/test/java/net/kemitix/mon/Customer.java +++ b/src/test/java/net/kemitix/mon/Customer.java @@ -33,7 +33,7 @@ class Customer { private final Address address; - Address getAddress() { + protected Address getAddress() { return address; } diff --git a/src/test/java/net/kemitix/mon/TypeAliasTest.java b/src/test/java/net/kemitix/mon/TypeAliasTest.java index 91687c3..1d07c80 100644 --- a/src/test/java/net/kemitix/mon/TypeAliasTest.java +++ b/src/test/java/net/kemitix/mon/TypeAliasTest.java @@ -74,7 +74,7 @@ public class TypeAliasTest { super(value); } - static AnAlias of(final String value) { + protected static AnAlias of(final String value) { return new AnAlias(value); } } From b3c652006715f23ea5d1e5489c34fd82f4407444 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 18 Sep 2017 20:40:53 +0100 Subject: [PATCH 03/16] {Identity,Mon}Test: JUnit tests should include asserts --- src/test/java/net/kemitix/mon/IdentityTest.java | 8 ++++++-- src/test/java/net/kemitix/mon/MonTest.java | 14 +++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/test/java/net/kemitix/mon/IdentityTest.java b/src/test/java/net/kemitix/mon/IdentityTest.java index c93a2e9..5a1b3f3 100644 --- a/src/test/java/net/kemitix/mon/IdentityTest.java +++ b/src/test/java/net/kemitix/mon/IdentityTest.java @@ -17,7 +17,7 @@ public class IdentityTest implements WithAssertions { //when final Identity idInt = idString.map(String::length); //then - idInt.map(id -> assertThat(id).isEqualTo(3)); + assertIdentityContains(idInt, 3); } @Test @@ -31,7 +31,11 @@ public class IdentityTest implements WithAssertions { .map(String::toLowerCase) .map(String::getBytes); //then - idBytes.map(bytes -> assertThat(bytes).isEqualTo("par".getBytes())); + assertIdentityContains(idBytes, "par".getBytes()); + } + + private void assertIdentityContains(final Identity identity, final T expected) { + identity.map(id -> assertThat(id).isEqualTo(expected)); } } diff --git a/src/test/java/net/kemitix/mon/MonTest.java b/src/test/java/net/kemitix/mon/MonTest.java index 91b51f0..96272c3 100644 --- a/src/test/java/net/kemitix/mon/MonTest.java +++ b/src/test/java/net/kemitix/mon/MonTest.java @@ -15,7 +15,7 @@ public class MonTest { //when final Mon wrap = Mon.of("test"); //then - wrap.map(value -> assertThat(value).isEqualTo("test")); + assertMonContains(wrap, "test"); } @Test @@ -25,7 +25,7 @@ public class MonTest { //when final Mon updated = wrap.map(a -> a + " more"); //then - updated.map(value -> assertThat(value).isEqualTo("test more")); + assertMonContains(updated, "test more"); } @Test @@ -35,7 +35,7 @@ public class MonTest { //when final Mon result = wrap.map(String::length); //then - result.map(value -> assertThat(value).isEqualTo(4)); + assertMonContains(result, 4); } @Test @@ -52,7 +52,7 @@ public class MonTest { final Optional> longAndInvalid = factory.apply("value is too long"); //then assertThat(shortAndValid).isNotEmpty(); - shortAndValid.ifPresent(valid -> valid.map(value -> assertThat(value).contains("value okay"))); + shortAndValid.ifPresent(valid -> assertMonContains(valid, "value okay")); assertThat(longAndInvalid).isEmpty(); } @@ -76,7 +76,7 @@ public class MonTest { final Mon> nonFlatMapped = wrap.map(Mon::of); final Mon result = wrap.flatMap(Mon::of); //then - result.map(value -> assertThat(value).isEqualTo("test")); + assertMonContains(result, "test"); nonFlatMapped.map(inner -> assertThat(result).isEqualTo(inner)); } @@ -144,4 +144,8 @@ public class MonTest { assertThat(one).isNotEqualTo(notAMon); assertThat(one).isNotEqualTo(null); } + + private void assertMonContains(final Mon wrap, final T expected) { + wrap.map(value -> assertThat(value).isEqualTo(expected)); + } } From c93ec60a31598a435760dc461fe5b1564c3b0739 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 18 Sep 2017 22:46:12 +0100 Subject: [PATCH 04/16] TypeAliasTest: Avoid calling toString() on String objects --- src/test/java/net/kemitix/mon/TypeAliasTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/net/kemitix/mon/TypeAliasTest.java b/src/test/java/net/kemitix/mon/TypeAliasTest.java index 1d07c80..069c6ab 100644 --- a/src/test/java/net/kemitix/mon/TypeAliasTest.java +++ b/src/test/java/net/kemitix/mon/TypeAliasTest.java @@ -60,7 +60,7 @@ public class TypeAliasTest { //given final String value = "value"; final AnAlias anAlias = AnAlias.of(value); - assertThat(anAlias.toString()).isEqualTo(value.toString()); + assertThat(anAlias.toString()).isEqualTo(value); } private static class AnAlias extends TypeAlias { From ccf3a1115755dcdea0d1c5e9051ce18350a9c17c Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 19 Sep 2017 23:09:28 +0100 Subject: [PATCH 05/16] MonTest: apply stepdown rule to methods --- src/test/java/net/kemitix/mon/MonTest.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/test/java/net/kemitix/mon/MonTest.java b/src/test/java/net/kemitix/mon/MonTest.java index 96272c3..3d8a660 100644 --- a/src/test/java/net/kemitix/mon/MonTest.java +++ b/src/test/java/net/kemitix/mon/MonTest.java @@ -18,6 +18,13 @@ public class MonTest { assertMonContains(wrap, "test"); } + private void assertMonContains( + final Mon wrap, + final T expected + ) { + wrap.map(value -> assertThat(value).isEqualTo(expected)); + } + @Test public void canMap() { //given @@ -144,8 +151,4 @@ public class MonTest { assertThat(one).isNotEqualTo(notAMon); assertThat(one).isNotEqualTo(null); } - - private void assertMonContains(final Mon wrap, final T expected) { - wrap.map(value -> assertThat(value).isEqualTo(expected)); - } } From fdc4cad4e4f999935b0e5b9825ccb4428a006b5b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 19 Sep 2017 23:10:31 +0100 Subject: [PATCH 06/16] Functor: rewrite map() javadoc --- src/main/java/net/kemitix/mon/Functor.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kemitix/mon/Functor.java b/src/main/java/net/kemitix/mon/Functor.java index dbcd72f..20e064f 100644 --- a/src/main/java/net/kemitix/mon/Functor.java +++ b/src/main/java/net/kemitix/mon/Functor.java @@ -33,12 +33,12 @@ import java.util.function.Function; public interface Functor { /** - * Map the content of the functor through the function. + * Applies the function to the value within the Functor, returning the result within a Functor. * - * @param f the function - * @param the type the functor maps to + * @param f the function to apply + * @param the type of the result of the function * - * @return the new functor + * @return a Functor containing the result of the function {@code f} applied to the value */ Functor map(Function f); } From 3d8ebfeed6a2f30611acbeea79380eae212d9f6f Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 19 Sep 2017 23:11:18 +0100 Subject: [PATCH 07/16] Mon: make map() and flatMap() final Also remove map() javadoc that is now in Functor. --- src/main/java/net/kemitix/mon/Mon.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/kemitix/mon/Mon.java b/src/main/java/net/kemitix/mon/Mon.java index eff8554..8abe82d 100644 --- a/src/main/java/net/kemitix/mon/Mon.java +++ b/src/main/java/net/kemitix/mon/Mon.java @@ -82,16 +82,8 @@ public class Mon implements Functor { return new Mon<>(v); } - /** - * Applies the function to the value within the Mon, returning a Mon containing the result. - * - * @param f the function to apply - * @param the type of the result of the function - * - * @return a Mon containing the result of the function {@code f} to the value - */ @Override - public Mon map(final Function f) { + public final Mon map(final Function f) { return Mon.of(f.apply(value)); } @@ -104,7 +96,7 @@ public class Mon implements Functor { * * @return a Mon containing the result of the function */ - public Mon flatMap(final Function> f) { + public final Mon flatMap(final Function> f) { return f.apply(value); } From cf723da38ae672e118248067f684531091286ec1 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 30 Sep 2017 15:41:08 +0100 Subject: [PATCH 08/16] Functor: clean up javadoc --- src/main/java/net/kemitix/mon/Functor.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kemitix/mon/Functor.java b/src/main/java/net/kemitix/mon/Functor.java index 20e064f..0111ca1 100644 --- a/src/main/java/net/kemitix/mon/Functor.java +++ b/src/main/java/net/kemitix/mon/Functor.java @@ -24,9 +24,16 @@ package net.kemitix.mon; import java.util.function.Function; /** - * The Functor interface. + * The Functor is used for types that can be mapped over. * - * @param the type of the functor content + *

Implementations of Functor should satisfy the following laws:

+ * + *
    + *
  • map id == id
  • + *
  • map (f . g) == map f . map g
  • + *
+ * + * @param the type of the Functor * * @author Tomasz Nurkiewicz (?@?.?) */ From 1046b6c5ae179850237bbafdcf54c948a1ec0dc0 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 30 Sep 2017 16:46:49 +0100 Subject: [PATCH 09/16] entities: add static builder and constructors and make previous revision Optional --- src/test/java/net/kemitix/mon/IdentityTest.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/test/java/net/kemitix/mon/IdentityTest.java b/src/test/java/net/kemitix/mon/IdentityTest.java index 5a1b3f3..513a979 100644 --- a/src/test/java/net/kemitix/mon/IdentityTest.java +++ b/src/test/java/net/kemitix/mon/IdentityTest.java @@ -10,6 +10,15 @@ import org.junit.Test; */ public class IdentityTest implements WithAssertions { + @Test + public void functorLawMapIdEqualsId() { + //given + final String id = "id"; + //when + + //then + } + @Test public void canMapIdentityFromStringToInteger() { //given @@ -20,6 +29,10 @@ public class IdentityTest implements WithAssertions { assertIdentityContains(idInt, 3); } + private void assertIdentityContains(final Identity identity, final T expected) { + identity.map(id -> assertThat(id).isEqualTo(expected)); + } + @Test public void canFluentlyComposeFunctions() { //given @@ -34,8 +47,4 @@ public class IdentityTest implements WithAssertions { assertIdentityContains(idBytes, "par".getBytes()); } - private void assertIdentityContains(final Identity identity, final T expected) { - identity.map(id -> assertThat(id).isEqualTo(expected)); - } - } From 4c85e56c803612faed22b63e2617be799d6e879c Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 7 Oct 2017 18:56:38 +0100 Subject: [PATCH 10/16] TypeAlias.map(): added --- src/main/java/net/kemitix/mon/TypeAlias.java | 16 +++++++++++++++- src/test/java/net/kemitix/mon/TypeAliasTest.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kemitix/mon/TypeAlias.java b/src/main/java/net/kemitix/mon/TypeAlias.java index 2dd5e6e..2f18f13 100644 --- a/src/main/java/net/kemitix/mon/TypeAlias.java +++ b/src/main/java/net/kemitix/mon/TypeAlias.java @@ -21,6 +21,8 @@ package net.kemitix.mon; +import java.util.function.Function; + /** * Type Alias for other types. * @@ -45,6 +47,19 @@ public abstract class TypeAlias { this.value = value; } + + /** + * Map the TypeAlias into another value. + * + * @param f the function to create the new value + * @param the type of the new value + * + * @return a TypeAlias + */ + public R map(final Function f) { + return f.apply(value); + } + @Override public final int hashCode() { return value.hashCode(); @@ -71,5 +86,4 @@ public abstract class TypeAlias { public final T getValue() { return value; } - } diff --git a/src/test/java/net/kemitix/mon/TypeAliasTest.java b/src/test/java/net/kemitix/mon/TypeAliasTest.java index 069c6ab..b6fb753 100644 --- a/src/test/java/net/kemitix/mon/TypeAliasTest.java +++ b/src/test/java/net/kemitix/mon/TypeAliasTest.java @@ -2,6 +2,8 @@ package net.kemitix.mon; import org.junit.Test; +import java.util.function.Function; + import static org.assertj.core.api.Assertions.assertThat; public class TypeAliasTest { @@ -59,10 +61,23 @@ public class TypeAliasTest { public void shouldHaveSameToStringAsAliasedType() throws Exception { //given final String value = "value"; + //when final AnAlias anAlias = AnAlias.of(value); + //then assertThat(anAlias.toString()).isEqualTo(value); } + @Test + public void shouldMapTypeAlias() { + //given + final AnAlias anAlias = AnAlias.of("text"); + final Function function = v -> v; + //when + final String value = anAlias.map(function); + //then + assertThat(value).isEqualTo("text"); + } + private static class AnAlias extends TypeAlias { /** From 1e8941b0303faf7bb5e923cbeedc1129adca93dc Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 19 Oct 2017 18:42:55 +0100 Subject: [PATCH 11/16] TypeAlias: allow getValue() to be overridden --- src/main/java/net/kemitix/mon/TypeAlias.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/kemitix/mon/TypeAlias.java b/src/main/java/net/kemitix/mon/TypeAlias.java index 2f18f13..ce3cb5f 100644 --- a/src/main/java/net/kemitix/mon/TypeAlias.java +++ b/src/main/java/net/kemitix/mon/TypeAlias.java @@ -83,7 +83,7 @@ public abstract class TypeAlias { * * @return the value */ - public final T getValue() { + public T getValue() { return value; } } From b5b11982e1afe0bd3a98e901bfe275aa44426dd5 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 19 Oct 2017 18:45:45 +0100 Subject: [PATCH 12/16] TypeAlias: prevent map() from being overridden --- src/main/java/net/kemitix/mon/TypeAlias.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/net/kemitix/mon/TypeAlias.java b/src/main/java/net/kemitix/mon/TypeAlias.java index ce3cb5f..f5e7636 100644 --- a/src/main/java/net/kemitix/mon/TypeAlias.java +++ b/src/main/java/net/kemitix/mon/TypeAlias.java @@ -47,7 +47,6 @@ public abstract class TypeAlias { this.value = value; } - /** * Map the TypeAlias into another value. * @@ -56,7 +55,7 @@ public abstract class TypeAlias { * * @return a TypeAlias */ - public R map(final Function f) { + public final R map(final Function f) { return f.apply(value); } From ccc0c914738535e41646bd5e5b54b4b81a8ce06d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 19 Oct 2017 19:38:15 +0100 Subject: [PATCH 13/16] Prepare for 0.2.0 release * Update CHANGELOG * Use `kemitix-parent` 4.0.0 * Make dependency versions properties --- CHANGELOG | 8 ++++++++ pom.xml | 13 +++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 980a0fc..893b4f3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,14 @@ CHANGELOG ========= +0.2.0 +----- + +* `TypeAlias.getValue()` is not `final` +* Added `TypeAlias.map()` +* `Mon.map()` and `Mon.flatMap()` are `final` +* Codacy Quality clean up + 0.1.0 ----- diff --git a/pom.xml b/pom.xml index ab55cb9..9bb2f61 100644 --- a/pom.xml +++ b/pom.xml @@ -7,22 +7,27 @@ net.kemitix kemitix-parent - 3.2.4 + 4.0.0 mon - 0.2.0-SNAPSHOT + 0.2.0 + + + 4.12 + 3.8.0 + junit junit - 4.12 + ${junit.version} test org.assertj assertj-core - 3.8.0 + ${assertj-core.version} test From f008db92f9e7971e01bde9af1d2a0047d1ecc26a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 19 Oct 2017 22:19:07 +0100 Subject: [PATCH 14/16] README.md: add TypeAlias heading --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 954e59f..70333f7 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ TypeAlias for Java ## Usage +### TypeAlias + ```java class Goal extends TypeAlias { private Goal(final String goal) { From d7acef3025b1295ee059c72ad158f767694c9f8b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 19 Oct 2017 22:38:23 +0100 Subject: [PATCH 15/16] pom.xml: revert kemitix-parent to 3.2.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9bb2f61..67fe99e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ net.kemitix kemitix-parent - 4.0.0 + 3.2.4 mon 0.2.0 From 5ea43d3406d0c476590a3ef94399c5ad964288ca Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 19 Oct 2017 22:47:45 +0100 Subject: [PATCH 16/16] .travis.yml: clean up unused env.global --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d1d54a..1f3bfa4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,5 +14,3 @@ deploy: script: sh .travis-support/deploy.sh on: branch: master -env: - global: