01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.compare.rangedifferencer;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: /**
16: * A custom iterator to iterate over a List of <code>RangeDifferences</code>.
17: * It is used internally by the <code>RangeDifferencer</code>.
18: */
19: /* package */class DifferencesIterator {
20:
21: List fRange;
22: int fIndex;
23: RangeDifference[] fArray;
24: RangeDifference fDifference;
25:
26: /*
27: * Creates a differences iterator on an array of <code>RangeDifference</code>s.
28: */
29: DifferencesIterator(RangeDifference[] differenceRanges) {
30:
31: fArray = differenceRanges;
32: fIndex = 0;
33: fRange = new ArrayList();
34: if (fIndex < fArray.length)
35: fDifference = fArray[fIndex++];
36: else
37: fDifference = null;
38: }
39:
40: /*
41: * Returns the number of RangeDifferences
42: */
43: int getCount() {
44: return fRange.size();
45: }
46:
47: /*
48: * Appends the edit to its list and moves to the next <code>RangeDifference</code>.
49: */
50: void next() {
51: fRange.add(fDifference);
52: if (fDifference != null) {
53: if (fIndex < fArray.length)
54: fDifference = fArray[fIndex++];
55: else
56: fDifference = null;
57: }
58: }
59:
60: /*
61: * Difference iterators are used in pairs.
62: * This method returns the other iterator.
63: */
64: DifferencesIterator other(DifferencesIterator right,
65: 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: }
|