diff dwtx/core/commands/contexts/ContextManager.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 6518c18a01f7
children
line wrap: on
line diff
--- a/dwtx/core/commands/contexts/ContextManager.d	Sun Aug 03 17:01:51 2008 +0200
+++ b/dwtx/core/commands/contexts/ContextManager.d	Thu Aug 07 15:01:33 2008 +0200
@@ -13,10 +13,6 @@
 
 module dwtx.core.commands.contexts.ContextManager;
 
-import tango.util.collection.HashSet;
-import tango.util.collection.model.Set;
-import tango.util.collection.model.SetView;
-
 import dwtx.core.commands.contexts.IContextListener;
 import dwtx.core.commands.contexts.IContextManagerListener;
 import dwtx.core.commands.contexts.ContextEvent;
@@ -27,6 +23,7 @@
 import dwtx.core.internal.commands.util.Util;
 
 import dwt.dwthelper.utils;
+import dwtx.dwtxhelper.Collection;
 
 /**
  * <p>
@@ -58,8 +55,8 @@
      * The set of active context identifiers. This value may be empty, but it is
      * never <code>null</code>.
      */
-    private Set!(String) activeContextIds;
-    private static Set!(String) EMPTY_SET;
+    private Set activeContextIds;
+    private static Set EMPTY_SET;
 
     // allow the ContextManager to send one event for a larger delta
     private bool caching = false;
@@ -68,12 +65,12 @@
 
     private bool activeContextsChange = false;
 
-    private Set!(String) oldIds = null;
+    private Set oldIds = null;
 
     public this(){
-        activeContextIds = new HashSet!(String);
+        activeContextIds = new HashSet();
         if( EMPTY_SET is null ){
-            EMPTY_SET = new HashSet!(String);
+            EMPTY_SET = new HashSet();
         }
     }
 
@@ -107,7 +104,7 @@
         if (caching) {
             activeContextIds.add(contextId);
         } else {
-            Set!(String) previouslyActiveContextIds = activeContextIds.duplicate();
+            Set previouslyActiveContextIds = new HashSet(activeContextIds);
             activeContextIds.add(contextId);
 
             fireContextManagerChanged(new ContextManagerEvent(this, null,
@@ -115,7 +112,7 @@
         }
 
         if (DEBUG) {
-            Tracing.printTrace("CONTEXTS", SetToString(activeContextIds)); //$NON-NLS-1$
+            Tracing.printTrace("CONTEXTS", activeContextIds.toString()); //$NON-NLS-1$
         }
 
     }
@@ -178,8 +175,8 @@
      *         the set is not <code>null</code>, then it contains only
      *         instances of <code>String</code>.
      */
-    public final SetView!(String) getActiveContextIds() {
-        return /+Collections.unmodifiableSet(+/activeContextIds/+)+/;
+    public final Set getActiveContextIds() {
+        return Collections.unmodifiableSet(activeContextIds);
     }
 
     /**
@@ -198,7 +195,7 @@
         Context context = cast(Context) handleObjectsById.get(contextId);
         if (context is null) {
             context = new Context(contextId);
-            handleObjectsById.add(contextId, context);
+            handleObjectsById.put(contextId, context);
             context.addContextListener(this);
         }
 
@@ -211,7 +208,7 @@
      * @return The set of defined context identifiers; this value may be empty,
      *         but it is never <code>null</code>.
      */
-    public final Set!(String) getDefinedContextIds() {
+    public final Set getDefinedContextIds() {
         return getDefinedHandleObjectIds();
     }
 
@@ -223,8 +220,8 @@
      * @since 3.2
      */
     public final Context[] getDefinedContexts() {
-        return cast(Context[]) definedHandleObjects
-                .toArray(/+new Context[definedHandleObjects.size()]+/);
+        return arraycast!(Context)( definedHandleObjects
+                .toArray(/+new Context[definedHandleObjects.size()]+/));
     }
 
     /**
@@ -243,7 +240,7 @@
         if (caching) {
             activeContextIds.remove(contextId);
         } else {
-            auto previouslyActiveContextIds = activeContextIds.dup;
+            Set previouslyActiveContextIds = new HashSet(activeContextIds);
             activeContextIds.remove(contextId);
 
             fireContextManagerChanged(new ContextManagerEvent(this, null,
@@ -251,18 +248,9 @@
         }
 
         if (DEBUG) {
-            Tracing.printTrace("CONTEXTS", SetToString(activeContextIds)); //$NON-NLS-1$
+            Tracing.printTrace("CONTEXTS", activeContextIds.toString()); //$NON-NLS-1$
         }
     }
-    private String SetToString( Set!(String) set ){
-        String s = "[";
-        foreach( id; set ){
-            if( s.length > 1 ) s ~= ", ";
-            s ~= id;
-        }
-        s ~= "]";
-        return s;
-    }
     /**
      * Removes a listener from this context manager.
      *
@@ -283,23 +271,24 @@
      *            The new set of active context identifiers; may be
      *            <code>null</code>.
      */
-    public final void setActiveContextIds(Set!(String) activeContextIds) {
-        if (Util.equals(this.activeContextIds.toArray, activeContextIds.toArray)) {
+    public final void setActiveContextIds(Set activeContextIds) {
+        if (Util.equals(cast(Object)this.activeContextIds, cast(Object)activeContextIds)) {
             return;
         }
 
         activeContextsChange = true;
 
-        Set!(String) previouslyActiveContextIds = this.activeContextIds;
+        Set previouslyActiveContextIds = this.activeContextIds;
         if (activeContextIds !is null) {
-            this.activeContextIds = activeContextIds.duplicate;
+            this.activeContextIds = new HashSet();
+            this.activeContextIds.addAll(activeContextIds);
         } else {
             this.activeContextIds = null;
         }
 
         if (DEBUG) {
             Tracing.printTrace("CONTEXTS", (activeContextIds is null) ? "none" //$NON-NLS-1$ //$NON-NLS-2$
-                    : SetToString(activeContextIds));
+                    : activeContextIds.toString());
         }
 
         if (!caching) {
@@ -322,10 +311,10 @@
         }
         caching = cache;
         bool fireChange = activeContextsChange;
-        Set!(String) holdOldIds = (oldIds is null? EMPTY_SET : oldIds );
+        Set holdOldIds = (oldIds is null?Collections.EMPTY_SET:oldIds);
 
         if (caching) {
-            oldIds = activeContextIds.duplicate;
+            oldIds = new HashSet(activeContextIds);
         } else {
             oldIds = null;
         }