Bug 528318: Use Array List Instead Of Vector
Early classes of the Java API, such as Vector were synchronized to
make them thread-safe. Unfortunately, synchronization has a big
negative impact on performance, even when using these collections
from a single thread.
It is better to use their new unsynchronized replacements like
ArrayList or LinkedList instead of Vector
Change-Id: I61d418e4e87f17c96d837573b62d672de95eae9f
Signed-off-by: Matthias Becker <ma.becker@sap.com>
diff --git a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/Birthday.java b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/Birthday.java
index aa73fed..4ea15a6 100644
--- a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/Birthday.java
+++ b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/Birthday.java
@@ -12,9 +12,9 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
-import java.util.Vector;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
@@ -76,9 +76,9 @@
}
//
- private static Vector<PropertyDescriptor> descriptors;
+ private static ArrayList<PropertyDescriptor> descriptors;
static {
- descriptors = new Vector<>();
+ descriptors = new ArrayList<>();
///
String[] dayValues = new String[] {
@@ -86,7 +86,7 @@
ComboBoxPropertyDescriptor days = new ComboBoxPropertyDescriptor(
P_ID_DAY, P_DAY, dayValues);
days.setLabelProvider(new DayLabelProvider());
- descriptors.addElement(days);
+ descriptors.add(days);
///
String[] monthValues = new String[] {
@@ -94,10 +94,10 @@
ComboBoxPropertyDescriptor months = new ComboBoxPropertyDescriptor(
P_ID_MONTH, P_MONTH, monthValues);
months.setLabelProvider(new MonthLabelProvider());
- descriptors.addElement(months);
+ descriptors.add(months);
///
- descriptors.addElement(new TextPropertyDescriptor(P_ID_YEAR, P_YEAR));
+ descriptors.add(new TextPropertyDescriptor(P_ID_YEAR, P_YEAR));
}
/**
@@ -129,7 +129,7 @@
/**
* Standard Accessor
*/
- private static Vector<PropertyDescriptor> getDescriptors() {
+ private static ArrayList<PropertyDescriptor> getDescriptors() {
return descriptors;
}
diff --git a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/EmailAddress.java b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/EmailAddress.java
index 2001a90..642d549 100644
--- a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/EmailAddress.java
+++ b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/EmailAddress.java
@@ -10,7 +10,8 @@
*******************************************************************************/
package org.eclipse.ui.examples.propertysheet;
-import java.util.Vector;
+
+import java.util.ArrayList;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
@@ -45,13 +46,13 @@
public static final String P_DOMAIN = MessageUtil.getString("domain"); //$NON-NLS-1$
//Property-Descriptors
- private static Vector<PropertyDescriptor> descriptors;
+ private static ArrayList<PropertyDescriptor> descriptors;
static {
- descriptors = new Vector<>(2, 2);
+ descriptors = new ArrayList<>();
//non-editable child properties --> provide no editors
- descriptors.addElement(new PropertyDescriptor(P_ID_USERID, P_USERID));
- descriptors.addElement(new PropertyDescriptor(P_ID_DOMAIN, P_DOMAIN));
+ descriptors.add(new PropertyDescriptor(P_ID_USERID, P_USERID));
+ descriptors.add(new PropertyDescriptor(P_ID_DOMAIN, P_DOMAIN));
}
/**
@@ -76,7 +77,7 @@
/**
* Returns the descriptors
*/
- private static Vector<PropertyDescriptor> getDescriptors() {
+ private static ArrayList<PropertyDescriptor> getDescriptors() {
return descriptors;
}
diff --git a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/GroupElement.java b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/GroupElement.java
index 59380f2..fd49ac5 100644
--- a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/GroupElement.java
+++ b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/GroupElement.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.examples.propertysheet;
-import java.util.Vector;
+import java.util.ArrayList;
import org.eclipse.swt.graphics.RGB;
@@ -24,12 +24,12 @@
public static String P_CONTENTS = "contents"; //$NON-NLS-1$
- private Vector<OrganizationElement> subGroups;
+ private ArrayList<OrganizationElement> subGroups;
- private Vector<OrganizationElement> users;
+ private ArrayList<OrganizationElement> users;
// must be synchronized to contain both the references of subGroups and users
- private Vector<OrganizationElement> contents;
+ private ArrayList<OrganizationElement> contents;
/**
* Constructor.
@@ -115,9 +115,9 @@
/**
* Returns the content
*/
- private Vector<OrganizationElement> getContents() {
+ private ArrayList<OrganizationElement> getContents() {
if (contents == null)
- contents = new Vector<>();
+ contents = new ArrayList<>();
return contents;
}
@@ -136,18 +136,18 @@
/**
* Returns the subgroups
*/
- private Vector<OrganizationElement> getSubGroups() {
+ private ArrayList<OrganizationElement> getSubGroups() {
if (subGroups == null)
- subGroups = new Vector<>();
+ subGroups = new ArrayList<>();
return subGroups;
}
/**
* Returns the users
*/
- private Vector<OrganizationElement> getUsers() {
+ private ArrayList<OrganizationElement> getUsers() {
if (users == null)
- users = new Vector<>();
+ users = new ArrayList<>();
return users;
}
diff --git a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/Name.java b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/Name.java
index c3bd0f0..62df951 100644
--- a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/Name.java
+++ b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/Name.java
@@ -11,7 +11,8 @@
package org.eclipse.ui.examples.propertysheet;
-import java.util.Vector;
+
+import java.util.ArrayList;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
@@ -51,14 +52,14 @@
public static final String P_DESCRIPTORS = "properties"; //$NON-NLS-1$
- static private Vector<TextPropertyDescriptor> descriptors;
+ static private ArrayList<TextPropertyDescriptor> descriptors;
static {
- descriptors = new Vector<>();
- descriptors.addElement(new TextPropertyDescriptor(P_ID_FIRSTNAME,
+ descriptors = new ArrayList<>();
+ descriptors.add(new TextPropertyDescriptor(P_ID_FIRSTNAME,
P_FIRSTNAME));
- descriptors.addElement(new TextPropertyDescriptor(P_ID_LASTNAME,
+ descriptors.add(new TextPropertyDescriptor(P_ID_LASTNAME,
P_LASTNAME));
- descriptors.addElement(new TextPropertyDescriptor(P_ID_MIDDLENAME,
+ descriptors.add(new TextPropertyDescriptor(P_ID_MIDDLENAME,
P_MIDDLENAME));
}
@@ -82,7 +83,7 @@
/**
* Returns the descriptors
*/
- private static Vector<TextPropertyDescriptor> getDescriptors() {
+ private static ArrayList<TextPropertyDescriptor> getDescriptors() {
return descriptors;
}
diff --git a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/OrganizationElement.java b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/OrganizationElement.java
index ad93b0b..e1b5962 100644
--- a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/OrganizationElement.java
+++ b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/OrganizationElement.java
@@ -10,13 +10,11 @@
*******************************************************************************/
package org.eclipse.ui.examples.propertysheet;
-import java.util.Vector;
+import java.util.ArrayList;
import org.eclipse.core.runtime.IAdaptable;
-
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IBasicPropertyConstants;
-
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
@@ -36,12 +34,12 @@
private ImageDescriptor imageDescriptor;
//
- private static Vector<PropertyDescriptor> descriptors;
+ private static ArrayList<PropertyDescriptor> descriptors;
static {
- descriptors = new Vector<>();
+ descriptors = new ArrayList<>();
PropertyDescriptor name = new TextPropertyDescriptor(
IBasicPropertyConstants.P_TEXT, MessageUtil.getString("name")); //$NON-NLS-1$
- descriptors.addElement(name);
+ descriptors.add(name);
}
/**
@@ -78,7 +76,7 @@
/**
* Returns the descriptors
*/
- static Vector<PropertyDescriptor> getDescriptors() {
+ static ArrayList<PropertyDescriptor> getDescriptors() {
return descriptors;
}
diff --git a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/StreetAddress.java b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/StreetAddress.java
index 0a58fa0..37f15a4 100644
--- a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/StreetAddress.java
+++ b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/StreetAddress.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.examples.propertysheet;
-import java.util.Vector;
+import java.util.ArrayList;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
@@ -53,16 +53,16 @@
public static final String P_STREET = MessageUtil.getString("street"); //$NON-NLS-1$
- private static Vector<TextPropertyDescriptor> descriptors;
+ private static ArrayList<TextPropertyDescriptor> descriptors;
static {
- descriptors = new Vector<>();
- descriptors.addElement(new TextPropertyDescriptor(P_ID_BUILD_NO,
+ descriptors = new ArrayList<>();
+ descriptors.add(new TextPropertyDescriptor(P_ID_BUILD_NO,
P_BUILD_NO));
descriptors
- .addElement(new TextPropertyDescriptor(P_ID_APTBOX, P_APTBOX));
+ .add(new TextPropertyDescriptor(P_ID_APTBOX, P_APTBOX));
descriptors
- .addElement(new TextPropertyDescriptor(P_ID_STREET, P_STREET));
+ .add(new TextPropertyDescriptor(P_ID_STREET, P_STREET));
}
/**
@@ -117,7 +117,7 @@
/**
* Returns the descriptors
*/
- private static Vector<TextPropertyDescriptor> getDescriptors() {
+ private static ArrayList<TextPropertyDescriptor> getDescriptors() {
return descriptors;
}
diff --git a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/UserElement.java b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/UserElement.java
index 940cb5e..f5a7bb7 100644
--- a/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/UserElement.java
+++ b/examples/org.eclipse.ui.examples.propertysheet/Eclipse UI Examples PropertySheet/org/eclipse/ui/examples/propertysheet/UserElement.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.examples.propertysheet;
-import java.util.Vector;
+import java.util.ArrayList;
import org.eclipse.jface.viewers.ICellEditorValidator;
import org.eclipse.jface.viewers.LabelProvider;
@@ -153,9 +153,9 @@
}
//
- static private Vector<PropertyDescriptor> descriptors;
+ static private ArrayList<PropertyDescriptor> descriptors;
static {
- descriptors = new Vector<>();
+ descriptors = new ArrayList<>();
PropertyDescriptor propertyDescriptor;
///
@@ -163,33 +163,33 @@
P_PHONENUMBER);
propertyDescriptor.setCategory(P_CONTACTINFO);
propertyDescriptor.setHelpContextIds(PHONE_NUMBER_CONTEXT);
- descriptors.addElement(propertyDescriptor);
+ descriptors.add(propertyDescriptor);
///
propertyDescriptor = new PropertyDescriptor(P_ID_ADDRESS, P_ADDRESS);
propertyDescriptor.setCategory(P_CONTACTINFO);
propertyDescriptor.setHelpContextIds(ADDRESS_CONTEXT);
- descriptors.addElement(propertyDescriptor);
+ descriptors.add(propertyDescriptor);
///
propertyDescriptor = new TextPropertyDescriptor(P_ID_EMAIL, P_EMAIL);
propertyDescriptor.setCategory(P_CONTACTINFO);
propertyDescriptor.setHelpContextIds(EMAIL_CONTEXT);
propertyDescriptor.setValidator(new EmailAddressValidator());
- descriptors.addElement(propertyDescriptor);
+ descriptors.add(propertyDescriptor);
///
propertyDescriptor = new TextPropertyDescriptor(P_ID_FULLNAME,
P_FULLNAME);
propertyDescriptor.setCategory(P_PERSONELINFO);
propertyDescriptor.setHelpContextIds(FULL_NAME_CONTEXT);
- descriptors.addElement(propertyDescriptor);
+ descriptors.add(propertyDescriptor);
///
propertyDescriptor = new PropertyDescriptor(P_ID_BDAY, P_BDAY);
propertyDescriptor.setCategory(P_PERSONELINFO);
propertyDescriptor.setHelpContextIds(BIRTHDAY_CONTEXT);
- descriptors.addElement(propertyDescriptor);
+ descriptors.add(propertyDescriptor);
///
propertyDescriptor = new ComboBoxPropertyDescriptor(P_ID_COOP, P_COOP,
@@ -197,7 +197,7 @@
propertyDescriptor.setCategory(P_PERSONELINFO);
propertyDescriptor.setHelpContextIds(COOP_CONTEXT);
propertyDescriptor.setLabelProvider(new BooleanLabelProvider());
- descriptors.addElement(propertyDescriptor);
+ descriptors.add(propertyDescriptor);
///
propertyDescriptor = new TextPropertyDescriptor(P_ID_SALARY, P_SALARY);
@@ -225,26 +225,26 @@
}
});
propertyDescriptor.setCategory(P_PERSONELINFO);
- descriptors.addElement(propertyDescriptor);
+ descriptors.add(propertyDescriptor);
/// HairColor
propertyDescriptor = new ColorPropertyDescriptor(P_ID_HAIRCOLOR,
P_HAIRCOLOR);
propertyDescriptor.setCategory(P_PERSONALINFO);
propertyDescriptor.setHelpContextIds(HAIR_COLOR__CONTEXT);
- descriptors.addElement(propertyDescriptor);
+ descriptors.add(propertyDescriptor);
/// EyeColor
propertyDescriptor = new ColorPropertyDescriptor(P_ID_EYECOLOR,
P_EYECOLOR);
propertyDescriptor.setCategory(P_PERSONALINFO);
propertyDescriptor.setHelpContextIds(EYE_COLOR_CONTEXT);
- descriptors.addElement(propertyDescriptor);
+ descriptors.add(propertyDescriptor);
//gets descriptors from parent, warning name-space collision may occur
- Vector<PropertyDescriptor> parentDescriptors = OrganizationElement.getDescriptors();
+ ArrayList<PropertyDescriptor> parentDescriptors = OrganizationElement.getDescriptors();
for (int i = 0; i < parentDescriptors.size(); i++) {
- descriptors.addElement(parentDescriptors.elementAt(i));
+ descriptors.add(parentDescriptors.get(i));
}
}
@@ -297,7 +297,7 @@
/**
* Returns the descriptors
*/
- static Vector<PropertyDescriptor> getDescriptors() {
+ static ArrayList<PropertyDescriptor> getDescriptors() {
return descriptors;
}
diff --git a/examples/org.eclipse.ui.examples.readmetool/Eclipse UI Examples Readme Tool/org/eclipse/ui/examples/readmetool/DefaultSectionsParser.java b/examples/org.eclipse.ui.examples.readmetool/Eclipse UI Examples Readme Tool/org/eclipse/ui/examples/readmetool/DefaultSectionsParser.java
index 42196a2..a986543 100644
--- a/examples/org.eclipse.ui.examples.readmetool/Eclipse UI Examples Readme Tool/org/eclipse/ui/examples/readmetool/DefaultSectionsParser.java
+++ b/examples/org.eclipse.ui.examples.readmetool/Eclipse UI Examples Readme Tool/org/eclipse/ui/examples/readmetool/DefaultSectionsParser.java
@@ -13,8 +13,8 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Hashtable;
-import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
@@ -79,7 +79,7 @@
@Override
public MarkElement[] parse(IFile file) {
Hashtable<String, MarkElement> markTable = new Hashtable<>(40);
- Vector<MarkElement> topLevel = new Vector<>();
+ ArrayList<MarkElement> topLevel = new ArrayList<>();
String s = getText(file);
int start = 0;
int end = -1;
@@ -128,7 +128,7 @@
lastme.setNumberOfLines(lineno - lastlineno - 1);
}
MarkElement[] results = new MarkElement[topLevel.size()];
- topLevel.copyInto(results);
+ results = topLevel.toArray(results);
return results;
}
diff --git a/examples/org.eclipse.ui.examples.readmetool/Eclipse UI Examples Readme Tool/org/eclipse/ui/examples/readmetool/MarkElement.java b/examples/org.eclipse.ui.examples.readmetool/Eclipse UI Examples Readme Tool/org/eclipse/ui/examples/readmetool/MarkElement.java
index 5f5697e..be23d63 100644
--- a/examples/org.eclipse.ui.examples.readmetool/Eclipse UI Examples Readme Tool/org/eclipse/ui/examples/readmetool/MarkElement.java
+++ b/examples/org.eclipse.ui.examples.readmetool/Eclipse UI Examples Readme Tool/org/eclipse/ui/examples/readmetool/MarkElement.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.ui.examples.readmetool;
-import java.util.Vector;
+import java.util.ArrayList;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.IAdaptable;
@@ -40,7 +40,7 @@
private int length;
- private Vector<MarkElement> children;
+ private ArrayList<MarkElement> children;
/**
* Creates a new MarkElement and stores parent element and
@@ -66,7 +66,7 @@
*/
private void addChild(MarkElement child) {
if (children == null) {
- children = new Vector<>();
+ children = new ArrayList<>();
}
children.add(child);
}