# HG changeset patch # User tatsuki # Date 1432014066 -32400 # Node ID 71624cf77dbfc0ec2b2b2ab3d8c5745b5aad5e83 # Parent f06dc60bd70f3a843f4500d2223b9edaf7fffc67 change complete list diff -r f06dc60bd70f -r 71624cf77dbf src/main/java/jp/ac/u_ryukyu/ie/cr/list/List.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/list/List.java Tue May 19 13:09:47 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/list/List.java Tue May 19 14:41:06 2015 +0900 @@ -12,7 +12,7 @@ final private int listLength; public List() { - this.head = new headNode(null); + this.head = new headNode(); this.listLength = 0; } @@ -22,12 +22,12 @@ list = list.addLast(attribute); } this.head = list.getHead(); - this.listLength = head.getNext().getNum(); + this.listLength = head.getNext().getNum() + 1; } private List(Node head) { this.head = head; - this.listLength = head.getNext().getNum(); + this.listLength = head.getNext().getNum() + 1; } public Node getHead() { @@ -35,15 +35,14 @@ } public List add(int num, T attribute) { - Node newNode = head.getNext().add(num, attribute); - if (newNode == null) + Node newHead = head.add(num, attribute); + if (newHead == null) return this; - Node newHead = new headNode<>(newNode); return new List(newHead); } public List addLast(T attribute) { - Node newNode = new DefaultNode(attribute, listLength + 1, head.getNext()); + Node newNode = new DefaultNode(attribute, listLength, head.getNext()); Node newHead = new headNode(newNode); return new List(newHead); } @@ -107,10 +106,9 @@ } public List replace(int num, T attribute) { - Node newNode = head.getNext().replaceNode(num, attribute); - if (newNode == null) + Node newHead = head.replaceNode(num, attribute); + if (newHead == null) return this; - Node newHead = new headNode<>(newNode); return new List(newHead); } @@ -119,15 +117,15 @@ } public T head() { - return index(1); + return index(0); } public List deleteLast() { - return delete(listLength); + return delete(listLength - 1); } public List deleteHead() { - return delete(1); + return delete(0); } public int length() { diff -r f06dc60bd70f -r 71624cf77dbf src/main/java/jp/ac/u_ryukyu/ie/cr/list/TailNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/list/TailNode.java Tue May 19 14:41:06 2015 +0900 @@ -0,0 +1,38 @@ +package jp.ac.u_ryukyu.ie.cr.list; + +/** + * Created by e115731 on 15/05/19. + */ +public class TailNode implements Node { + + @Override + public int getNum() { + return -1; + } + + @Override + public Node getNext() { + return null; + } + + @Override + public T getAttribute() { + return null; + } + + @Override + public Node add(int num, T attribute) { + return null; + } + + @Override + public Node delete(int num) { + return null; + } + + @Override + public Node replaceNode(int num, T attribute) { + return null; + } + +} diff -r f06dc60bd70f -r 71624cf77dbf src/main/java/jp/ac/u_ryukyu/ie/cr/list/headNode.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/list/headNode.java Tue May 19 13:09:47 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/list/headNode.java Tue May 19 14:41:06 2015 +0900 @@ -6,6 +6,11 @@ public class headNode implements Node { private final Node next; + + public headNode() { + this.next = new TailNode(); + } + public headNode(Node next) { this.next = next; } @@ -15,8 +20,6 @@ } public Node getNext() { - if (next == null) - return this; return next; } @@ -25,11 +28,21 @@ } public Node add(int num, T attribute) { - if (num == 0) { - return new DefaultNode<>(attribute, num, this); + if (next.getNum() == num - 1) { + Node newNode = new DefaultNode<>(attribute, num, next); + return new headNode(newNode); } - return null; + if (next.getNum() == num) { + Node newNode = new DefaultNode(attribute, num, next.getNext()); + Node newNext = new DefaultNode(next.getAttribute(), num++, newNode); + return new headNode(newNext); + } + + Node newNode = next.add(num, attribute); + if (newNode == null) + return this; + return new headNode(newNode); } public Node delete(int deleteNum) { @@ -45,6 +58,15 @@ @Override public Node replaceNode(int num, T attribute) { - return null; + Node nextNode = getNext(); + if (nextNode.getNum() == num) { + Node newNode = new DefaultNode(attribute, num, nextNode.getNext()); + return new headNode(newNode); + } + + Node newNode = next.replaceNode(num, attribute); + if (newNode == null) + return this; + return new headNode(newNode); } } diff -r f06dc60bd70f -r 71624cf77dbf src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Tue May 19 13:09:47 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultTreeEditor.java Tue May 19 14:41:06 2015 +0900 @@ -48,7 +48,7 @@ } // target - Direction targetDirection = path.head(); + Direction targetDirection = path.last(); TreeNode target = targetDirection.getTarget(); Either either = editor.edit(target); if(either.isA()){ diff -r f06dc60bd70f -r 71624cf77dbf src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/deleteTest.java --- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/deleteTest.java Tue May 19 13:09:47 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/deleteTest.java Tue May 19 14:41:06 2015 +0900 @@ -12,7 +12,7 @@ public void deleteTest() { List list = new List(); - for (int count = 1; count <= 10; count++) { + for (int count = 0; count < 10; count++) { list = list.addLast(count); } @@ -23,8 +23,8 @@ Assert.assertEquals(attribute,2); Assert.assertEquals(newList.length(),8); newList = newList.deleteLast(); - attribute = newList.index(7); - Assert.assertEquals(attribute,9); + attribute = newList.index(6); + Assert.assertEquals(attribute,8); Assert.assertEquals(list.length(),10); } } diff -r f06dc60bd70f -r 71624cf77dbf src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/listAdd.java --- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/listAdd.java Tue May 19 13:09:47 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/listAdd.java Tue May 19 14:41:06 2015 +0900 @@ -13,8 +13,18 @@ public void listAddTest() { List list = new List(); - for (int count = 1; count <= 10; count++) { + List list2 = new List(); + + for (int count = 0; count < 10; count++) { list = list.addLast(count); + list2 = list2.add(count, count); + } + + for (int count = 0; count < 10; count++) { + int num = list.index(count); + int num2 = list2.index(count); + Assert.assertEquals(num,count); + Assert.assertEquals(num2,count); } Assert.assertEquals(list.length(), 10); int num = list.index(5); diff -r f06dc60bd70f -r 71624cf77dbf src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/replaceTest.java --- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/replaceTest.java Tue May 19 13:09:47 2015 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/list/replaceTest.java Tue May 19 14:41:06 2015 +0900 @@ -11,7 +11,7 @@ @Test public void replaceTest() { List list = new List(); - for (int count = 1; count <= 10; count++) { + for (int count = 0; count < 10; count++) { list = list.addLast(count); } List newList = list.replace(5, 15);