cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [1/2] cayenne git commit: Added orderList and orderedList
Date Tue, 05 Apr 2016 09:02:10 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 4bdff812c -> 277070189


Added orderList and orderedList


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

Branch: refs/heads/master
Commit: 46b45279e5c6fba5b352c777927388298e73f9c3
Parents: 4bdff81
Author: Lon Varscsak <lon.varscsak@gmail.com>
Authored: Mon Apr 4 18:29:20 2016 -0700
Committer: Lon Varscsak <lon.varscsak@gmail.com>
Committed: Mon Apr 4 18:29:20 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/cayenne/query/Ordering.java | 25 ++++++++++++++++++++
 1 file changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/46b45279/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 ccd7a58..bcb5f9e 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
@@ -22,6 +22,7 @@ package org.apache.cayenne.query;
 import java.io.PrintWriter;
 import java.io.Serializable;
 import java.io.StringWriter;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
@@ -62,6 +63,20 @@ public class Ordering implements Comparator<Object>, Serializable,
XMLSerializab
 		Collections.sort(objects, ComparatorUtils.chainedComparator(orderings));
 	}
 
+	/**
+	 * Orders a given list of objects, using a List of Orderings applied
+	 * according the default iteration order of the Orderings list. I.e. each
+	 * Ordering with lower index is more significant than any other Ordering
+	 * with higher index. List being ordered is modified in place.
+	 */
+	public static <E> List<E> orderedList(List<E> objects, List<? extends
Ordering> orderings) {
+		List<E> newList = new ArrayList<E>(objects);
+		
+		orderList(newList, orderings);
+		
+		return newList;
+	}
+	
 	public Ordering() {
 	}
 
@@ -312,10 +327,19 @@ public class Ordering implements Comparator<Object>, Serializable,
XMLSerializab
 		Collections.sort(objects, this);
 	}
 
+	public <E> List<E> orderedList(List<E> objects) {
+		List<E> newList = new ArrayList<E>(objects);
+		
+		orderList(newList);
+		
+		return newList;
+	}
+
 	/**
 	 * Comparable interface implementation. Can compare two Java Beans based on
 	 * the stored expression.
 	 */
+	@Override
 	public int compare(Object o1, Object o2) {
 		Expression exp = getSortSpec();
 		Object value1 = null;
@@ -367,6 +391,7 @@ public class Ordering implements Comparator<Object>, Serializable,
XMLSerializab
 	 * 
 	 * @since 1.1
 	 */
+	@Override
 	public void encodeAsXML(XMLEncoder encoder) {
 		encoder.print("<ordering");
 


Mime
View raw message