cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject cayenne git commit: CAY-2136 Allow orderedList(..) to accept Collection. Tests.
Date Thu, 10 Nov 2016 12:59:24 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 2b7a21b5b -> 0a1278d9a


CAY-2136 Allow orderedList(..) to accept Collection. Tests.


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/0a1278d9
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/0a1278d9
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/0a1278d9

Branch: refs/heads/master
Commit: 0a1278d9a938f02cc0cff3a55345a3eeda32f79f
Parents: 2b7a21b
Author: hugith <hugi@karlmenn.is>
Authored: Thu Nov 10 12:39:36 2016 +0000
Committer: hugith <hugi@karlmenn.is>
Committed: Thu Nov 10 12:39:36 2016 +0000

----------------------------------------------------------------------
 .../java/org/apache/cayenne/query/Ordering.java |  5 +-
 .../org/apache/cayenne/query/OrderingTest.java  | 62 ++++++++++++++++++++
 2 files changed, 65 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/0a1278d9/cayenne-server/src/main/java/org/apache/cayenne/query/Ordering.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/Ordering.java b/cayenne-server/src/main/java/org/apache/cayenne/query/Ordering.java
index 94f495d..0a3d156 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/Ordering.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/Ordering.java
@@ -23,6 +23,7 @@ import java.io.PrintWriter;
 import java.io.Serializable;
 import java.io.StringWriter;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
@@ -71,7 +72,7 @@ public class Ordering implements Comparator<Object>, Serializable,
XMLSerializab
 	 * 
 	 * @since 4.0
 	 */
-	public static <E> List<E> orderedList(List<E> objects, List<? extends
Ordering> orderings) {
+	public static <E> List<E> orderedList(Collection<E> objects, List<?
extends Ordering> orderings) {
 		List<E> newList = new ArrayList<E>(objects);
 		
 		orderList(newList, orderings);
@@ -332,7 +333,7 @@ public class Ordering implements Comparator<Object>, Serializable,
XMLSerializab
 	/**
 	 * @since 4.0
 	 */
-	public <E> List<E> orderedList(List<E> objects) {
+	public <E> List<E> orderedList(Collection<E> objects) {
 		List<E> newList = new ArrayList<E>(objects);
 		
 		orderList(newList);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/0a1278d9/cayenne-server/src/test/java/org/apache/cayenne/query/OrderingTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/OrderingTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/OrderingTest.java
index cd2279c..b32a8dc 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/query/OrderingTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/query/OrderingTest.java
@@ -25,6 +25,8 @@ import org.junit.Test;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
@@ -195,4 +197,64 @@ public class OrderingTest {
         assertEquals(list.get(1), orderedList.get(4));
         assertEquals(list.get(0), orderedList.get(5));
     }
+    
+    @Test
+    public void testOrderedListInstanceMethod() {
+    	Collection<TstBean> set = new HashSet<TstBean>(6);
+    	
+    	TstBean shouldBe0 = new TstBean("a", 0);
+    	TstBean shouldBe1 = new TstBean("b", 0);
+    	TstBean shouldBe2 = new TstBean("c", 0);
+    	TstBean shouldBe3 = new TstBean("d", 0);
+    	TstBean shouldBe4 = new TstBean("f", 0);
+    	TstBean shouldBe5 = new TstBean("r", 0);
+    	
+    	set.add(shouldBe1);
+    	set.add(shouldBe0);
+    	set.add(shouldBe5);
+    	set.add(shouldBe3);
+    	set.add(shouldBe2);
+    	set.add(shouldBe4);
+    	
+    	List<TstBean> orderedList = new Ordering("string", SortOrder.ASCENDING).orderedList(set);
+    	
+    	assertEquals(shouldBe0, orderedList.get(0));
+    	assertEquals(shouldBe1, orderedList.get(1));
+    	assertEquals(shouldBe2, orderedList.get(2));
+    	assertEquals(shouldBe3, orderedList.get(3));
+    	assertEquals(shouldBe4, orderedList.get(4));
+    	assertEquals(shouldBe5, orderedList.get(5));
+    }
+    
+    @Test
+    public void testOrderedListStaticMethod() {
+        Collection<TstBean> set = new HashSet<TstBean>(6);
+
+        TstBean shouldBe0 = new TstBean("a", 5);
+        TstBean shouldBe1 = new TstBean("b", 5);
+        TstBean shouldBe2 = new TstBean("b", 2);
+        TstBean shouldBe3 = new TstBean("b", 1);
+        TstBean shouldBe4 = new TstBean("c", 30);
+        TstBean shouldBe5 = new TstBean("c", 1);
+
+        set.add(shouldBe0);
+        set.add(shouldBe5);
+        set.add(shouldBe3);
+        set.add(shouldBe1);
+        set.add(shouldBe4);
+        set.add(shouldBe2);
+        
+        List<Ordering> orderings = new ArrayList<Ordering>(2);
+        orderings.add(new Ordering("string", SortOrder.ASCENDING));
+        orderings.add(new Ordering("integer", SortOrder.DESCENDING));
+
+        List<TstBean> orderedList = Ordering.orderedList(set, orderings);
+        
+        assertEquals(shouldBe0, orderedList.get(0));
+        assertEquals(shouldBe1, orderedList.get(1));
+        assertEquals(shouldBe2, orderedList.get(2));
+        assertEquals(shouldBe3, orderedList.get(3));
+        assertEquals(shouldBe4, orderedList.get(4));
+        assertEquals(shouldBe5, orderedList.get(5));
+    }
 }


Mime
View raw message