1 /*
2 Bloof - visualize the evolution of your software project
3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de>
4 http://bloof.sf.net/
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 $RCSfile: RevisionIterator.java,v $
19 Created on $Date: 2003/09/06 08:35:09 $
20 */
21 package net.sf.bloof.scm.cvsplugin;
22
23 import net.sf.bloof.scm.ScmRevision;
24 import net.sf.bloof.scm.ScmRevisionIterator;
25
26 import java.io.Reader;
27 import java.util.NoSuchElementException;
28 import java.util.Vector;
29
30 /***
31 * SCM Iterator on all revision of the specified CVS module
32 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
33 * @version $Id: RevisionIterator.java,v 1.14 2003/09/06 08:35:09 pekacki Exp $
34 */
35 public class RevisionIterator implements ScmRevisionIterator {
36
37 /***
38 * Constructor RevisionIterator
39 * @param aReader <code>Reader</code> on the CVS log file
40 */
41 public RevisionIterator(Reader aReader) {
42 mParser = new LogParser(aReader, this);
43 Thread parserThread = new Thread(mParser);
44 parserThread.start();
45 }
46
47 protected void addRevision(Revision aR) {
48 synchronized (this) {
49 mRevisionBuffer.add(aR);
50 notifyAll();
51 }
52
53 }
54 /***
55 * @see net.sf.bloof.scm.ScmRevisionIterator#getNext( )
56 */
57 public ScmRevision getNext() throws NoSuchElementException {
58 while (mRevisionBuffer.size() == 0 && !mParserHasFinished) {
59 synchronized (this) {
60 try {
61 wait();
62 } catch (InterruptedException e) {
63 e.printStackTrace();
64 }
65 }
66 }
67
68 if (mRevisionBuffer.size() > 0) {
69 synchronized (this) {
70 return (ScmRevision) mRevisionBuffer.remove(0);
71 }
72 } else {
73 throw new NoSuchElementException("No more revisions.");
74 }
75
76 }
77
78 /***
79 * @see net.sf.bloof.scm.ScmRevisionIterator#hasNext( )
80 */
81 public boolean hasNext() {
82 while (!mParserHasFinished && mRevisionBuffer.size() == 0) {
83 synchronized (this) {
84 try {
85 wait();
86 } catch (InterruptedException e) {
87 // do nothing
88 }
89 }
90 }
91 return mRevisionBuffer.size() > 0;
92 }
93
94 protected void parserHasFinished() {
95 mParserHasFinished = true;
96 synchronized (this) {
97 this.notifyAll();
98 }
99 }
100
101 private LogParser mParser;
102
103 private boolean mParserHasFinished = false;
104
105 private Vector mRevisionBuffer = new Vector();
106
107 }
This page was automatically generated by Maven