|
From: <ha...@us...> - 2008-03-26 14:37:25
|
Revision: 1944
http://cogkit.svn.sourceforge.net/cogkit/?rev=1944&view=rev
Author: hategan
Date: 2008-03-26 07:36:04 -0700 (Wed, 26 Mar 2008)
Log Message:
-----------
lazy attribute map initialization; clean-ups
Modified Paths:
--------------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/TaskImpl.java
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/TaskImpl.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/TaskImpl.java 2008-03-26 14:34:34 UTC (rev 1943)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/TaskImpl.java 2008-03-26 14:36:04 UTC (rev 1944)
@@ -9,6 +9,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -54,8 +55,7 @@
public TaskImpl() {
this.id = new IdentityImpl();
- this.attributes = new HashMap();
- this.serviceList = new ArrayList();
+ this.serviceList = new ArrayList(2);
this.status = new StatusImpl();
statusListeners = new CopyOnWriteHashSet();
outputListeners = new CopyOnWriteHashSet();
@@ -106,8 +106,10 @@
}
public void setService(int index, Service service) {
- this.serviceList.ensureCapacity(index + 1);
- int sz = this.serviceList.size();
+ while (serviceList.size() < index) {
+ serviceList.add(null);
+ }
+ int sz = serviceList.size();
if (sz == index) {
this.serviceList.add(index, service);
}
@@ -121,11 +123,11 @@
}
public void addService(Service service) {
- this.serviceList.add(service);
+ serviceList.add(service);
}
public Service removeService(int index) {
- return (Service) this.serviceList.remove(index);
+ return (Service) serviceList.remove(index);
}
public Service getService(int index) {
@@ -137,7 +139,7 @@
public Collection removeAllServices() {
Collection services = this.serviceList;
- this.serviceList = new ArrayList();
+ this.serviceList = new ArrayList(2);
return services;
}
@@ -146,12 +148,11 @@
}
public Collection getAllServices() {
- return this.serviceList;
+ return serviceList;
}
public void setRequiredService(int value) {
this.requiredServices = value;
- this.serviceList.ensureCapacity(value);
}
public int getRequiredServices() {
@@ -222,7 +223,7 @@
notifyListeners(status);
}
// Now prove that this works correctly with concurrent updates.
- // I will pay $20 for the first one.
+ // I will pay $20 for the first such proof that I receive.
}
protected void notifyListeners(Status status) {
@@ -256,15 +257,28 @@
}
public void setAttribute(String name, Object value) {
- this.attributes.put(name.toLowerCase(), value);
+ if (attributes == null) {
+ attributes = new HashMap();
+ }
+ attributes.put(name.toLowerCase(), value);
}
public Object getAttribute(String name) {
- return this.attributes.get(name.toLowerCase());
+ if (attributes != null) {
+ return attributes.get(name.toLowerCase());
+ }
+ else {
+ return null;
+ }
}
public Collection getAttributeNames() {
- return this.attributes.keySet();
+ if (attributes != null) {
+ return attributes.keySet();
+ }
+ else {
+ return Collections.EMPTY_MAP.keySet();
+ }
}
public void addStatusListener(StatusListener listener) {
@@ -335,7 +349,7 @@
}
public int hashCode() {
- return (int) this.id.getValue();
+ return this.id.hashCode();
}
public synchronized void waitFor() throws InterruptedException {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|