Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 204:ce00e580cc44
List implement append
author | tatsuki |
---|---|
date | Tue, 19 May 2015 12:07:24 +0900 |
parents | 1833956aea55 |
children | 89df000def32 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/list/List.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/DefaultOperationLog.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/appendTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/listAdd.java |
diffstat | 4 files changed, 51 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/list/List.java Tue May 19 11:31:59 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/list/List.java Tue May 19 12:07:24 2015 +0900 @@ -72,7 +72,7 @@ stack.push(currentNode.getAttribute()); currentNode = currentNode.getNext(); } - return new Iterator<T>(){ + return new Iterator<T>() { @Override public boolean hasNext() { @@ -124,12 +124,12 @@ } @Override - public String toString(){ + public String toString() { String pathString = "<"; Iterator<T> iterator = reverseIterator(); while (true) { pathString += iterator.next(); - if(iterator.hasNext()) + if (iterator.hasNext()) pathString += ","; else break; @@ -137,4 +137,14 @@ pathString += ">"; return pathString; } + + public List<T> append(List<T> list) { + Iterator<T> iterator = list.reverseIterator(); + List<T> newList = this; + while (iterator.hasNext()) { + T attribute = iterator.next(); + newList = newList.addLast(attribute); + } + return newList; + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/DefaultOperationLog.java Tue May 19 11:31:59 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/DefaultOperationLog.java Tue May 19 12:07:24 2015 +0900 @@ -1,10 +1,10 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; +import fj.data.List; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; + import java.util.Iterator; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; -import fj.data.List; - public class DefaultOperationLog implements OperationLog { private final List<NodeOperation> log;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/appendTest.java Tue May 19 12:07:24 2015 +0900 @@ -0,0 +1,35 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.list; + +import jp.ac.u_ryukyu.ie.cr.list.List; +import junit.framework.Assert; +import org.junit.Test; + +import java.util.Iterator; + +/** + * Created by e115731 on 15/05/19. + */ +public class appendTest { + @Test + public void appendTest() { + + List<Integer> list = new List<>(); + for (int count = 1; count <= 10; count++) { + list = list.addLast(count); + } + + List<Integer> list2 = new List<>(); + for (int count = 11; count <= 20; count++) { + list2 = list2.addLast(count); + } + + List<Integer> newList = list.append(list2); + Iterator<Integer> iterator = newList.reverseIterator(); + for (int count = 1; count <= 20; count++) { + Assert.assertTrue(iterator.hasNext()); + int num = iterator.next(); + Assert.assertEquals(num, count); + } + + } +}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/listAdd.java Tue May 19 11:31:59 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/listAdd.java Tue May 19 12:07:24 2015 +0900 @@ -12,27 +12,18 @@ @Test public void listAddTest() { - fj.data.List<Integer> test = fj.data.List.list(-1); - for (int count = 1; count <= 10; count++) { - test = test.cons(count); - } - int aaa = test.head(); - test = test.tail(); List<Integer> list = new List<Integer>(); - for (int count = 1; count <= 10; count++) { list = list.addLast(count); } Assert.assertEquals(list.length(), 10); int num = list.index(5); Assert.assertEquals(num, 5); - List<Integer> newList = list.add(5, 1000); num = newList.index(5); Assert.assertEquals(num, 1000); num = list.index(5); Assert.assertEquals(num, 5); - list = list.add(1000, 1001); num = list.index(5); Assert.assertEquals(num, 5);