Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58c83c9
commit e2471ab
Showing
8 changed files
with
1,360 additions
and
143 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
1,015 changes: 1,015 additions & 0 deletions
1,015
src/main/java/com/logicalpractice/persistentcollections/PersistentHashMap.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/logicalpractice/persistentcollections/PersistentMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.logicalpractice.persistentcollections; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* | ||
*/ | ||
public interface PersistentMap<K,V> extends Map<K,V> { | ||
|
||
PersistentMap<K,V> with(K key, V value); | ||
|
||
TransientMap<K,V> toTransientMap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/logicalpractice/persistentcollections/TransientMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.logicalpractice.persistentcollections; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* | ||
*/ | ||
public interface TransientMap<K,V> extends Map<K,V> { | ||
|
||
PersistentMap<K,V> toPersistentMap(); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/logicalpractice/persistentcollections/Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.logicalpractice.persistentcollections; | ||
|
||
/** | ||
* | ||
*/ | ||
public class Util { | ||
|
||
public static boolean equals(Object lhs, Object rhs){ | ||
return (lhs == rhs) || (lhs != null && lhs.equals(rhs)); | ||
} | ||
|
||
public static int hashCode(Object o) { | ||
return o == null ? 1 : o.hashCode(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/com/logicalpractice/persistentcollections/UtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.logicalpractice.persistentcollections; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* | ||
*/ | ||
public class UtilTest { | ||
|
||
@Test | ||
public void testEquals() throws Exception { | ||
assertTrue(Util.equals(null, null)); | ||
assertTrue(Util.equals("Thing", "Thing")); // same reference | ||
|
||
assertFalse(Util.equals("Thing", null)); | ||
assertFalse(Util.equals(null, "null")); | ||
} | ||
|
||
@SuppressWarnings("RedundantStringConstructorCall") | ||
@Test | ||
public void testEquals2() throws Exception { | ||
assertTrue(Util.equals(new String("Thing"), new String("Thing"))); // not same reference | ||
assertFalse(Util.equals(new String("foo"), new String("bar"))); | ||
} | ||
|
||
@Test | ||
public void testHashCode() throws Exception { | ||
|
||
} | ||
} |