[Schmitzm-commits] r1892 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Fri Mar 9 21:13:05 CET 2012


Author: alfonx
Date: 2012-03-09 21:13:04 +0100 (Fri, 09 Mar 2012)
New Revision: 1892

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
Log:

	/**
	 * Zerlegt eine Liste in mehrere Listen mit einer maximalen Gr?\195?\182?\195?\159e.
	 */
	public static List<List> splitList(List list, int maxListSize) 

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2012-03-08 14:35:54 UTC (rev 1891)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2012-03-09 20:13:04 UTC (rev 1892)
@@ -43,6 +43,7 @@
 import java.text.NumberFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collection;
@@ -50,6 +51,7 @@
 import java.util.Comparator;
 import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.List;
 import java.util.Locale;
 import java.util.TimeZone;
 import java.util.TreeSet;
@@ -2267,4 +2269,26 @@
 		// else
 		// return String.format("%02d:%02d:%02d.%03d", days, hr, min, sec, ms);
 	}
+
+	/**
+	 * Zerlegt eine Liste in mehrere Listen mit einer maximalen Größe.
+	 */
+	public static List<List> splitList(List list, int maxListSize) {
+		List<List> splittedList = new ArrayList<List>();
+		int itemsRemaining = list.size();
+		int start = 0;
+
+		while (itemsRemaining != 0) {
+			int end = itemsRemaining >= maxListSize ? (start + maxListSize) : start + itemsRemaining;
+
+			splittedList.add(list.subList(start, end));
+
+			int sizeOfFinalList = end - start;
+			itemsRemaining = itemsRemaining - sizeOfFinalList;
+			start = start + sizeOfFinalList;
+		}
+
+		return splittedList;
+	}
+
 }



More information about the Schmitzm-commits mailing list