summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-05-07 03:11:43 (EDT)
committerStefan Liebig2008-05-07 03:11:43 (EDT)
commit36ea64e78b3a8f5524b9fe2100749333606e31c7 (patch)
treef85c8cf6b05d643b49eed1d0a230bf751064eabb
parent35a613febc0c34e219d13c8a20c902366e385b53 (diff)
downloadorg.eclipse.riena-36ea64e78b3a8f5524b9fe2100749333606e31c7.zip
org.eclipse.riena-36ea64e78b3a8f5524b9fe2100749333606e31c7.tar.gz
org.eclipse.riena-36ea64e78b3a8f5524b9fe2100749333606e31c7.tar.bz2
*** empty log message ***
-rw-r--r--org.eclipse.riena.core/src/org/eclipse/riena/core/util/StringUtils.java72
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/core/util/StringUtilsTest.java71
2 files changed, 143 insertions, 0 deletions
diff --git a/org.eclipse.riena.core/src/org/eclipse/riena/core/util/StringUtils.java b/org.eclipse.riena.core/src/org/eclipse/riena/core/util/StringUtils.java
new file mode 100644
index 0000000..3554b5a
--- /dev/null
+++ b/org.eclipse.riena.core/src/org/eclipse/riena/core/util/StringUtils.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2008 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.util;
+
+/**
+ * Collection of String/CharSequence utilities.
+ */
+public final class StringUtils {
+
+ private StringUtils() {
+ // Utility class
+ }
+
+ /**
+ * Tests ´simple´ emptiness. A character sequence is empty either if it is
+ * null or it has a zero length.
+ *
+ * @param sequence
+ * @return
+ */
+ public static final boolean isEmpty(final CharSequence sequence) {
+ return sequence == null || sequence.length() == 0;
+ }
+
+ /**
+ * Tests whether the char sequence has content. A character sequence is
+ * given either if it is not null and it has a none zero length.
+ *
+ * @param sequence
+ * @return
+ */
+ public static final boolean isGiven(final CharSequence sequence) {
+ return sequence != null && sequence.length() != 0;
+ }
+
+ /**
+ * Tests ´deep´ emptiness. A string is empty if it is either null or its
+ * trimmed version has a zero length.
+ *
+ * @param string
+ * @return
+ */
+ public static final boolean isDeepEmpty(final String string) {
+ return string == null || string.trim().length() == 0;
+ }
+
+ /**
+ * Tests equality of the given strings.
+ *
+ * @param sequence1
+ * candidate 1, may be null
+ * @param sequence2
+ * candidate 2, may be null
+ * @return
+ */
+ public static final boolean equals(final CharSequence sequence1, final CharSequence sequence2) {
+ if (sequence1 == sequence2)
+ return true;
+ if (sequence1 == null || sequence2 == null)
+ return false;
+ return sequence1.equals(sequence2);
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/core/util/StringUtilsTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/core/util/StringUtilsTest.java
new file mode 100644
index 0000000..b6c4f44
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/core/util/StringUtilsTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2008 compeople AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.core.util;
+
+import junit.framework.TestCase;
+
+/**
+ * Nomen est omen!
+ */
+public class StringUtilsTest extends TestCase {
+
+ /**
+ * Nomen est omen!
+ */
+ public void testIsEmpty() {
+ assertTrue(StringUtils.isEmpty(null));
+ assertTrue(StringUtils.isEmpty(""));
+ assertFalse(StringUtils.isEmpty(" "));
+ assertFalse(StringUtils.isEmpty(" a "));
+ }
+
+ /**
+ * Nomen est omen!
+ */
+ public void testIsGiven() {
+ assertFalse(StringUtils.isGiven(null));
+ assertFalse(StringUtils.isGiven(""));
+ assertTrue(StringUtils.isGiven(" "));
+ assertTrue(StringUtils.isGiven(" a "));
+ }
+
+ /**
+ * Nomen est omen!
+ */
+ public void testIsDeepEmpty() {
+ assertTrue(StringUtils.isDeepEmpty(null));
+ assertTrue(StringUtils.isDeepEmpty(""));
+ assertTrue(StringUtils.isDeepEmpty(" "));
+ assertFalse(StringUtils.isDeepEmpty(" a "));
+ }
+
+ /**
+ * Nomen est omen!
+ */
+ public void testEquals() {
+ assertTrue(StringUtils.equals(null, null));
+
+ assertFalse(StringUtils.equals(null, ""));
+ assertFalse(StringUtils.equals("", null));
+
+ String c = "c";
+ assertTrue(StringUtils.equals(c, c));
+
+ assertTrue(StringUtils.equals("c", "c"));
+
+ assertFalse(StringUtils.equals(null, "a"));
+ assertFalse(StringUtils.equals("a", null));
+
+ assertFalse(StringUtils.equals("b", "a"));
+ assertFalse(StringUtils.equals("a", "b"));
+
+ }
+}