summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-03-12 16:20:22 (EDT)
committerEike Stepper2007-03-12 16:20:22 (EDT)
commit4dfd056b256be2313d8e08bf01167dfdb3656bd2 (patch)
tree537229a561674f20e4b5838008a40a6f5b920f46
parent3f0f713cc5ec0533cb2a788b99a6f588e0896f10 (diff)
downloadcdo-4dfd056b256be2313d8e08bf01167dfdb3656bd2.zip
cdo-4dfd056b256be2313d8e08bf01167dfdb3656bd2.tar.gz
cdo-4dfd056b256be2313d8e08bf01167dfdb3656bd2.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/container/ManagedContainer.java53
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/factory/Factory.java23
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/factory/FactoryKey.java58
3 files changed, 87 insertions, 47 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/container/ManagedContainer.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/container/ManagedContainer.java
index 68c1ea6..96539c5 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/container/ManagedContainer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/container/ManagedContainer.java
@@ -18,6 +18,7 @@ import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.registry.IRegistry;
import org.eclipse.internal.net4j.util.event.Notifier;
+import org.eclipse.internal.net4j.util.factory.FactoryKey;
import org.eclipse.internal.net4j.util.registry.HashMapRegistry;
import java.io.IOException;
@@ -41,7 +42,7 @@ public class ManagedContainer extends Notifier implements IManagedContainer
private IRegistry<ElementKey, Object> elementRegistry = new HashMapRegistry();
- private long lastElementID;
+ private long maxElementID;
public IFactory[] getFactories()
{
@@ -135,7 +136,7 @@ public class ManagedContainer extends Notifier implements IManagedContainer
element = factory.create(description);
if (element != null)
{
- key.setID(++lastElementID);
+ key.setID(++maxElementID);
elementRegistry.put(key, element);
fireEvent(new SingleDeltaContainerEvent(this, element, IContainerDelta.Kind.ADDED));
}
@@ -200,6 +201,8 @@ public class ManagedContainer extends Notifier implements IManagedContainer
{
}
}
+
+ initMaxElementID();
}
}
@@ -220,47 +223,19 @@ public class ManagedContainer extends Notifier implements IManagedContainer
}
}
- /**
- * @author Eike Stepper
- */
- private static final class FactoryKey
+ public void initMaxElementID()
{
- private String productGroup;
-
- private String factoryType;
-
- public FactoryKey(String productGroup, String factoryType)
- {
- this.productGroup = productGroup;
- this.factoryType = factoryType;
- }
-
- public String getProductGroup()
- {
- return productGroup;
- }
-
- public String getFactoryType()
- {
- return factoryType;
- }
-
- @Override
- public boolean equals(Object obj)
+ synchronized (elementRegistry)
{
- if (obj instanceof FactoryKey)
+ maxElementID = 0;
+ for (ElementKey key : elementRegistry.keySet())
{
- FactoryKey key = (FactoryKey)obj;
- return ObjectUtil.equals(productGroup, key.productGroup) && ObjectUtil.equals(factoryType, key.factoryType);
+ long id = key.getID();
+ if (maxElementID < id)
+ {
+ maxElementID = id;
+ }
}
-
- return false;
- }
-
- @Override
- public int hashCode()
- {
- return ObjectUtil.hashCode(productGroup) ^ ObjectUtil.hashCode(factoryType);
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/factory/Factory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/factory/Factory.java
index dac6048..61bcf1f 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/factory/Factory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/factory/Factory.java
@@ -17,23 +17,30 @@ import org.eclipse.net4j.util.factory.IFactory;
*/
public abstract class Factory<PRODUCT> implements IFactory<PRODUCT>
{
- private String productGroup;
-
- private String type;
+ private FactoryKey key;
public Factory(String productGroup, String type)
{
- this.productGroup = productGroup;
- this.type = type;
+ key = new FactoryKey(productGroup, type);
+ }
+
+ public FactoryKey getKey()
+ {
+ return key;
+ }
+
+ public String getFactoryType()
+ {
+ return key.getFactoryType();
}
public String getProductGroup()
{
- return productGroup;
+ return key.getProductGroup();
}
- public String getType()
+ public String toString()
{
- return type;
+ return key.toString();
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/factory/FactoryKey.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/factory/FactoryKey.java
new file mode 100644
index 0000000..abdb7be
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/util/factory/FactoryKey.java
@@ -0,0 +1,58 @@
+package org.eclipse.internal.net4j.util.factory;
+
+import org.eclipse.net4j.util.ObjectUtil;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ */
+public final class FactoryKey implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private String productGroup;
+
+ private String factoryType;
+
+ public FactoryKey(String productGroup, String factoryType)
+ {
+ this.productGroup = productGroup;
+ this.factoryType = factoryType;
+ }
+
+ public String getProductGroup()
+ {
+ return productGroup;
+ }
+
+ public String getFactoryType()
+ {
+ return factoryType;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof FactoryKey)
+ {
+ FactoryKey key = (FactoryKey)obj;
+ return ObjectUtil.equals(productGroup, key.productGroup) && ObjectUtil.equals(factoryType, key.factoryType);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return ObjectUtil.hashCode(productGroup) ^ ObjectUtil.hashCode(factoryType);
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("{0}[{1}]", productGroup, factoryType);
+ }
+} \ No newline at end of file