diff options
author | Alexander Kurtakov | 2017-09-09 08:43:54 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2017-09-09 08:43:54 +0000 |
commit | e68d8740242fc3d667d6108ff939fa371e427692 (patch) | |
tree | 9278ba0a17e08f9585f2b1aebe625f5555eb71a9 | |
parent | 036789af5311c1c0a09543a958f3538030ab6612 (diff) | |
download | eclipse.platform.ua-e68d8740242fc3d667d6108ff939fa371e427692.tar.gz eclipse.platform.ua-e68d8740242fc3d667d6108ff939fa371e427692.tar.xz eclipse.platform.ua-e68d8740242fc3d667d6108ff939fa371e427692.zip |
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>
8 files changed, 24 insertions, 99 deletions
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 3b57ab79a..77eccf017 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 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... 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, 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 77b14dc25..2af9ea2d2 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.help.internal.UAElementFactory; 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 abstract class AbstractIntroContainer extends AbstractBaseIntroElement { 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 13adf8cf7..1549c4383 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 @@ package org.eclipse.ui.internal.intro.impl.model; 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 @@ public abstract class AbstractIntroElement implements Cloneable { 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 9a8deeebd..2e1931636 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.BundleUtil; 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 @@ public abstract class AbstractIntroPage extends AbstractIntroContainer { 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 6d2968174..34e6d875d 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.BundleUtil; 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 @@ public class IntroModelRoot extends AbstractIntroContainer { 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 e7bfb6ca7..84517a7ea 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.BrowserIntroPartImplemen 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 @@ public class IntroPartPresentation extends AbstractIntroElement { * */ 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 696a30d3c..d1f748adb 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.nio.charset.StandardCharsets; 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 @@ public class IntroURLParser { 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 bb3fed345..b26831888 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 @@ package org.eclipse.ui.internal.intro.impl.util; 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 @@ public class StringUtil { result.append(next); } } - String resString = result.toString(); - return resString; + return result.toString(); } } |