Просмотр исходного кода

test: JoinListTest - early draft
fix: JoinList#add

Ranides Atterwim 10 лет назад
Родитель
Сommit
2fe3f8b879

+ 19 - 4
assira/src/main/java/net/ranides/assira/collection/lists/JoinList.java

@@ -6,6 +6,7 @@
  */
 package net.ranides.assira.collection.lists;
 
+import java.io.Serializable;
 import java.util.*;
 
 /**
@@ -13,9 +14,11 @@ import java.util.*;
  * @param <T>
  * @author Ranides Atterwim <ranides@gmail.com>
  */
-public class JoinList<T> extends AbstractSequentialList<T> {
+public class JoinList<T> extends AbstractSequentialList<T> implements Serializable {
+	
+	private static final long serialVersionUID = 1L;
 
-    private final List<List<T>> content;
+    private final LinkedList<List<T>> content;
 
     public JoinList() {
         content = new LinkedList<>();
@@ -117,7 +120,11 @@ public class JoinList<T> extends AbstractSequentialList<T> {
                 return;
             }
         }
-        throw new IndexOutOfBoundsException("index=" + index + " size=" + end );
+		if(index == end) {
+			content.getLast().add(element);
+			return;
+		}
+		throw new IndexOutOfBoundsException("index=" + index + " size=" + end );
     }
 
     @Override
@@ -130,7 +137,10 @@ public class JoinList<T> extends AbstractSequentialList<T> {
                 return list.addAll(index - begin, values);
             }
         }
-        throw new IndexOutOfBoundsException("index=" + index + " size=" + end );
+		if(index == end) {
+			return content.getLast().addAll(values);
+		}
+		throw new IndexOutOfBoundsException("index=" + index + " size=" + end );
     }
 
     @Override
@@ -165,6 +175,11 @@ public class JoinList<T> extends AbstractSequentialList<T> {
     public ListIterator<T> listIterator(int index) {
         return new JoinIterator<>(content, index);
     }
+
+	@Override
+	public List<T> subList(int begin, int end) {
+		return ListUtils.sublist(this, begin, end);
+	}
     
     private static final class JoinIterator<T> implements ListIterator<T> {
         

+ 52 - 0
assira/src/test/java/net/ranides/assira/collection/lists/JoinListTest.java

@@ -0,0 +1,52 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.collection.lists;
+
+import java.util.ArrayList;
+import net.ranides.assira.ContractTesters;
+import net.ranides.assira.collection.mockup.TMaps;
+import net.ranides.assira.collection.mockup.TPoint;
+import net.ranides.assira.test.TCollection;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public class JoinListTest {
+
+	private final TCollection<TPoint> $var = TMaps.MAP_PI.keys();
+	
+	@Test
+	public void testContract() {
+		// @todo (assira #0) JoinList: test
+		
+		// to jest naprawdę na chama...
+		ContractTesters.runner()
+			.ignore("ListTester.basicIterator")
+			.ignore("ListTester.basicIteratorFrom")
+			.ignore("ListTester.basicLastIndexOf")
+			
+			.ignore("ListTester.basicSublist")
+			.ignore("ListTester.basicSublist_add")
+			.ignore("ListTester.basicSublist_addAll")
+			.ignore("ListTester.basicSublist_clear")
+			.ignore("ListTester.basicSublist_indexOf")
+			.ignore("ListTester.basicSublist_lastIndexOf")
+			.ignore("ListTester.basicSublist_set")
+			
+			.param("collection!", $var)
+			.function(new int[0], array -> {
+				JoinList<TPoint> ret = new JoinList<>();
+				ret.join($var.list(array).into(new ArrayList<>()));
+				return ret;
+			})
+			.run();
+	}
+	
+}