[Schmitzm-commits] r1562 - in trunk/schmitzm-core/src: main/java/de/schmitzm/lang test/java/de/schmitzm/lang

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Apr 23 12:56:02 CEST 2011


Author: alfonx
Date: 2011-04-23 12:56:01 +0200 (Sat, 23 Apr 2011)
New Revision: 1562

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

	/**
	 * Entfernt alle <code>null</code> Werte aus einem Array.
	 * 
	 * @param withNulls
	 * @return withoutNulls
	 */
	public static <E> E[] removeNulls(E... withNulls) {
		E[] result = Arrays.copyOfRange(withNulls, 0, 0);
		// E[] result = withNulls.clone();
		for (E o : withNulls) {
			if (o != null)
				result = extendArray(result, o);
		}
		return result;
	}

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2011-04-22 22:39:38 UTC (rev 1561)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2011-04-23 10:56:01 UTC (rev 1562)
@@ -1785,4 +1785,20 @@
 			string = string.substring(0, string.length() - 1);
 		return string;
 	}
+
+	/**
+	 * Entfernt alle <code>null</code> Werte aus einem Array.
+	 * 
+	 * @param withNulls
+	 * @return withoutNulls
+	 */
+	public static <E> E[] removeNulls(E... withNulls) {
+		E[] result = Arrays.copyOfRange(withNulls, 0, 0);
+		// E[] result = withNulls.clone();
+		for (E o : withNulls) {
+			if (o != null)
+				result = extendArray(result, o);
+		}
+		return result;
+	}
 }

Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java	2011-04-22 22:39:38 UTC (rev 1561)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/lang/LangUtilTest.java	2011-04-23 10:56:01 UTC (rev 1562)
@@ -92,4 +92,23 @@
 		// Level.WARN, Logger.getLogger("org.hibernate").getLevel());
 	}
 
+	@Test
+	public void testRemoveNulls_Integer()
+	{
+		Integer[] withNuller = new Integer[] { 3, null, 5, null };
+		Integer[] withOutNulls = LangUtil.removeNulls(withNuller);
+		assertEquals(2, withOutNulls.length);
+		assertEquals(3, withOutNulls[0], 0);
+		assertEquals(5, withOutNulls[1], 0);
+	}
+
+	@Test
+	public void testRemoveNulls_Strings() {
+		String[] withNuller = new String[] { "s3", null, "s5", null };
+		String[] withOutNulls = LangUtil.removeNulls(withNuller);
+		assertEquals(2, withOutNulls.length);
+		assertEquals("s3", withOutNulls[0]);
+		assertEquals("s5", withOutNulls[1]);
+	}
+
 }
\ No newline at end of file



More information about the Schmitzm-commits mailing list