org.eclipse.compare.rangedifferencer.DifferencesIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docx4j Show documentation
Show all versions of docx4j Show documentation
docx4j is a library which helps you to work with the Office Open
XML file format as used in docx
documents, pptx presentations, and xlsx spreadsheets.
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.compare.rangedifferencer;
import java.util.ArrayList;
import java.util.List;
/**
* A custom iterator to iterate over a List of RangeDifferences
.
* It is used internally by the RangeDifferencer
.
*/
/* package */class DifferencesIterator {
List fRange;
int fIndex;
RangeDifference[] fArray;
RangeDifference fDifference;
/*
* Creates a differences iterator on an array of RangeDifference
s.
*/
DifferencesIterator(RangeDifference[] differenceRanges) {
fArray = differenceRanges;
fIndex = 0;
fRange = new ArrayList();
if (fIndex < fArray.length)
fDifference = fArray[fIndex++];
else
fDifference = null;
}
/*
* Returns the number of RangeDifferences
*/
int getCount() {
return fRange.size();
}
/*
* Appends the edit to its list and moves to the next RangeDifference
.
*/
void next() {
fRange.add(fDifference);
if (fDifference != null) {
if (fIndex < fArray.length)
fDifference = fArray[fIndex++];
else
fDifference = null;
}
}
/*
* Difference iterators are used in pairs. This method returns the other
* iterator.
*/
DifferencesIterator other(DifferencesIterator right,
DifferencesIterator left) {
if (this == right)
return left;
return right;
}
/*
* Removes all RangeDifference
s
*/
void removeAll() {
fRange.clear();
}
}