[FOray-commit] SF.net SVN: foray:[11795] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2021-01-15 18:58:55
|
Revision: 11795
http://sourceforge.net/p/foray/code/11795
Author: victormote
Date: 2021-01-15 18:58:47 +0000 (Fri, 15 Jan 2021)
Log Message:
-----------
Add primitive iterator implementations for the primitive sequence classes. Conform to related aXSL changes in the primitive sequence interfaces.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/CharArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/IntSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/package-info.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfCrossRefInfo.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/BooleanSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortSequenceIterator.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -29,7 +29,9 @@
package org.foray.common.data;
import org.foray.common.primitive.ByteUtils;
+import org.foray.common.sequence.ByteSequenceIterator;
+import org.axsl.common.sequence.BytePrimitiveIterator;
import org.axsl.common.sequence.ByteSequence;
import org.axsl.common.sequence.ByteSequencePlus;
@@ -660,4 +662,14 @@
return this;
}
+ @Override
+ public BytePrimitiveIterator iterator() {
+ return new ByteSequenceIterator(this);
+ }
+
+ @Override
+ public BytePrimitiveIterator iteratorReverse() {
+ return new ByteSequenceIterator(this, true);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -28,6 +28,7 @@
package org.foray.common.data;
+import org.axsl.common.sequence.IntPrimitiveIterator;
import org.axsl.common.sequence.IntSequencePlus;
/**
@@ -52,12 +53,12 @@
}
@Override
- public IntSequenceIterator iterator() {
+ public IntPrimitiveIterator iterator() {
return new org.foray.common.data.IntSequenceIterator(this);
}
@Override
- public IntSequenceIterator iteratorReverse() {
+ public IntPrimitiveIterator iteratorReverse() {
return new org.foray.common.data.IntSequenceIterator(this, true);
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/CharArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/CharArrayBuilder.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/CharArrayBuilder.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -28,6 +28,9 @@
package org.foray.common.data;
+import org.foray.common.sequence.CharSequenceIterator;
+
+import org.axsl.common.sequence.CharPrimitiveIterator;
import org.axsl.common.sequence.CharSequenceMutable;
import org.axsl.common.sequence.CharSequencePlus;
@@ -295,4 +298,14 @@
return this;
}
+ @Override
+ public CharPrimitiveIterator iterator() {
+ return new CharSequenceIterator(this);
+ }
+
+ @Override
+ public CharPrimitiveIterator iteratorReverse() {
+ return new CharSequenceIterator(this, true);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/IntSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/IntSequenceIterator.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/IntSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -35,7 +35,7 @@
/**
* Iterates an instance of {@link IntSequence}.
*/
-public class IntSequenceIterator implements org.axsl.common.sequence.IntSequenceIterator {
+public class IntSequenceIterator implements org.axsl.common.sequence.IntPrimitiveIterator {
/** The sequence being iterated. */
private IntSequence sequence;
@@ -94,7 +94,7 @@
* Check {@link #hasNext()} first to avoid this exception.
* @see java.util.Iterator#next()
*/
- public int next() {
+ public int nextInt() {
if (! hasNext()) {
throw new NoSuchElementException();
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArray.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArray.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -28,6 +28,9 @@
package org.foray.common.data;
+import org.foray.common.sequence.LongSequenceIterator;
+
+import org.axsl.common.sequence.LongPrimitiveIterator;
import org.axsl.common.sequence.LongSequence;
import org.axsl.common.sequence.LongSequenceMutable;
import org.axsl.common.sequence.LongSequencePlus;
@@ -137,4 +140,14 @@
return null;
}
+ @Override
+ public LongPrimitiveIterator iterator() {
+ return new LongSequenceIterator(this);
+ }
+
+ @Override
+ public LongPrimitiveIterator iteratorReverse() {
+ return new LongSequenceIterator(this, true);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArrayBuilder.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArrayBuilder.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -28,6 +28,9 @@
package org.foray.common.data;
+import org.foray.common.sequence.LongSequenceIterator;
+
+import org.axsl.common.sequence.LongPrimitiveIterator;
import org.axsl.common.sequence.LongSequence;
import org.axsl.common.sequence.LongSequenceMutable;
import org.axsl.common.sequence.LongSequencePlus;
@@ -295,4 +298,14 @@
return this;
}
+ @Override
+ public LongPrimitiveIterator iterator() {
+ return new LongSequenceIterator(this);
+ }
+
+ @Override
+ public LongPrimitiveIterator iteratorReverse() {
+ return new LongSequenceIterator(this, true);
+ }
+
}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/BooleanSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/BooleanSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/BooleanSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.BooleanPrimitiveIterator;
+import org.axsl.common.sequence.BooleanSequence;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link BooleanSequence}.
+ */
+public class BooleanSequenceIterator implements BooleanPrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private BooleanSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public BooleanSequenceIterator(final BooleanSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public BooleanSequenceIterator(final BooleanSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public boolean nextBoolean() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final boolean returnValue = sequence.booleanAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final boolean returnValue = sequence.booleanAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.BytePrimitiveIterator;
+import org.axsl.common.sequence.ByteSequence;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link ByteSequence}.
+ */
+public class ByteSequenceIterator implements BytePrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private ByteSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public ByteSequenceIterator(final ByteSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public ByteSequenceIterator(final ByteSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public byte nextByte() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final byte returnValue = sequence.byteAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final byte returnValue = sequence.byteAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.CharPrimitiveIterator;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link CharSequence}.
+ */
+public class CharSequenceIterator implements CharPrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private CharSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public CharSequenceIterator(final CharSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public CharSequenceIterator(final CharSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public char nextChar() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final char returnValue = sequence.charAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final char returnValue = sequence.charAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.LongPrimitiveIterator;
+import org.axsl.common.sequence.LongSequence;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link LongSequence}.
+ */
+public class LongSequenceIterator implements LongPrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private LongSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public LongSequenceIterator(final LongSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public LongSequenceIterator(final LongSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public long nextLong() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final long returnValue = sequence.longAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final long returnValue = sequence.longAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.ShortPrimitiveIterator;
+import org.axsl.common.sequence.ShortSequence;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link ShortSequence}.
+ */
+public class ShortSequenceIterator implements ShortPrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private ShortSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public ShortSequenceIterator(final ShortSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public ShortSequenceIterator(final ShortSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public short nextShort() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final short returnValue = sequence.shortAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final short returnValue = sequence.shortAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/package-info.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/package-info.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/package-info.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -27,6 +27,7 @@
*/
/**
+ * Implementations of the interfaces in {@link org.axsl.common.sequence}.
* Wrappers of primitive arrays, intended to make array handling more safe and more flexible, and to make code using
* them more fluent.
*/
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -45,21 +45,21 @@
public void testForwardIterator() {
final IntSequenceIterator out = new IntSequenceIterator(array1);
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(5, out.next());
+ Assert.assertEquals(5, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(-5, out.next());
+ Assert.assertEquals(-5, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(100, out.next());
+ Assert.assertEquals(100, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(-100, out.next());
+ Assert.assertEquals(-100, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(Integer.MAX_VALUE, out.next());
+ Assert.assertEquals(Integer.MAX_VALUE, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(Integer.MIN_VALUE, out.next());
+ Assert.assertEquals(Integer.MIN_VALUE, out.nextInt());
Assert.assertFalse(out.hasNext());
try {
- out.next();
+ out.nextInt();
Assert.fail("NoSuchElementException expected here.");
} catch (final NoSuchElementException e) {
/* This is the expected path. */
@@ -70,21 +70,21 @@
public void testReverseIterator() {
final IntSequenceIterator out = new IntSequenceIterator(array1, true);
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(Integer.MIN_VALUE, out.next());
+ Assert.assertEquals(Integer.MIN_VALUE, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(Integer.MAX_VALUE, out.next());
+ Assert.assertEquals(Integer.MAX_VALUE, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(-100, out.next());
+ Assert.assertEquals(-100, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(100, out.next());
+ Assert.assertEquals(100, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(-5, out.next());
+ Assert.assertEquals(-5, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(5, out.next());
+ Assert.assertEquals(5, out.nextInt());
Assert.assertFalse(out.hasNext());
try {
- out.next();
+ out.nextInt();
Assert.fail("NoSuchElementException expected here.");
} catch (final NoSuchElementException e) {
/* This is the expected path. */
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfCrossRefInfo.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfCrossRefInfo.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfCrossRefInfo.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -30,10 +30,11 @@
import org.foray.common.data.ByteArrayBuilder;
import org.foray.common.data.IntArrayBuilder;
-import org.foray.common.data.IntSequenceIterator;
import org.foray.common.primitive.StringUtils;
import org.foray.pdf.object.PdfObject;
+import org.axsl.common.sequence.IntPrimitiveIterator;
+
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -104,7 +105,7 @@
* The deferred list is conceptually stack-like, so the iterator returns the object IDs in reverse order.
* @return A new iterator over the deferred indirect object IDs.
*/
- public IntSequenceIterator iteratorForDeferred() {
+ public IntPrimitiveIterator iteratorForDeferred() {
return this.indirectWriteLast.iteratorReverse();
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -38,7 +38,6 @@
import org.foray.common.ColorUtil;
import org.foray.common.data.ByteArrayBuilder;
-import org.foray.common.data.IntSequenceIterator;
import org.foray.pdf.PdfConstants;
import org.foray.pdf.PdfCrossRefEntry;
import org.foray.pdf.PdfCrossRefInfo;
@@ -46,6 +45,7 @@
import org.foray.pdf.PdfParser;
import org.axsl.common.Gradient;
+import org.axsl.common.sequence.IntPrimitiveIterator;
import org.axsl.font.Font;
import org.axsl.font.FontUse;
import org.axsl.graphic.Graphic;
@@ -289,9 +289,9 @@
}
private void writeDeferredIndirectObjects(final OutputStream output) throws PdfException {
- final IntSequenceIterator deferredObjectIterator = this.xrefInfo.iteratorForDeferred();
+ final IntPrimitiveIterator deferredObjectIterator = this.xrefInfo.iteratorForDeferred();
while (deferredObjectIterator.hasNext()) {
- final int objectId = deferredObjectIterator.next();
+ final int objectId = deferredObjectIterator.nextInt();
final PdfCrossRefEntry xref = this.xrefInfo.getTableEntry(objectId);
final PdfObject o = xref.getObject();
xref.setOffset(this.position);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|