From: zapata Date: Sat, 11 Nov 2006 15:42:22 +0000 (+0000) Subject: updates on the change tracker X-Git-Tag: LATEST_MERGED_1_1~37 X-Git-Url: http://erislabs.net/gitweb/?p=mir.git;a=commitdiff_plain;h=4335a4f3724bb39a822e4cc16f7edb894d587a16 updates on the change tracker --- diff --git a/source/mir/changetracker/ChangeReporter.java b/source/mir/changetracker/ChangeReporter.java index 84f8bde5..401721b1 100644 --- a/source/mir/changetracker/ChangeReporter.java +++ b/source/mir/changetracker/ChangeReporter.java @@ -87,7 +87,7 @@ public class ChangeReporter { } if (aFlush) { - aTracker.clearChanges(changesToReport); + aTracker.removeChanges(changesToReport); } } finally { diff --git a/source/mir/changetracker/ChangeTracker.java b/source/mir/changetracker/ChangeTracker.java index 7b5d2c7d..41dca6f3 100644 --- a/source/mir/changetracker/ChangeTracker.java +++ b/source/mir/changetracker/ChangeTracker.java @@ -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 List of changes + * Adds a Collection 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 Collection 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 Collection 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 Collection of changes represented by + * their full path in the form of a String */ - 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 index 00000000..a22d70f6 --- /dev/null +++ b/source/mir/changetracker/ChangeType.java @@ -0,0 +1,33 @@ +package mir.changetracker; + +/** + * Class that is used to indicate the kind of change + */ +public final class ChangeType { + private String name; + + ChangeType(String aName) { + name = aName; + } + + public String getName() { + return name; + } + + /** + * ChangeType indicating the file(s) in question have been added. + */ + public static final ChangeType ADDITION = new ChangeType("Addition"); + + /** + * ChangeType indicating the file(s) in question have been modified. + */ + public static final ChangeType MODIFICATION = new ChangeType("Modification"); + + /** + * The file(s) in question have been deleted. + */ + public static final ChangeType DELETION = new ChangeType("Deletion"); + + +}