updates on the change tracker
authorzapata <zapata>
Sat, 11 Nov 2006 15:42:22 +0000 (15:42 +0000)
committerzapata <zapata>
Sat, 11 Nov 2006 15:42:22 +0000 (15:42 +0000)
source/mir/changetracker/ChangeReporter.java
source/mir/changetracker/ChangeTracker.java
source/mir/changetracker/ChangeType.java [new file with mode: 0644]

index 84f8bde..401721b 100644 (file)
@@ -87,7 +87,7 @@ public class ChangeReporter {
           }
 
           if (aFlush) {
-            aTracker.clearChanges(changesToReport);
+            aTracker.removeChanges(changesToReport);
           }
         }
         finally {
index 7b5d2c7..41dca6f 100644 (file)
@@ -32,6 +32,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Arrays;
+import java.util.Collection;
 
 /**
  * Change tracker, tracks changes to a path based repository.
@@ -39,79 +40,104 @@ import java.util.Arrays;
  */
 
 public class ChangeTracker {
-  private List changes;
-
-  public ChangeTracker() {
-    changes = new ArrayList();
-  }
+  private final List changes = new ArrayList();
 
   /**
-   * Adds a single change
+   * Add a single change. A change is represented by the full path
+   * of the file involved.
    */
-  public void addChange(String aPath) {
+  public void addChange(String aPath, ChangeType aChangeType) {
     synchronized (changes) {
-      changes.add(aPath);
+      changes.add(new Change(aPath, aChangeType));
     }
   }
 
   /**
-   * Adds an array of changes
+   * Add an array of changes. Each change is represented by the full path
+   * of the file involved.
    */
-  public void addChanges(String[] aPaths) {
-    addChanges(Arrays.asList(aPaths));
+  public void addChanges(String[] aPaths, ChangeType aChangeType) {
+    addChanges(Arrays.asList(aPaths), aChangeType);
   }
 
   /**
-   * Adds a <code>List</code> of changes
+   * Adds a <code>Collection</code> of changes. Each change is represented by the
+   * full path of the file involved.
    */
-  public void addChanges(List aChanges) {
+  public void addChanges(Collection aChanges, ChangeType aChangeType) {
     synchronized (changes) {
-      changes.addAll(aChanges);
+      Iterator i = aChanges.iterator();
+      while (i.hasNext()) {
+        addChange((String) i.next(), aChangeType);
+      }
     }
   }
 
+  public class Change {
+    private ChangeType type;
+    private String path;
+
+    Change(String anAbsolutePath, ChangeType aType) {
+      type = aType;
+      path = anAbsolutePath;
+    }
+
+    public String getPath() {
+      return path;
+    }
+
+    public ChangeType getType() {
+      return type;
+    }
+
+  }
+
   /**
-   * Returns changes within a base path, and removes them from the
-   *     tracker.
+   * Returns a <code>Collection</code> of {@link Change}s within a base
+   *     path, and removes them from the tracker.
    */
-  public List flushChanges(String aBasePath) {
+  List flushChanges(String aBasePath) {
     return flushChanges(aBasePath, new String[0]);
   }
 
   /**
-   * Returns changes within a base path, and removes them from the
-   *     tracker.
+   * Returns a <code>Collection</code> of {@link Change}s within a base
+   *     path, exluding a list of excluded paths, and removes them from
+   *     the tracker.
    */
-  public List flushChanges(String aBasePath, String[] anExcludedPaths) {
+  List flushChanges(String aBasePath, String[] anExcludedPaths) {
     synchronized (changes) {
       List result = getChanges(aBasePath, anExcludedPaths);
 
-      clearChanges(result);
+      removeChanges(result);
 
       return result;
     }
   }
 
   /**
-   * Removes changes from the tracker
+   * Remove specific changes from the change tracker.
+   *
+   * @param someChanges a <code>Collection</code> of changes represented by
+   * their full path in the form of a <code>String</code>
    */
-  public void clearChanges(List aChanges) {
+  void removeChanges(Collection someChanges) {
     synchronized (changes) {
-      changes.removeAll(aChanges);
+      changes.removeAll(someChanges);
     }
   }
 
   /**
    * Returns all changes within a base path
    */
-  public List getChanges(String aBasePath) {
+  List getChanges(String aBasePath) {
     synchronized (changes) {
       List result = new ArrayList();
 
       Iterator i = changes.iterator();
       while (i.hasNext()) {
-        String change = (String) i.next();
-        if (change.startsWith(aBasePath))
+        Change change = (Change) i.next();
+        if (change.getPath().startsWith(aBasePath))
           result.add(change);
       }
 
@@ -122,7 +148,7 @@ public class ChangeTracker {
   /**
    * gets all changes within a base path, but excluding some other paths
    */
-  public List getChanges(String aBasePath, String[] anExcludingPaths) {
+  List getChanges(String aBasePath, String[] anExcludingPaths) {
     synchronized (changes) {
       List result = getChanges(aBasePath);
 
@@ -130,9 +156,9 @@ public class ChangeTracker {
         List remove = new ArrayList();
         Iterator j = result.iterator();
         while (j.hasNext()) {
-          String item = (String) j.next();
-          if (item.startsWith(anExcludingPaths[i])) {
-            remove.add(item);
+          Change change = (Change) j.next();
+          if (change.getPath().startsWith(anExcludingPaths[i])) {
+            remove.add(change);
           }
         }
         result.removeAll(remove);
diff --git a/source/mir/changetracker/ChangeType.java b/source/mir/changetracker/ChangeType.java
new file mode 100644 (file)
index 0000000..a22d70f
--- /dev/null
@@ -0,0 +1,33 @@
+package mir.changetracker;\r
+\r
+/**\r
+ * Class that is used to indicate the kind of change\r
+ */\r
+public final class ChangeType {\r
+  private String name;\r
+\r
+  ChangeType(String aName) {\r
+    name = aName;\r
+  }\r
+\r
+  public String getName() {\r
+    return name;\r
+  }\r
+\r
+  /**\r
+   * <code>ChangeType</code> indicating the file(s) in question have been added.\r
+   */\r
+  public static final ChangeType ADDITION = new ChangeType("Addition");\r
+\r
+  /**\r
+   * <code>ChangeType</code> indicating the file(s) in question have been modified.\r
+   */\r
+  public static final ChangeType MODIFICATION = new ChangeType("Modification");\r
+\r
+  /**\r
+   * The file(s) in question have been deleted.\r
+   */\r
+  public static final ChangeType DELETION = new ChangeType("Deletion");\r
+\r
+\r
+}\r