KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > rangedifferencer > DifferencesIterator


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

11 package org.eclipse.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 /* package */ class DifferencesIterator {
21
22     List JavaDoc fRange;
23     int fIndex;
24     RangeDifference[] fArray;
25     RangeDifference fDifference;
26     
27     /*
28      * Creates a differences iterator on an array of <code>RangeDifference</code>s.
29      */

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

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

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

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

74     void removeAll() {
75         fRange.clear();
76     }
77 }
78
Popular Tags