Bug 522083 - Simplify StringUtils classes
No need for multiple concat methods - just use varargs.
No need for split method - pre 1.4 JVM is not supported now.
Change-Id: I1c1e349746d7c817933c1451393b8abfd67ba37a
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/util/StringUtil.java b/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/util/StringUtil.java
index 3b57ab7..77eccf0 100644
--- a/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/util/StringUtil.java
+++ b/org.eclipse.ui.intro.universal/src/org/eclipse/ui/internal/intro/universal/util/StringUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2017 IBM Corporation 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
@@ -10,40 +10,13 @@
*******************************************************************************/
package org.eclipse.ui.internal.intro.universal.util;
-
-
public class StringUtil {
- public static StringBuffer concat(String string1, String string2,
- String string3) {
- StringBuffer buffer = new StringBuffer(string1);
- buffer.append(string2);
- buffer.append(string3);
- return buffer;
+ public static StringBuffer concat(String... strings) {
+ StringBuffer buffer = new StringBuffer();
+ for (String string : strings) {
+ buffer.append(string);
+ }
+ return buffer;
}
-
- public static StringBuffer concat(String string1, String string2,
- String string3, String string4) {
- StringBuffer buffer = concat(string1, string2, string3);
- buffer.append(string4);
- return buffer;
- }
-
- public static StringBuffer concat(String string1, String string2,
- String string3, String string4, String string5) {
- StringBuffer buffer = concat(string1, string2, string3, string4);
- buffer.append(string5);
- return buffer;
- }
-
- public static StringBuffer concat(String string1, String string2,
- String string3, String string4, String string5, String string6) {
- StringBuffer buffer = concat(string1, string2, string3, string4,
- string5);
- buffer.append(string6);
- return buffer;
- }
-
-
-
}
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroContainer.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroContainer.java
index 77b14dc..2af9ea2 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroContainer.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroContainer.java
@@ -20,7 +20,6 @@
import org.eclipse.ui.internal.intro.impl.model.loader.ExtensionPointManager;
import org.eclipse.ui.internal.intro.impl.util.IntroEvaluationContext;
import org.eclipse.ui.internal.intro.impl.util.Log;
-import org.eclipse.ui.internal.intro.impl.util.StringUtil;
import org.osgi.framework.Bundle;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -414,7 +413,7 @@
public AbstractIntroElement findTarget(AbstractIntroContainer container,
String path) {
// extract path segments. Get first segment to start search.
- String[] pathSegments = StringUtil.split(path, "/"); //$NON-NLS-1$
+ String[] pathSegments = path.split("/"); //$NON-NLS-1$
if (container == null)
return null;
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroElement.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroElement.java
index 13adf8c..1549c43 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroElement.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2016 IBM Corporation and others.
+ * Copyright (c) 2004, 2017 IBM Corporation 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
@@ -13,7 +13,6 @@
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.ui.internal.intro.impl.model.util.BundleUtil;
-import org.eclipse.ui.internal.intro.impl.util.StringUtil;
import org.osgi.framework.Bundle;
import org.w3c.dom.Element;
@@ -273,7 +272,7 @@
if (element.hasAttribute(att)) {
String value = element.getAttribute(att);
if (value!=null) {
- String[] splitValues = StringUtil.split(value, ","); //$NON-NLS-1$
+ String[] splitValues = value.split(","); //$NON-NLS-1$
IntroModelRoot root = getModelRoot();
if (root!=null) {
for (int i = 0; i < splitValues.length; i++) {
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java
index 9a8deee..2e19316 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java
@@ -30,7 +30,6 @@
import org.eclipse.ui.internal.intro.impl.model.util.ModelUtil;
import org.eclipse.ui.internal.intro.impl.util.IntroEvaluationContext;
import org.eclipse.ui.internal.intro.impl.util.Log;
-import org.eclipse.ui.internal.intro.impl.util.StringUtil;
import org.osgi.framework.Bundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -764,7 +763,7 @@
Object[] results = new Object[2];
// path must be pageId/anchorID in the case of of XHTML pages.
// pages.
- String[] pathSegments = StringUtil.split(path, "/"); //$NON-NLS-1$
+ String[] pathSegments = path.split("/"); //$NON-NLS-1$
if (pathSegments.length != 2)
// path does not have correct format. Return empty results.
return results;
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroModelRoot.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroModelRoot.java
index 6d29681..34e6d87 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroModelRoot.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroModelRoot.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2016 IBM Corporation and others.
+ * Copyright (c) 2004, 2017 IBM Corporation 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
@@ -36,7 +36,6 @@
import org.eclipse.ui.internal.intro.impl.model.util.ModelUtil;
import org.eclipse.ui.internal.intro.impl.util.IntroEvaluationContext;
import org.eclipse.ui.internal.intro.impl.util.Log;
-import org.eclipse.ui.internal.intro.impl.util.StringUtil;
import org.eclipse.ui.intro.config.IntroConfigurer;
import org.osgi.framework.Bundle;
import org.w3c.dom.Document;
@@ -548,7 +547,7 @@
IntroExtensionContent extensionContent) {
String path = extensionContent.getPath();
// path must be pageId/anchorID in the case of anchors in XHTML pages.
- String[] pathSegments = StringUtil.split(path, "/"); //$NON-NLS-1$
+ String[] pathSegments = path.split("/"); //$NON-NLS-1$
if (pathSegments.length != 2)
// path does not have correct format.
return false;
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java
index e7bfb6c..84517a7 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/IntroPartPresentation.java
@@ -29,7 +29,6 @@
import org.eclipse.ui.internal.intro.impl.presentations.FormIntroPartImplementation;
import org.eclipse.ui.internal.intro.impl.presentations.TextIntroPartImplementation;
import org.eclipse.ui.internal.intro.impl.util.Log;
-import org.eclipse.ui.internal.intro.impl.util.StringUtil;
import org.eclipse.ui.intro.IIntroPart;
/**
@@ -347,7 +346,7 @@
*
*/
private boolean listValueHasValue(String stringValue, String value) {
- String[] attributeValues = StringUtil.split(stringValue, ","); //$NON-NLS-1$
+ String[] attributeValues = stringValue.split(","); //$NON-NLS-1$
for (int i = 0; i < attributeValues.length; i++) {
if (attributeValues[i].equalsIgnoreCase(value))
return true;
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/url/IntroURLParser.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/url/IntroURLParser.java
index 696a30d..d1f748a 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/url/IntroURLParser.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/url/IntroURLParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2016 IBM Corporation and others.
+ * Copyright (c) 2003, 2017 IBM Corporation 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
@@ -17,7 +17,6 @@
import java.util.Properties;
import org.eclipse.ui.internal.intro.impl.util.Log;
-import org.eclipse.ui.internal.intro.impl.util.StringUtil;
/**
* A parser that knows how to parser OOBE action URLs. If URL is a valid intro
@@ -165,12 +164,12 @@
return properties;
// now extract the key/value pairs from the query.
- String[] params = StringUtil.split(query, "&"); //$NON-NLS-1$
+ String[] params = query.split("&"); //$NON-NLS-1$
for (int i = 0; i < params.length; i++) {
// for every parameter, ie: key=value pair, create a property
// entry. we know we have the key as the first string in the array,
// and the value as the second array.
- String[] keyValuePair = StringUtil.split(params[i], "="); //$NON-NLS-1$
+ String[] keyValuePair = params[i].split("="); //$NON-NLS-1$
if (keyValuePair.length != 2) {
Log.warning("Ignoring the following Intro URL parameter: " //$NON-NLS-1$
+ params[i]);
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/StringUtil.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/StringUtil.java
index bb3fed3..b268318 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/StringUtil.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/util/StringUtil.java
@@ -12,56 +12,15 @@
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
public class StringUtil {
- public static StringBuffer concat(String string1, String string2,
- String string3) {
- StringBuffer buffer = new StringBuffer(string1);
- buffer.append(string2);
- buffer.append(string3);
- return buffer;
- }
-
- public static StringBuffer concat(String string1, String string2,
- String string3, String string4) {
- StringBuffer buffer = concat(string1, string2, string3);
- buffer.append(string4);
- return buffer;
- }
-
- public static StringBuffer concat(String string1, String string2,
- String string3, String string4, String string5) {
- StringBuffer buffer = concat(string1, string2, string3, string4);
- buffer.append(string5);
- return buffer;
- }
-
- public static StringBuffer concat(String string1, String string2,
- String string3, String string4, String string5, String string6) {
- StringBuffer buffer = concat(string1, string2, string3, string4,
- string5);
- buffer.append(string6);
- return buffer;
- }
-
- /*
- * Helper method for String#split to handle the case where we
- * might be running on Foundation class libraries instead of 1.4.
- */
- public static String[] split(String string, String delimiters) {
- try {
- return string.split(delimiters);
- } catch (NoSuchMethodError e) {
- // not running 1.4 so try a string tokenizer
- List<String> result = new ArrayList<>();
- for (StringTokenizer tokenizer = new StringTokenizer(string, delimiters); tokenizer.hasMoreTokens(); )
- result.add(tokenizer.nextToken());
- return result.toArray(new String[result.size()]);
- }
+ public static StringBuffer concat(String... strings) {
+ StringBuffer buffer = new StringBuffer();
+ for (String string : strings) {
+ buffer.append(string);
+ }
+ return buffer;
}
public static String decode(String s, String enc) throws UnsupportedEncodingException {
@@ -99,8 +58,7 @@
result.append(next);
}
}
- String resString = result.toString();
- return resString;
+ return result.toString();
}
}