Use Collections API instead of dealing with string arrays

Everything the StingArrays utility class does can also be done using
the Java Collections API. Arrays.asList() creates a lightweight wrapper
class without copying the array. So performance-wise, there is no
reason not to use this existing API.

Change-Id: Iec38610130bc8b7c09f475770b12c590d7d3c103
Signed-off-by: Ralf Sternberg <rsternberg@eclipsesource.com>
diff --git a/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/delegate/RWTLaunchDelegate.java b/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/delegate/RWTLaunchDelegate.java
index 92c75e0..31e0e95 100644
--- a/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/delegate/RWTLaunchDelegate.java
+++ b/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/delegate/RWTLaunchDelegate.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2013 Rüdiger Herrmann and others.
+ * Copyright (c) 2011, 2014 Rüdiger Herrmann 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
@@ -12,6 +12,7 @@
 package org.eclipse.rap.tools.launch.rwt.internal.delegate;
 
 import java.text.MessageFormat;
+import java.util.*;
 
 import org.eclipse.core.runtime.*;
 import org.eclipse.debug.core.ILaunch;
@@ -19,7 +20,8 @@
 import org.eclipse.jdt.launching.JavaLaunchDelegate;
 import org.eclipse.jdt.launching.SocketUtil;
 import org.eclipse.rap.tools.launch.rwt.internal.config.RWTLaunchConfig;
-import org.eclipse.rap.tools.launch.rwt.internal.util.*;
+import org.eclipse.rap.tools.launch.rwt.internal.util.BundleFileLocator;
+import org.eclipse.rap.tools.launch.rwt.internal.util.StringUtil;
 
 
 public class RWTLaunchDelegate extends JavaLaunchDelegate {
@@ -30,6 +32,7 @@
 
   private RWTLaunch launch;
 
+  @Override
   public void launch( ILaunchConfiguration configuration,
                       String mode,
                       ILaunch launch,
@@ -57,26 +60,29 @@
     }
   }
 
+  @Override
   public String getMainTypeName( ILaunchConfiguration configuration ) {
     return "org.eclipse.rap.tools.launch.rwt.internal.jetty.JettyLauncher"; //$NON-NLS-1$
   }
 
+  @Override
   public String[] getClasspath( ILaunchConfiguration configuration ) throws CoreException {
-    String[] result = super.getClasspath( configuration );
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.rap.tools.launch.rwt" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.jetty.continuation" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.jetty.http" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.jetty.io" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.jetty.security" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.jetty.server" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.jetty.servlet" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.jetty.util" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.jetty.webapp" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "org.eclipse.jetty.xml" ) ); //$NON-NLS-1$
-    result = StringArrays.append( result, BundleFileLocator.locate( "javax.servlet" ) ); //$NON-NLS-1$
-    return result;
+    List<String> list = new ArrayList<String>( Arrays.asList( super.getClasspath( configuration ) ) );
+    list.add( BundleFileLocator.locate( "org.eclipse.rap.tools.launch.rwt" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "org.eclipse.jetty.continuation" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "org.eclipse.jetty.http" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "org.eclipse.jetty.io" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "org.eclipse.jetty.security" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "org.eclipse.jetty.server" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "org.eclipse.jetty.servlet" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "org.eclipse.jetty.util" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "org.eclipse.jetty.webapp" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "org.eclipse.jetty.xml" ) ); //$NON-NLS-1$
+    list.add( BundleFileLocator.locate( "javax.servlet" ) ); //$NON-NLS-1$
+    return list.toArray( new String[0] );
   }
 
+  @Override
   public String getProgramArguments( ILaunchConfiguration configuration ) {
     // don't call super, program arguments are not configurable via the UI
     String port = String.valueOf( launch.getPort() );
@@ -86,6 +92,7 @@
     return MessageFormat.format( "{0} {1} \"{2}\"", arguments ); //$NON-NLS-1$
   }
 
+  @Override
   public String getVMArguments( ILaunchConfiguration configuration ) throws CoreException {
     StringBuilder result = new StringBuilder();
     result.append( super.getVMArguments( configuration ) );
diff --git a/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/shortcut/TypeInspector.java b/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/shortcut/TypeInspector.java
index b1dfccd..6457c02 100644
--- a/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/shortcut/TypeInspector.java
+++ b/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/shortcut/TypeInspector.java
@@ -10,8 +10,10 @@
  ******************************************************************************/
 package org.eclipse.rap.tools.launch.rwt.internal.shortcut;
 
+import java.util.Arrays;
+import java.util.List;
+
 import org.eclipse.jdt.core.*;
-import org.eclipse.rap.tools.launch.rwt.internal.util.StringArrays;
 
 
 class TypeInspector {
@@ -46,9 +48,9 @@
   }
 
   private boolean implementsEntryPoint() throws JavaModelException {
-    String[] superInterfaceNames = type.getSuperInterfaceNames();
-    return    StringArrays.contains( superInterfaceNames, "EntryPoint" ) //$NON-NLS-1$
-           || StringArrays.contains( superInterfaceNames, "IEntryPoint" ); //$NON-NLS-1$
+    List<String> superInterfaceNames = Arrays.asList( type.getSuperInterfaceNames() );
+    return    superInterfaceNames.contains( "EntryPoint" ) //$NON-NLS-1$
+           || superInterfaceNames.contains( "IEntryPoint" ); //$NON-NLS-1$
   }
 
   private boolean hasCreateUIMethod() {
@@ -71,8 +73,8 @@
   }
 
   private boolean implementsApplicationConfiguration() throws JavaModelException {
-    String[] superInterfaceNames = type.getSuperInterfaceNames();
-    return StringArrays.contains( superInterfaceNames, "ApplicationConfiguration" ); //$NON-NLS-1$
+    List<String> superInterfaceNames = Arrays.asList( type.getSuperInterfaceNames() );
+    return superInterfaceNames.contains( "ApplicationConfiguration" ); //$NON-NLS-1$
   }
 
   private boolean hasConfigureMethod() {
diff --git a/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/util/StringArrays.java b/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/util/StringArrays.java
deleted file mode 100644
index be71f78..0000000
--- a/bundles/org.eclipse.rap.tools.launch.rwt/src/org/eclipse/rap/tools/launch/rwt/internal/util/StringArrays.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2013 Rüdiger Herrmann 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:
- *    Rüdiger Herrmann - initial API and implementation
- *    EclipseSource - ongoing development
- ******************************************************************************/
-package org.eclipse.rap.tools.launch.rwt.internal.util;
-
-
-public class StringArrays {
-
-  public static String[] append( String[] strings, String string ) {
-    String[] result = new String[ strings.length + 1 ];
-    System.arraycopy( strings, 0, result, 0, strings.length );
-    result[ strings.length ] = string;
-    return result;
-  }
-
-  public static boolean contains( String[] strings, String string ) {
-    boolean result = false;
-    for( int i = 0; !result && i < strings.length; i++ ) {
-      if( strings[ i ].equals( string ) ) {
-        result = true;
-      }
-    }
-    return result;
-  }
-
-  private StringArrays() {
-    // prevent instantiation
-  }
-
-}
diff --git a/tests/org.eclipse.rap.tools.launch.rwt.test/src/org/eclipse/rap/tools/launch/rwt/internal/util/StringArrays_Test.java b/tests/org.eclipse.rap.tools.launch.rwt.test/src/org/eclipse/rap/tools/launch/rwt/internal/util/StringArrays_Test.java
deleted file mode 100644
index fc03217..0000000
--- a/tests/org.eclipse.rap.tools.launch.rwt.test/src/org/eclipse/rap/tools/launch/rwt/internal/util/StringArrays_Test.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2013 Rüdiger Herrmann 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:
- *    Rüdiger Herrmann - initial API and implementation
- *    EclipseSource - ongoing development
- ******************************************************************************/
-package org.eclipse.rap.tools.launch.rwt.internal.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.eclipse.rap.tools.launch.rwt.internal.util.StringArrays;
-import org.junit.Test;
-
-
-public class StringArrays_Test {
-
-  @Test
-  public void testAppend_withEmptyArray() {
-    String[] strings = StringArrays.append( new String[ 0 ], "x" );
-    assertEquals( 1, strings.length );
-    assertEquals( "x", strings[ 0 ] );
-  }
-
-  @Test
-  public void testAppend_withNonEmptyArray() {
-    String[] strings = StringArrays.append( new String[] { "x" }, "y" );
-    assertEquals( 2, strings.length );
-    assertEquals( "x", strings[ 0 ] );
-    assertEquals( "y", strings[ 1 ] );
-  }
-
-  @Test
-  public void testContains_withNonExistingString() {
-    String[] strings = { "a", "b" };
-    boolean contains = StringArrays.contains( strings, "c" );
-    assertFalse( contains );
-  }
-
-  @Test
-  public void testContains_withExistingString() {
-    String[] strings = { "a", "b" };
-    boolean contains = StringArrays.contains( strings, "b" );
-    assertTrue( contains );
-  }
-
-  @Test
-  public void testContains_withEmptyStrings() {
-    boolean contains = StringArrays.contains( new String[ 0 ], "c" );
-    assertFalse( contains );
-  }
-
-}