LibreOffice Module xmerge (master) 1
ObjectArrayIterator.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19package org.openoffice.xmerge.merger.diff;
20
22
30public final class ObjectArrayIterator implements Iterator {
31
33 private Object [] objArray;
34 private int currentPosition;
35
41 public ObjectArrayIterator(Object [] objArray) {
42 if (objArray != null) {
43 this.objArray = new Object[objArray.length];
44 System.arraycopy(objArray, 0, this.objArray, 0, objArray.length);
46 } else {
47 this.objArray = new Object[0];
48 }
49 }
50
51 public Object next() {
52 if (currentPosition < objArray.length - 1) {
54 return currentElement();
55 } else {
56 return null;
57 }
58 }
59
60 public Object previous() {
61 if (currentPosition > 0) {
63 return currentElement();
64 } else {
65 return null;
66 }
67 }
68
69 public Object start() {
71 return currentElement();
72 }
73
74 public Object end() {
75 if (objArray.length > 0) {
76 currentPosition = objArray.length - 1;
77 }
78 return currentElement();
79 }
80
82 if (objArray.length > 0) {
84 } else {
85 return null;
86 }
87 }
88
94 public void replace(Object object) {
95 objArray[currentPosition] = object;
96 }
97
103 public void insert(Object object) {
104 Object [] objArray2 = new Object[objArray.length+1];
105
106 // copy the array content up before the currentposition
107 if (currentPosition > 0) {
108 System.arraycopy(objArray, 0, objArray2, 0, currentPosition);
109 }
110
111 objArray2[currentPosition] = object;
112
113 // copy the array content up after the currentposition
114 System.arraycopy(objArray, currentPosition, objArray2,
116
117 objArray = objArray2;
119 }
120
126 public void append(Object object) {
127 Object [] objArray2 = new Object[objArray.length + 1];
128
129 int newPosition = currentPosition + 1;
130
131 // copy the array content up to the currentposition
132 System.arraycopy(objArray, 0, objArray2, 0, newPosition);
133
134 objArray2[newPosition] = object;
135
136 // copy the array content up after the currentposition
137 if (currentPosition < objArray.length - 1) {
138 System.arraycopy(objArray, newPosition, objArray2,
139 newPosition + 1, objArray.length - newPosition);
140 }
141
142 objArray = objArray2;
143 }
144
148 public void remove() {
149 Object [] objArray2 = new Object[objArray.length - 1];
150
151 // copy the array content up before the currentposition
152 if (currentPosition > 0) {
153 System.arraycopy(objArray, 0, objArray2, 0, currentPosition);
154 }
155
156 // copy the array content up after the currentposition
157 if (currentPosition < objArray.length - 1) {
158 System.arraycopy(objArray, currentPosition + 1, objArray2,
160 }
161
162 objArray = objArray2;
163
164 if (currentPosition == objArray.length)
166 }
167
168 public int elementCount() {
169 return objArray.length;
170 }
171
172 public boolean equivalent(Object obj1, Object obj2) {
173 return obj1.equals(obj2);
174 }
175
176 public void refresh() {
177 // do nothing
178 }
179}
This is an implementation of the Iterator interface.
Object start()
Move to the beginning of the sequence.
ObjectArrayIterator(Object[] objArray)
Standard constructor.
boolean equivalent(Object obj1, Object obj2)
A method to allow the difference algorithm to test whether the obj1 and obj2 in the Iterator are cons...
Object next()
Move to next element in the sequence.
Object currentElement()
Return the current element Object content.
void insert(Object object)
Insert Object after current Object.
void append(Object object)
Append Object after current Object.
void replace(Object object)
Replace current Object.
int elementCount()
Return the total element count in the sequence.
void refresh()
A method to force the Iterator to traverse the tree again to refresh the content.
This is an interface used by the DiffAlgorithm and MergeAlgorithm to access a Document.
Definition: Iterator.java:27
The DiffAlgorithm and MergeAlgorithm are used to provide the merge capabilities of this project.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...
Definition: Convert.java:19