2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with any library licensed under the Apache Software License,
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
23 * (or with modified versions of the above that use the same license as the above),
24 * and distribute linked combinations including the two. You must obey the
25 * GNU General Public License in all respects for all of the code used other than
26 * the above mentioned libraries. If you modify this file, you may extend this
27 * exception to your version of the file, but you are not obligated to do so.
28 * If you do not wish to do so, delete this exception statement from your version.
31 package mir.changetracker;
33 import java.util.ArrayList;
34 import java.util.Iterator;
35 import java.util.List;
36 import java.util.Arrays;
39 * Change tracker, tracks changes to a path based repository.
40 * All methods are thread-safe
43 public class ChangeTracker {
46 public ChangeTracker() {
47 changes = new ArrayList();
51 * Adds a single change
53 public void addChange(String aPath) {
54 synchronized (changes) {
60 * Adds an array of changes
62 public void addChanges(String[] aPaths) {
63 addChanges(Arrays.asList(aPaths));
67 * Adds a <code>List</code> of changes
69 public void addChanges(List aChanges) {
70 synchronized (changes) {
71 changes.addAll(aChanges);
76 * Returns changes within a base path, and removes them from the
79 public List flushChanges(String aBasePath) {
80 return flushChanges(aBasePath, new String[0]);
84 * Returns changes within a base path, and removes them from the
87 public List flushChanges(String aBasePath, String[] anExcludedPaths) {
88 synchronized (changes) {
89 List result = getChanges(aBasePath, anExcludedPaths);
98 * Removes changes from the tracker
100 public void clearChanges(List aChanges) {
101 synchronized (changes) {
102 changes.removeAll(aChanges);
107 * Returns all changes within a base path
109 public List getChanges(String aBasePath) {
110 synchronized (changes) {
111 List result = new ArrayList();
113 Iterator i = changes.iterator();
114 while (i.hasNext()) {
115 String change = (String) i.next();
116 if (change.startsWith(aBasePath))
125 * gets all changes within a base path, but excluding some other paths
127 public List getChanges(String aBasePath, String[] anExcludingPaths) {
128 synchronized (changes) {
129 List result = getChanges(aBasePath);
131 for (int i=0; i<anExcludingPaths.length && result.size()>0; i++) {
132 List remove = new ArrayList();
133 Iterator j = result.iterator();
134 while (j.hasNext()) {
135 String item = (String) j.next();
136 if (item.startsWith(anExcludingPaths[i])) {
140 result.removeAll(remove);