KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > texteditor > quickdiff > compare > rangedifferencer > DifferencesIterator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.texteditor.quickdiff.compare.rangedifferencer;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 /**
17  * A custom iterator to iterate over a List of <code>RangeDifferences</code>.
18  * It is used internally by the <code>RangeDifferencer</code>.
19  *
20  * @since 3.0
21  */

22 /* package */ class DifferencesIterator {
23
24     List JavaDoc fRange;
25     int fIndex;
26     RangeDifference[] fArray;
27     RangeDifference fDifference;
28     
29     /**
30      * Creates a differences iterator on an array of <code>RangeDifference</code>s.
31      */

32     DifferencesIterator(RangeDifference[] differenceRanges) {
33         
34         fArray= differenceRanges;
35         fIndex= 0;
36         fRange= new ArrayList JavaDoc();
37         if (fIndex < fArray.length)
38             fDifference= fArray[fIndex++];
39         else
40             fDifference= null;
41     }
42
43     /**
44       * Returns the number of RangeDifferences
45       */

46     int getCount() {
47         return fRange.size();
48     }
49
50     /**
51      * Appends the edit to its list and moves to the next <code>RangeDifference</code>.
52      */

53     void next() {
54         fRange.add(fDifference);
55         if (fDifference != null) {
56             if (fIndex < fArray.length)
57                 fDifference= fArray[fIndex++];
58             else
59                 fDifference= null;
60         }
61     }
62
63     /**
64      * Difference iterators are used in pairs.
65      * This method returns the other iterator.
66      */

67     DifferencesIterator other(DifferencesIterator right, DifferencesIterator left) {
68         if (this == right)
69             return left;
70         return right;
71     }
72
73     /**
74       * Removes all <code>RangeDifference</code>s
75       */

76     void removeAll() {
77         fRange.clear();
78     }
79 }
80
Popular Tags