diff --git a/CHANGELOG b/CHANGELOG
index 893b4f3..123b8df 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
CHANGELOG
=========
+0.3.0
+-----
+
+* `TypeAlias.getValue()` removed in favour of using `map()`
+
0.2.0
-----
diff --git a/README.md b/README.md
index 70333f7..dd342cd 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ TypeAlias for Java
net.kemitix
mon
- ${mon.version}
+ 0.3.0
```
diff --git a/pom.xml b/pom.xml
index 67fe99e..58bac15 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
3.2.4
mon
- 0.2.0
+ 0.3.0
4.12
diff --git a/src/main/java/net/kemitix/mon/TypeAlias.java b/src/main/java/net/kemitix/mon/TypeAlias.java
index f5e7636..f5dc0c5 100644
--- a/src/main/java/net/kemitix/mon/TypeAlias.java
+++ b/src/main/java/net/kemitix/mon/TypeAlias.java
@@ -38,13 +38,20 @@ public abstract class TypeAlias {
*/
private final T value;
+ private final Class super T> type;
+
/**
* Constructor.
*
* @param value the value
+ * @param type the type of the value
*/
- protected TypeAlias(final T value) {
+ protected TypeAlias(
+ final T value,
+ final Class super T> type
+ ) {
this.value = value;
+ this.type = type;
}
/**
@@ -56,25 +63,30 @@ public abstract class TypeAlias {
* @return a TypeAlias
*/
public final R map(final Function f) {
- return f.apply(value);
+ return f.apply(getValue());
}
@Override
public final int hashCode() {
- return value.hashCode();
+ return getValue().hashCode();
}
@Override
+ @SuppressWarnings("unchecked")
public final boolean equals(final Object o) {
if (o instanceof TypeAlias) {
- return value.equals(((TypeAlias) o).value);
+ if (((TypeAlias) o).type.equals(type)) {
+ return ((TypeAlias) o).map(getValue()::equals);
+ } else {
+ return false;
+ }
}
- return value.equals(o);
+ return map(o::equals);
}
@Override
public final String toString() {
- return value.toString();
+ return getValue().toString();
}
/**
@@ -82,7 +94,7 @@ public abstract class TypeAlias {
*
* @return the value
*/
- public T getValue() {
+ private 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 b6fb753..41c4222 100644
--- a/src/test/java/net/kemitix/mon/TypeAliasTest.java
+++ b/src/test/java/net/kemitix/mon/TypeAliasTest.java
@@ -2,6 +2,7 @@ package net.kemitix.mon;
import org.junit.Test;
+import java.util.Collections;
import java.util.function.Function;
import static org.assertj.core.api.Assertions.assertThat;
@@ -13,10 +14,26 @@ public class TypeAliasTest {
//given
final String value = "value";
//when
- final TypeAlias typeAlias = new TypeAlias(value) {
+ final TypeAlias typeAlias = givenTypeAlias(value);
+ //then
+ assertThat(typeAlias.map(value::equals)).isTrue();
+ }
+
+ @Test
+ public void shouldCreateATypeAliasWithNestedGenericTypes() {
+ //given
+ final Iterable iterable = Collections.emptyList();
+ //when
+ final TypeAlias> typeAlias =
+ new TypeAlias>(iterable, Iterable.class) {
};
//then
- assertThat(typeAlias.getValue()).isEqualTo(value);
+ assertThat(typeAlias.map(iterable::equals)).isTrue();
+ }
+
+ private TypeAlias givenTypeAlias(final String value) {
+ return new TypeAlias(value, String.class) {
+ };
}
@Test
@@ -26,7 +43,16 @@ public class TypeAliasTest {
//when
final AnAlias anAlias = AnAlias.of(value);
//then
- assertThat(anAlias.getValue()).isEqualTo(value);
+ assertThat(anAlias.map(value::equals)).isTrue();
+ }
+
+ @Test
+ public void shouldNotBeEqualWhenValueTypesAreDifferent() {
+ //given
+ final TypeAlias stringTypeAlias = givenTypeAlias("1");
+ final TypeAlias integerTypeAlias = new TypeAlias(1, Integer.class){};
+ //then
+ assertThat(stringTypeAlias).isNotEqualTo(integerTypeAlias);
}
@Test
@@ -86,7 +112,7 @@ public class TypeAliasTest {
* @param value the value
*/
protected AnAlias(final String value) {
- super(value);
+ super(value, String.class);
}
protected static AnAlias of(final String value) {