Skip to content

Commit

Permalink
PesistentHashMap compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
tempredirect committed Mar 2, 2012
1 parent 58c83c9 commit e2471ab
Show file tree
Hide file tree
Showing 8 changed files with 1,360 additions and 143 deletions.
412 changes: 271 additions & 141 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1,015 changes: 1,015 additions & 0 deletions src/main/java/com/logicalpractice/persistentcollections/PersistentHashMap.java

Large diffs are not rendered by default.

Expand Up @@ -8,7 +8,7 @@
*/
public interface PersistentList<T> extends List<T>, RandomAccess {

PersistentList<T> withSet(int i, T val);
PersistentList<T> with(int i, T val);

PersistentList<T> withAppended(T val);

Expand Down
@@ -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();
}
Expand Up @@ -54,7 +54,7 @@ public Object[] arrayFor(int i) {
}

@Override
public PersistentList<T> withSet(int i, T val) {
public PersistentList<T> with(int i, T val) {
if (i >= 0 && i < cnt) {
if (i >= tailoff()) {
Object[] newTail = new Object[tail.length];
Expand Down
@@ -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 src/main/java/com/logicalpractice/persistentcollections/Util.java
@@ -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();
}
}
@@ -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 {

}
}

0 comments on commit e2471ab

Please sign in to comment.