Bug 489330 - Technical debt : Number instantiations

Save resources by using the Number factories (valueOf) rather than
creating new instances.

Change-Id: I285439a41bb102a88d893527f23366444ccafdbe
Signed-off-by: Mickael Istria <mistria@redhat.com>
diff --git a/bundles/org.eclipse.equinox.cm/src/org/eclipse/equinox/internal/cm/PluginManager.java b/bundles/org.eclipse.equinox.cm/src/org/eclipse/equinox/internal/cm/PluginManager.java
index dbab045..0456ce4 100644
--- a/bundles/org.eclipse.equinox.cm/src/org/eclipse/equinox/internal/cm/PluginManager.java
+++ b/bundles/org.eclipse.equinox.cm/src/org/eclipse/equinox/internal/cm/PluginManager.java
@@ -53,7 +53,7 @@
 	}
 
 	private static class PluginTracker extends ServiceTracker<ConfigurationPlugin, ConfigurationPlugin> {
-		final Integer ZERO = new Integer(0);
+		final Integer ZERO = Integer.valueOf(0);
 		private TreeSet<ServiceReference<ConfigurationPlugin>> serviceReferences = new TreeSet<ServiceReference<ConfigurationPlugin>>(new Comparator<ServiceReference<ConfigurationPlugin>>() {
 			public int compare(ServiceReference<ConfigurationPlugin> s1, ServiceReference<ConfigurationPlugin> s2) {
 
diff --git a/bundles/org.eclipse.equinox.cm/src/org/eclipse/equinox/internal/cm/reliablefile/ReliableFile.java b/bundles/org.eclipse.equinox.cm/src/org/eclipse/equinox/internal/cm/reliablefile/ReliableFile.java
index 80a7308..f4e3dfb 100644
--- a/bundles/org.eclipse.equinox.cm/src/org/eclipse/equinox/internal/cm/reliablefile/ReliableFile.java
+++ b/bundles/org.eclipse.equinox.cm/src/org/eclipse/equinox/internal/cm/reliablefile/ReliableFile.java
@@ -197,12 +197,12 @@
 				return null;
 			List<Integer> list = new ArrayList<Integer>(defaultMaxGenerations);
 			if (file.exists())
-				list.add(new Integer(0)); //base file exists
+				list.add(Integer.valueOf(0)); //base file exists
 			for (int i = 0; i < files.length; i++) {
 				if (files[i].startsWith(prefix)) {
 					try {
 						int id = Integer.parseInt(files[i].substring(prefixLen));
-						list.add(new Integer(id));
+						list.add(Integer.valueOf(id));
 					} catch (NumberFormatException e) {/*ignore*/
 					}
 				}
diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/PluginVersionIdentifier.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/PluginVersionIdentifier.java
index aa0eff7..7fc0e8b 100644
--- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/PluginVersionIdentifier.java
+++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/PluginVersionIdentifier.java
@@ -202,9 +202,9 @@
 
 		// "result" is a 4-element array with the major, minor, service, and qualifier
 		Object[] result = new Object[4];
-		result[0] = new Integer(numbers[0]);
-		result[1] = new Integer(numbers[1]);
-		result[2] = new Integer(numbers[2]);
+		result[0] = Integer.valueOf(numbers[0]);
+		result[1] = Integer.valueOf(numbers[1]);
+		result[2] = Integer.valueOf(numbers[2]);
 		if (elementSize >= 4)
 			result[3] = elements.elementAt(3);
 		else
diff --git a/bundles/org.eclipse.equinox.coordinator/osgi/org/osgi/service/coordinator/CoordinationPermission.java b/bundles/org.eclipse.equinox.coordinator/osgi/org/osgi/service/coordinator/CoordinationPermission.java
index 7892b43..a746355 100644
--- a/bundles/org.eclipse.equinox.coordinator/osgi/org/osgi/service/coordinator/CoordinationPermission.java
+++ b/bundles/org.eclipse.equinox.coordinator/osgi/org/osgi/service/coordinator/CoordinationPermission.java
@@ -519,7 +519,7 @@
 		if (bundle != null) {
 			AccessController.doPrivileged(new PrivilegedAction<Void>() {
 				public Void run() {
-					map.put("id", new Long(bundle.getBundleId()));
+					map.put("id", Long.valueOf(bundle.getBundleId()));
 					map.put("location", bundle.getLocation());
 					String name = bundle.getSymbolicName();
 					if (name != null) {
diff --git a/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/CoordinatorImpl.java b/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/CoordinatorImpl.java
index 37c9a79..4e4127c 100644
--- a/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/CoordinatorImpl.java
+++ b/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/CoordinatorImpl.java
@@ -148,7 +148,7 @@
 				throw new IllegalStateException(NLS.bind(Messages.CoordinatorShutdown, name, timeout));
 			synchronized (CoordinatorImpl.class) {
 				coordinations.add(coordination);
-				idToCoordination.put(new Long(coordination.getId()), coordination);
+				idToCoordination.put(Long.valueOf(coordination.getId()), coordination);
 			}
 		}
 		if (timeout > 0) {
@@ -171,7 +171,7 @@
 		CoordinationWeakReference.processOrphanedCoordinations();
 		CoordinationReferent result = null;
 		synchronized (CoordinatorImpl.class) {
-			CoordinationImpl c = idToCoordination.get(new Long(id));
+			CoordinationImpl c = idToCoordination.get(Long.valueOf(id));
 			if (c != null)
 				result = c.getReferent();
 		}
@@ -297,7 +297,7 @@
 		synchronized (this) {
 			synchronized (CoordinatorImpl.class) {
 				this.coordinations.remove(coordination);
-				idToCoordination.remove(new Long(coordination.getId()));
+				idToCoordination.remove(Long.valueOf(coordination.getId()));
 				participantToCoordination.keySet().removeAll(participants);
 			}
 		}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java
index da6a16c..ec55869 100644
--- a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java
@@ -646,7 +646,7 @@
     props.put("test.property.value", "setFromCM");
     props.put("test.property.list", "setFromCM");
     props.put("component.name", "setFromCM");
-    props.put("component.id", new Long(-1));
+    props.put("component.id", Long.valueOf(-1));
     // the line below will create the configuration if it doesn't exists!
     // see CM api for details
 
@@ -696,7 +696,7 @@
     newProps.put("override.property.2", "setFromMethod");
     newProps.put("override.property.3", "setFromMethod");
     newProps.put(ComponentConstants.COMPONENT_NAME, "setFromMethod");
-    newProps.put(ComponentConstants.COMPONENT_ID, new Long(-1));
+    newProps.put(ComponentConstants.COMPONENT_ID, Long.valueOf(-1));
     newProps.put("name", "test");
 
     ComponentInstance ci = factory.newInstance(newProps);
@@ -1596,7 +1596,7 @@
     waitBundleStart();
 
     Hashtable props = new Hashtable(10);
-    props.put("config.base.data", new Integer(1));
+    props.put("config.base.data", Integer.valueOf(1));
 
     // component notsetNS100 - property not set by Configuration Admin; XML NS
     // 1.0.0
@@ -1697,7 +1697,7 @@
     waitBundleStart();
 
     Hashtable props = new Hashtable(10);
-    props.put("config.base.data", new Integer(1));
+    props.put("config.base.data", Integer.valueOf(1));
 
     // component notsetNS100 - property not set by Configuration Admin; XML NS
     // 1.0.0
@@ -2123,7 +2123,7 @@
           if (properties == null) {
             properties = new Hashtable();
           }
-          properties.put("component.index", new Integer(i));
+          properties.put("component.index", Integer.valueOf(i));
           config.update(properties);
 
           sleep0(100);
@@ -2214,7 +2214,7 @@
     Bundle tb21 = installBundle("tb21");
 
     Hashtable props = new Hashtable(10);
-    props.put("config.dummy.data", new Integer(1));
+    props.put("config.dummy.data", Integer.valueOf(1));
     cm.getConfiguration(MOD_NOTSET_NS100).update(props);
     cm.getConfiguration(MOD_NOARGS_NS100).update(props);
     cm.getConfiguration(MOD_CC_NS100).update(props);
@@ -2227,7 +2227,7 @@
     tb21.start();
     waitBundleStart();
 
-    props.put("config.dummy.data", new Integer(2));
+    props.put("config.dummy.data", Integer.valueOf(2));
     Hashtable unsatisfyingProps = new Hashtable(10);
     unsatisfyingProps.put("ref.target", "(component.name=org.eclipse.equinox.ds.tests.tb21.unexisting.provider)");
 
@@ -2271,7 +2271,7 @@
     Bundle tb21a = installBundle("tb21a");
 
     Hashtable props = new Hashtable(10);
-    props.put("config.dummy.data", new Integer(1));
+    props.put("config.dummy.data", Integer.valueOf(1));
     cm.getConfiguration(MOD_NOTSET_NS110).update(props);
     cm.getConfiguration(MOD_NOARGS_NS110).update(props);
     cm.getConfiguration(MOD_CC_NS110).update(props);
@@ -2284,7 +2284,7 @@
     tb21a.start();
     waitBundleStart();
 
-    props.put("config.dummy.data", new Integer(2));
+    props.put("config.dummy.data", Integer.valueOf(2));
     Hashtable unsatisfyingProps = new Hashtable(10);
     unsatisfyingProps.put("ref.target", "(component.name=org.eclipse.equinox.ds.tests.tb21.unexisting.provider)");
 
@@ -2388,7 +2388,7 @@
     Bundle tb21a = installBundle("tb21a");
 
     Hashtable props = new Hashtable(10);
-    props.put("config.dummy.data", new Integer(1));
+    props.put("config.dummy.data", Integer.valueOf(1));
     cm.getConfiguration(MOD_CC_NS110).update(props);
     cm.getConfiguration(MOD_NOT_EXIST_NS110).update(props);
     cm.getConfiguration(MOD_THROW_EX_NS110).update(props);
@@ -2400,12 +2400,12 @@
 
     // Verifying correctness of updated component properties
     PropertiesProvider bs = getBaseService(MOD_CC_NS110);
-    props.put("config.dummy.data", new Integer(2));
+    props.put("config.dummy.data", Integer.valueOf(2));
     cm.getConfiguration(MOD_CC_NS110).update(props);
     Thread.sleep(timeout * 2);
     Object val = ((ComponentContextProvider) bs).getComponentContext().getProperties().get("config.dummy.data");
     assertEquals("Modified method of " + MOD_CC_NS110 + " should be called", 1 << 2, (1 << 2) & getBaseConfigData(bs));
-    assertTrue("Component properties should be updated properly for " + MOD_CC_NS110, (new Integer(2)).equals(val));
+    assertTrue("Component properties should be updated properly for " + MOD_CC_NS110, (Integer.valueOf(2)).equals(val));
 
     // Specified modified method doesn't exist, deactivate() should be called
     // instead of modified
@@ -2481,7 +2481,7 @@
     	return;
     
     Hashtable props = new Hashtable(11);
-    props.put("config.base.data", new Integer(1));
+    props.put("config.base.data", Integer.valueOf(1));
     //create the configurations for the test DS components
     Configuration config = cm.getConfiguration(COMP_OPTIONAL);
     config.update(props);
@@ -2594,9 +2594,9 @@
       final String PROP_BIND_11 = "bind11";
       final String PROP_BIND_0n = "bind0n";
       final String PROP_BIND_1n = "bind1n";
-      final Integer RANK_1 = new Integer(1);
-      final Integer RANK_2 = new Integer(2);
-      final Integer RANK_3 = new Integer(3);
+      final Integer RANK_1 = Integer.valueOf(1);
+      final Integer RANK_2 = Integer.valueOf(2);
+      final Integer RANK_3 = Integer.valueOf(3);
       tb25.start();
       waitBundleStart();
 
@@ -2704,9 +2704,9 @@
       final String PROP_BIND_11 = "bind11";
       final String PROP_BIND_0n = "bind0n";
       final String PROP_BIND_1n = "bind1n";
-      final Integer RANK_1 = new Integer(1);
-      final Integer RANK_2 = new Integer(2);
-      final Integer RANK_3 = new Integer(3);
+      final Integer RANK_1 = 1;
+      final Integer RANK_2 = 2;
+      final Integer RANK_3 = 3;
       tb25.start();
       waitBundleStart();
 
diff --git a/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/internal/event/mapper/EventAdapter.java b/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/internal/event/mapper/EventAdapter.java
index 0e4eb69..04e2d05 100644
--- a/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/internal/event/mapper/EventAdapter.java
+++ b/bundles/org.eclipse.equinox.event/src/org/eclipse/equinox/internal/event/mapper/EventAdapter.java
@@ -52,7 +52,7 @@
 
 	public void putBundleProperties(Map<String, Object> properties, Bundle bundle) {
 		// assertion bundle != null
-		properties.put(Constants.BUNDLE_ID, new Long(bundle.getBundleId()));
+		properties.put(Constants.BUNDLE_ID, Long.valueOf(bundle.getBundleId()));
 		String symbolicName = bundle.getSymbolicName();
 		if (symbolicName != null) {
 			properties.put(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
diff --git a/bundles/org.eclipse.equinox.http.jetty9/src/org/eclipse/equinox/http/jetty/internal/Activator.java b/bundles/org.eclipse.equinox.http.jetty9/src/org/eclipse/equinox/http/jetty/internal/Activator.java
index d72182a..cb41cb6 100644
--- a/bundles/org.eclipse.equinox.http.jetty9/src/org/eclipse/equinox/http/jetty/internal/Activator.java
+++ b/bundles/org.eclipse.equinox.http.jetty9/src/org/eclipse/equinox/http/jetty/internal/Activator.java
@@ -114,7 +114,7 @@
 		int httpPort = Details.getIntProp(context, JettyConstants.HTTP_PORT, -1);
 		if (httpPort == -1)
 			httpPort = Details.getInt(context, ORG_OSGI_SERVICE_HTTP_PORT, 0);
-		defaultSettings.put(JettyConstants.HTTP_PORT, new Integer(httpPort));
+		defaultSettings.put(JettyConstants.HTTP_PORT, Integer.valueOf(httpPort));
 
 		// HTTP Host (default is 0.0.0.0)
 		String httpHost = Details.getStringProp(context, JettyConstants.HTTP_HOST, null);
@@ -128,13 +128,13 @@
 		// minimum number of threads
 		int minThreads = Details.getIntProp(context, JettyConstants.HTTP_MINTHREADS, 8);
 		if (minThreads != -1) {
-			defaultSettings.put(JettyConstants.HTTP_MINTHREADS, new Integer(minThreads));
+			defaultSettings.put(JettyConstants.HTTP_MINTHREADS, Integer.valueOf(minThreads));
 		}
 
 		// maximum number of threads
 		int maxThreads = Details.getIntProp(context, JettyConstants.HTTP_MAXTHREADS, 200);
 		if (maxThreads != -1) {
-			defaultSettings.put(JettyConstants.HTTP_MAXTHREADS, new Integer(maxThreads));
+			defaultSettings.put(JettyConstants.HTTP_MAXTHREADS, Integer.valueOf(maxThreads));
 		}
 
 		if (httpsEnabled.booleanValue()) {
@@ -143,7 +143,7 @@
 			int httpsPort = Details.getIntProp(context, JettyConstants.HTTP_PORT, -1);
 			if (httpsPort == -1)
 				httpsPort = Details.getInt(context, ORG_OSGI_SERVICE_HTTP_PORT_SECURE, 443);
-			defaultSettings.put(JettyConstants.HTTPS_PORT, new Integer(httpsPort));
+			defaultSettings.put(JettyConstants.HTTPS_PORT, Integer.valueOf(httpsPort));
 
 			// HTTPS Host (default is 0.0.0.0)
 			String httpsHost = Details.getStringProp(context, JettyConstants.HTTPS_HOST, null);
@@ -193,7 +193,7 @@
 		String sessionInactiveInterval = Details.getStringProp(context, JettyConstants.CONTEXT_SESSIONINACTIVEINTERVAL, null);
 		if (sessionInactiveInterval != null) {
 			try {
-				defaultSettings.put(JettyConstants.CONTEXT_SESSIONINACTIVEINTERVAL, new Integer(sessionInactiveInterval));
+				defaultSettings.put(JettyConstants.CONTEXT_SESSIONINACTIVEINTERVAL, Integer.valueOf(sessionInactiveInterval));
 			} catch (NumberFormatException e) {
 				//(log this) ignore
 			}
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/DataParser.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/DataParser.java
index 91959f4..5128d9a 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/DataParser.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/DataParser.java
@@ -126,19 +126,19 @@
 			case AttributeDefinition.STRING :
 				return value;
 			case AttributeDefinition.LONG :
-				return new Long(value);
+				return Long.valueOf(value);
 			case AttributeDefinition.INTEGER :
-				return new Integer(value);
+				return Integer.valueOf(value);
 			case AttributeDefinition.SHORT :
-				return new Short(value);
+				return Short.valueOf(value);
 			case AttributeDefinition.CHARACTER :
-				return new Character(value.charAt(0));
+				return Character.valueOf(value.charAt(0));
 			case AttributeDefinition.BYTE :
-				return new Byte(value);
+				return Byte.valueOf(value);
 			case AttributeDefinition.DOUBLE :
-				return new Double(value);
+				return Double.valueOf(value);
 			case AttributeDefinition.FLOAT :
-				return new Float(value);
+				return Float.valueOf(value);
 			case AttributeDefinition.BIGINTEGER :
 				return new BigInteger(value);
 			case AttributeDefinition.BIGDECIMAL :
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java
index 93c2e75..127de74 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java
@@ -58,7 +58,7 @@
 		// Avoid synthetic accessor method warnings.
 		final LogService loggerTemp = this.logger;
 		final ServiceTracker<Object, Object> tracker = this.metaTypeProviderTracker;
-		Long bID = new Long(b.getBundleId());
+		Long bID = Long.valueOf(b.getBundleId());
 		synchronized (_mtps) {
 			if (_mtps.containsKey(bID))
 				return _mtps.get(bID);
@@ -116,7 +116,7 @@
 	public void bundleChanged(BundleEvent event) {
 
 		int type = event.getType();
-		Long bID = new Long(event.getBundle().getBundleId());
+		Long bID = Long.valueOf(event.getBundle().getBundleId());
 
 		switch (type) {
 			case BundleEvent.UPDATED :
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/ValueTokenizer.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/ValueTokenizer.java
index d916055..4f374ba 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/ValueTokenizer.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/ValueTokenizer.java
@@ -195,7 +195,7 @@
 						rangeError = validateString(ad, s);
 						break;
 					case AttributeDefinition.INTEGER :
-						Integer intVal = new Integer(s);
+						Integer intVal = Integer.valueOf(s);
 						if (ad._minValue != null && intVal.compareTo((Integer) ad._minValue) < 0) {
 							rangeError = true;
 						} else if (ad._maxValue != null && intVal.compareTo((Integer) ad._maxValue) > 0) {
@@ -203,7 +203,7 @@
 						}
 						break;
 					case AttributeDefinition.LONG :
-						Long longVal = new Long(s);
+						Long longVal = Long.valueOf(s);
 						if (ad._minValue != null && longVal.compareTo((Long) ad._minValue) < 0) {
 							rangeError = true;
 						} else if (ad._maxValue != null && longVal.compareTo((Long) ad._maxValue) > 0) {
@@ -211,7 +211,7 @@
 						}
 						break;
 					case AttributeDefinition.DOUBLE :
-						Double doubleVal = new Double(s);
+						Double doubleVal = Double.valueOf(s);
 						if (ad._minValue != null && doubleVal.compareTo((Double) ad._minValue) < 0) {
 							rangeError = true;
 						} else if (ad._maxValue != null && doubleVal.compareTo((Double) ad._maxValue) > 0) {
@@ -223,7 +223,7 @@
 						// Seems unnecessary to impose any further restrictions.
 						break;
 					case AttributeDefinition.CHARACTER :
-						Character charVal = new Character(s.charAt(0));
+						Character charVal = Character.valueOf(s.charAt(0));
 						if (ad._minValue != null && charVal.compareTo((Character) ad._minValue) < 0) {
 							rangeError = true;
 						} else if (ad._maxValue != null && charVal.compareTo((Character) ad._maxValue) > 0) {
@@ -231,7 +231,7 @@
 						}
 						break;
 					case AttributeDefinition.FLOAT :
-						Float floatVal = new Float(s);
+						Float floatVal = Float.valueOf(s);
 						if (ad._minValue != null && floatVal.compareTo((Float) ad._minValue) < 0) {
 							rangeError = true;
 						} else if (ad._maxValue != null && floatVal.compareTo((Float) ad._maxValue) > 0) {
@@ -239,7 +239,7 @@
 						}
 						break;
 					case AttributeDefinition.SHORT :
-						Short shortVal = new Short(s);
+						Short shortVal = Short.valueOf(s);
 						if (ad._minValue != null && shortVal.compareTo((Short) ad._minValue) < 0) {
 							rangeError = true;
 						} else if (ad._maxValue != null && shortVal.compareTo((Short) ad._maxValue) > 0) {
@@ -247,7 +247,7 @@
 						}
 						break;
 					case AttributeDefinition.BYTE :
-						Byte byteVal = new Byte(s);
+						Byte byteVal = Byte.valueOf(s);
 						if (ad._minValue != null && byteVal.compareTo((Byte) ad._minValue) < 0) {
 							rangeError = true;
 						} else if (ad._maxValue != null && byteVal.compareTo((Byte) ad._maxValue) > 0) {