001: /*
002: ** Java cvs client library package.
003: ** Copyright (c) 1997-2002 by Timothy Gerard Endres
004: **
005: ** This program is free software.
006: **
007: ** You may redistribute it and/or modify it under the terms of the GNU
008: ** Library General Public License (LGPL) as published by the Free Software
009: ** Foundation.
010: **
011: ** Version 2 of the license should be included with this distribution in
012: ** the file LICENSE.txt, as well as License.html. If the license is not
013: ** included with this distribution, you may find a copy at the FSF web
014: ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the Free
015: ** Software Foundation at 59 Temple Place - Suite 330, Boston, MA 02111 USA.
016: **
017: ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
018: ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
019: ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
020: ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
021: ** REDISTRIBUTION OF THIS SOFTWARE.
022: **
023: */
024:
025: package com.ice.cvsc;
026:
027: import java.io.*;
028: import java.lang.*;
029: import java.util.*;
030:
031: /**
032: * The CVSEntryVector class subclasses Vector to specifically
033: * handle CVSEntry ocjects. This subclass adds several convenience
034: * methods for adding and retrieving CVSEntry objects quickly.
035: *
036: * @version $Revision: 2.3 $
037: * @author Timothy Gerard Endres, <a href="mailto:time@ice.com">time@ice.com</a>.
038: * @see CVSClient
039: * @see CVSProject
040: */
041:
042: public class CVSEntryVector extends Vector {
043: static public final String RCS_ID = "$Id: CVSEntryVector.java,v 2.3 2003/07/27 01:08:32 time Exp $";
044: static public final String RCS_REV = "$Revision: 2.3 $";
045:
046: static public boolean traceLocate = false;
047: static public boolean traceLocatePath = false;
048:
049: /**
050: * Indicates if this entry vector is 'dirty'. If this
051: * is true, then an entry was removed from this vector.
052: * Since that entry can not indicate a dirty condition
053: * because it is gone, we must record that state in the
054: * vector itself. We also pick out the added entry case
055: * in the event that the adder forgot to dirty the newly
056: * added entry.
057: */
058: private boolean isDirty;
059:
060: public CVSEntryVector() {
061: super ();
062: this .isDirty = false;
063: }
064:
065: public CVSEntryVector(int initCap) {
066: super (initCap);
067: this .isDirty = false;
068: }
069:
070: public CVSEntryVector(int initCap, int capIncr) {
071: super (initCap, capIncr);
072: this .isDirty = false;
073: }
074:
075: // UNDONE - finalize should removeAllEntries!!!
076:
077: public void removeAllEntries() {
078: // Since we can contain other CVSEntryVector, we
079: // need to recurse on those to be sure all is freed!
080: //
081: for (int i = 0; i < this .size(); ++i) {
082: CVSEntry entry = this .entryAt(i);
083: if (entry.isDirectory()) {
084: entry.removeAllEntries();
085: }
086: }
087:
088: this .removeAllElements();
089: }
090:
091: public CVSEntry entryAt(int index) {
092: return (CVSEntry) this .elementAt(index);
093: }
094:
095: public CVSEntry getEntryAt(int index) {
096: return (CVSEntry) this .elementAt(index);
097: }
098:
099: public void appendEntry(CVSEntry entry) {
100: this .addElement(entry);
101: this .isDirty = true;
102: }
103:
104: private boolean removeEntry(CVSEntry entry) {
105: boolean result;
106:
107: result = this .removeElement(entry);
108: if (result) {
109: this .isDirty = true;
110: }
111:
112: return result;
113: }
114:
115: private boolean removeEntry(String entryName) {
116: for (int i = 0; i < this .size(); ++i) {
117: CVSEntry entry = this .entryAt(i);
118:
119: if (entryName.equals(entry.getName())) {
120: this .removeElementAt(i);
121: this .isDirty = true;
122: return true;
123: }
124: }
125:
126: return false;
127: }
128:
129: /**
130: * Check to see if any entries in this vector are dirty.
131: *
132: * @return If any entry is dirty, returns true, else false.
133: */
134:
135: public boolean isDirty() {
136: if (this .isDirty)
137: return true;
138:
139: for (int i = 0; i < this .size(); ++i) {
140: CVSEntry entry = (CVSEntry) this .elementAt(i);
141: if (entry.isDirty())
142: return true;
143: }
144:
145: return false;
146: }
147:
148: /**
149: * Check to see if any entries in this vector are dirty.
150: *
151: * @return If any entry is dirty, returns true, else false.
152: */
153:
154: public void setDirty(boolean dirty) {
155: this .isDirty = dirty;
156:
157: for (int i = 0; i < this .size(); ++i) {
158: CVSEntry entry = (CVSEntry) this .elementAt(i);
159: entry.setDirty(dirty);
160: }
161: }
162:
163: /**
164: * Locate an entry in this entry vector with the given name.
165: *
166: * @param name The entry's name (without any path).
167: * @return The entry corresponding to name, or null if not found.
168: */
169:
170: public CVSEntry locateEntry(String name) {
171: CVSTracer.traceIf(CVSEntryVector.traceLocate,
172: "===== CVSEntryVector.locateEntry: " + "name '" + name
173: + "' =====");
174:
175: for (int i = 0; i < this .size(); ++i) {
176: CVSEntry entry = (CVSEntry) this .elementAt(i);
177:
178: CVSTracer.traceIf(CVSEntryVector.traceLocate,
179: "CVSEntryVector.locateEntry: ENTRY '"
180: + entry.getFullName() + "' isDir '"
181: + entry.isDirectory() + "'");
182:
183: if (name.equals(entry.getName())) {
184: CVSTracer.traceIf(CVSEntryVector.traceLocate,
185: "CVSEntryVector.locateEntry: '"
186: + entry.getFullName() + "' FOUND.");
187: return entry;
188: }
189: }
190:
191: CVSTracer
192: .traceIf(CVSEntryVector.traceLocate,
193: "CVSEntryVector.locateEntry: '" + name
194: + "' NOT FOUND.");
195:
196: return null;
197: }
198:
199: }
|