[FOray-commit] SF.net SVN: foray:[12668] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-06-20 18:32:44
|
Revision: 12668
http://sourceforge.net/p/foray/code/12668
Author: victormote
Date: 2022-06-20 18:32:41 +0000 (Mon, 20 Jun 2022)
Log Message:
-----------
Move NibbleArrayBuilder to correct package. Rough-in implementation of related aXSL interface.
Modified Paths:
--------------
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/PatternTreeTests.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/NibbleArrayBuilder.java
trunk/foray/foray-common/src/test/java/org/foray/common/sequence/NibbleArrayBuilderTests.java
Removed Paths:
-------------
trunk/foray/foray-common/src/main/java/org/foray/common/data/NibbleArrayBuilder.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/NibbleArrayBuilderTests.java
Deleted: trunk/foray/foray-common/src/main/java/org/foray/common/data/NibbleArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/NibbleArrayBuilder.java 2022-06-20 17:30:22 UTC (rev 12667)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/NibbleArrayBuilder.java 2022-06-20 18:32:41 UTC (rev 12668)
@@ -1,253 +0,0 @@
-/*
- * Copyright 2004 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.data;
-
-import org.foray.common.WellKnownConstants;
-import org.foray.common.primitive.BitUtils;
-import org.foray.common.primitive.NumberUtils;
-import org.foray.common.sequence.ByteArrayBuilder;
-
-import java.io.Serializable;
-
-/**
- * A vector of nibbles, or half bytes. The purpose of this class is to reduce by approximately half
- * the amount of memory needed to store a data structure which only needs 4 bits for each element.
- */
-public class NibbleArrayBuilder implements Serializable {
-
- /** Constant needed for serialization. */
- private static final long serialVersionUID = -8706615311680792485L;
-
- /** Default Capacity increment size. */
- private static final int DEFAULT_BLOCK_SIZE = 2048;
-
- /** Capacity increment size. */
- private int blockSize = NibbleArrayBuilder.DEFAULT_BLOCK_SIZE;
-
- /** The encapsulated ByteArrayBuilder that actually contains the data. */
- private ByteArrayBuilder backingVector;
-
- /** Index to to the next free item in this vector. */
- private int nextIndex = 0;
-
- /**
- * No-argument constructor.
- */
- public NibbleArrayBuilder() {
- this(NibbleArrayBuilder.DEFAULT_BLOCK_SIZE);
- }
-
- /**
- * Constructor.
- * @param capacity The initial capacity, in half-bytes, of the new vector.
- */
- public NibbleArrayBuilder(final int capacity) {
- if (capacity > 0) {
- this.blockSize = capacity;
- } else {
- this.blockSize = NibbleArrayBuilder.DEFAULT_BLOCK_SIZE;
- }
- final int byteCapacity = computeByteCapacity(this.blockSize);
- this.backingVector = new ByteArrayBuilder(byteCapacity);
- }
-
- /**
- * Returns the number of half-byte items in the vector.
- * @return The number of items in the vector.
- */
- public int length() {
- return this.nextIndex;
- }
-
- /**
- * Returns the number of bytes actually used to store the vector content.
- * @return The number of bytes used to store the vector content.
- */
- public int lengthInBytes() {
- return this.backingVector.length();
- }
-
- /**
- * Returns the current capacity of the vector, in half-bytes.
- * @return The currect capacity of the vector.
- */
- public int capacity() {
- return this.backingVector.capacity() * 2;
- }
-
- /**
- * Converts an index specified for nibbles into the correct index to use to retrieve the byte
- * containing that nibble.
- * @param nibbleIndex The index to the nibble.
- * @return The index to the matching byte.
- */
- public int computeByteIndex(final int nibbleIndex) {
- return nibbleIndex / 2;
- }
-
- /**
- * Converts an capacity specified for nibbles into the correct capacity to use to for bytes.
- * This is similar to {@link #computeByteIndex(int)}, but rounds the number of bytes up to
- * ensure that all half-bytes have room.
- * @param nibbleCapacity The capacity in half-bytes.
- * @return The capacity in bytes.
- */
- int computeByteCapacity(final int nibbleCapacity) {
- int byteCapacity = nibbleCapacity / 2;
- if (NumberUtils.isOdd(nibbleCapacity)) {
- byteCapacity ++;
- }
- return byteCapacity;
- }
-
- /**
- * Adds one element to the vector.
- * @param value The half-byte value to be added to the vector.
- * This must be in the range 0x0 thru 0xF.
- */
- public void add(final byte value) {
- alloc(1);
- set(this.nextIndex - 1, value);
- }
-
- /**
- * Adds the content of a byte array to this vector.
- * @param value The array of half-byte values to be added to the vector.
- * Each element must be in the range 0x0 thru 0xF.
- */
- public void add(final byte[] value) {
- for (int i = 0; i < value.length; i++) {
- add(value[i]);
- }
- }
-
- /**
- * Place an item in the vector at a specific index.
- * @param index The 0-based index into the vector.
- * @param value The half-byte value to be placed in the vector. This must be in the range
- * 0x0 thru 0xF.
- */
- public void set(final int index, final byte value) {
- validateInput(value);
- final int byteIndex = computeByteIndex(index);
- final byte oldValue = this.backingVector.get(byteIndex);
- byte newValue = 0x0;
- if (NumberUtils.isOdd(index)) {
- /* If the index is odd, place the input nibble into the low-order bits. */
- newValue = BitUtils.maskLowOrderBits(oldValue);
- newValue = (byte) (newValue | value);
- } else {
- /* If the index is even, place the input nibble into the high-order bits. */
- newValue = BitUtils.maskHighOrderBits(oldValue);
- final byte shiftedValue = (byte) (value << WellKnownConstants.BITS_PER_NIBBLE);
- newValue = (byte) (newValue | shiftedValue);
- }
-
- this.backingVector.set(byteIndex, newValue);
- }
-
- /**
- * Retrieve a value from a specific index in the vector.
- * @param index The 0-based index whose value should be returned.
- * @return The value at {@code index}.
- */
- public byte get(final int index) {
- final int byteIndex = computeByteIndex(index);
- final byte byteValue = this.backingVector.get(byteIndex);
- byte nibbleValue = 0x0;
- if (NumberUtils.isOdd(index)) {
- /* If the index is odd, return just the low-order bits. */
- nibbleValue = BitUtils.maskHighOrderBits(byteValue);
- } else {
- /* If the index is even, return just the high-order bits. */
- nibbleValue = (byte) (byteValue >>> WellKnownConstants.BITS_PER_NIBBLE);
- /* Have to mask out the high-order bits after the cast, in case the shifted value has
- * the high-order bit set, and therefore looks negative -- in that case the caset sets
- * all of the high-order bits. */
- nibbleValue = BitUtils.maskHighOrderBits(nibbleValue);
- }
-
- return nibbleValue;
- }
-
- /**
- * Allocates or uses a specified number of elements (half-bytes).
- * If needed, this method automatically increases the vector's capacity.
- * @param size The number of elements (half-bytes) to be allocated.
- * @return The index to the beginning of the allocated elements (half-bytes).
- */
- private int alloc(final int size) {
- final int index = this.nextIndex;
- final int minimumCapacity = this.nextIndex + size;
- final int minimumByteCapacity = computeByteCapacity(minimumCapacity);
- final int bytesToAdd = minimumByteCapacity - this.backingVector.length();
- this.backingVector.alloc(bytesToAdd);
- this.nextIndex += size;
- return index;
- }
-
- /**
- * Sets the capacity of this vector equal to its size, to that there is no
- * unused capacity.
- */
- public void trimToSize() {
- this.backingVector.trimToSize();
- }
-
- /**
- * Returns the index of the first occurrence of a specified value in the vector.
- * @param value The value whose index is sought.
- * @param startingIndex The index in the vector at which the search should be started.
- * @return The index to the first occurrence of {@code value} at or after {@code startingIndex}, or -1 if it does
- * not occur in the vector.
- */
- public int indexOf(final byte value, final int startingIndex) {
- validateInput(value);
- for (int i = startingIndex; i < this.nextIndex; i++) {
- if (this.get(i) == value) {
- return i;
- }
- }
- return -1;
- }
-
- /**
- * Ensures that an input byte is in the correct range, throwing an
- * {@link IllegalArgumentException} if it is not.
- * @param inputByte The byte to be tested for suitability in a packed vector.
- */
- private void validateInput(final byte inputByte) {
- if (inputByte < 0
- || inputByte > WellKnownConstants.MAX_4_BIT_UNSIGNED_BYTE) {
- throw new IllegalArgumentException("Expected val in the range 0x0 to 0xF: "
- + inputByte);
- }
- }
-
-}
Copied: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/NibbleArrayBuilder.java (from rev 12650, trunk/foray/foray-common/src/main/java/org/foray/common/data/NibbleArrayBuilder.java)
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/NibbleArrayBuilder.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/NibbleArrayBuilder.java 2022-06-20 18:32:41 UTC (rev 12668)
@@ -0,0 +1,413 @@
+/*
+ * Copyright 2004 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.foray.common.WellKnownConstants;
+import org.foray.common.primitive.BitUtils;
+import org.foray.common.primitive.NumberUtils;
+
+import org.axsl.utility.sequence.NibblePrimitiveIterator;
+import org.axsl.utility.sequence.NibbleSequence;
+import org.axsl.utility.sequence.NibbleSequenceMutable;
+import org.axsl.utility.sequence.NibbleSequencePlus;
+
+import java.io.Serializable;
+
+/**
+ * A vector of nibbles, or half bytes. The purpose of this class is to reduce by approximately half
+ * the amount of memory needed to store a data structure which only needs 4 bits for each element.
+ */
+public class NibbleArrayBuilder implements NibbleSequenceMutable, Serializable {
+
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = -8706615311680792485L;
+
+ /** Default Capacity increment size. */
+ private static final int DEFAULT_BLOCK_SIZE = 2048;
+
+ /** Capacity increment size. */
+ private int blockSize = NibbleArrayBuilder.DEFAULT_BLOCK_SIZE;
+
+ /** The encapsulated ByteArrayBuilder that actually contains the data. */
+ private ByteArrayBuilder backingVector;
+
+ /** Index to to the next free item in this vector. */
+ private int nextIndex = 0;
+
+ /**
+ * No-argument constructor.
+ */
+ public NibbleArrayBuilder() {
+ this(NibbleArrayBuilder.DEFAULT_BLOCK_SIZE);
+ }
+
+ /**
+ * Constructor.
+ * @param capacity The initial capacity, in half-bytes, of the new vector.
+ */
+ public NibbleArrayBuilder(final int capacity) {
+ if (capacity > 0) {
+ this.blockSize = capacity;
+ } else {
+ this.blockSize = NibbleArrayBuilder.DEFAULT_BLOCK_SIZE;
+ }
+ final int byteCapacity = computeByteCapacity(this.blockSize);
+ this.backingVector = new ByteArrayBuilder(byteCapacity);
+ }
+
+ /**
+ * Returns the number of half-byte items in the vector.
+ * @return The number of items in the vector.
+ */
+ public int length() {
+ return this.nextIndex;
+ }
+
+ /**
+ * Returns the number of bytes actually used to store the vector content.
+ * @return The number of bytes used to store the vector content.
+ */
+ public int lengthInBytes() {
+ return this.backingVector.length();
+ }
+
+ /**
+ * Returns the current capacity of the vector, in half-bytes.
+ * @return The currect capacity of the vector.
+ */
+ public int capacity() {
+ return this.backingVector.capacity() * 2;
+ }
+
+ /**
+ * Converts an index specified for nibbles into the correct index to use to retrieve the byte
+ * containing that nibble.
+ * @param nibbleIndex The index to the nibble.
+ * @return The index to the matching byte.
+ */
+ public int computeByteIndex(final int nibbleIndex) {
+ return nibbleIndex / 2;
+ }
+
+ /**
+ * Converts an capacity specified for nibbles into the correct capacity to use to for bytes.
+ * This is similar to {@link #computeByteIndex(int)}, but rounds the number of bytes up to
+ * ensure that all half-bytes have room.
+ * @param nibbleCapacity The capacity in half-bytes.
+ * @return The capacity in bytes.
+ */
+ int computeByteCapacity(final int nibbleCapacity) {
+ int byteCapacity = nibbleCapacity / 2;
+ if (NumberUtils.isOdd(nibbleCapacity)) {
+ byteCapacity ++;
+ }
+ return byteCapacity;
+ }
+
+ /**
+ * Adds one element to the vector.
+ * @param value The half-byte value to be added to the vector.
+ * This must be in the range 0x0 thru 0xF.
+ */
+ public void add(final byte value) {
+ alloc(1);
+ set(this.nextIndex - 1, value);
+ }
+
+ /**
+ * Adds the content of a byte array to this vector.
+ * @param value The array of half-byte values to be added to the vector.
+ * Each element must be in the range 0x0 thru 0xF.
+ */
+ public void add(final byte[] value) {
+ for (int i = 0; i < value.length; i++) {
+ add(value[i]);
+ }
+ }
+
+ /**
+ * Place an item in the vector at a specific index.
+ * @param index The 0-based index into the vector.
+ * @param value The half-byte value to be placed in the vector. This must be in the range
+ * 0x0 thru 0xF.
+ */
+ public void set(final int index, final byte value) {
+ validateInput(value);
+ final int byteIndex = computeByteIndex(index);
+ final byte oldValue = this.backingVector.get(byteIndex);
+ byte newValue = 0x0;
+ if (NumberUtils.isOdd(index)) {
+ /* If the index is odd, place the input nibble into the low-order bits. */
+ newValue = BitUtils.maskLowOrderBits(oldValue);
+ newValue = (byte) (newValue | value);
+ } else {
+ /* If the index is even, place the input nibble into the high-order bits. */
+ newValue = BitUtils.maskHighOrderBits(oldValue);
+ final byte shiftedValue = (byte) (value << WellKnownConstants.BITS_PER_NIBBLE);
+ newValue = (byte) (newValue | shiftedValue);
+ }
+
+ this.backingVector.set(byteIndex, newValue);
+ }
+
+ /**
+ * Retrieve a value from a specific index in the vector.
+ * @param index The 0-based index whose value should be returned.
+ * @return The value at {@code index}.
+ */
+ public byte get(final int index) {
+ final int byteIndex = computeByteIndex(index);
+ final byte byteValue = this.backingVector.get(byteIndex);
+ byte nibbleValue = 0x0;
+ if (NumberUtils.isOdd(index)) {
+ /* If the index is odd, return just the low-order bits. */
+ nibbleValue = BitUtils.maskHighOrderBits(byteValue);
+ } else {
+ /* If the index is even, return just the high-order bits. */
+ nibbleValue = (byte) (byteValue >>> WellKnownConstants.BITS_PER_NIBBLE);
+ /* Have to mask out the high-order bits after the cast, in case the shifted value has
+ * the high-order bit set, and therefore looks negative -- in that case the caset sets
+ * all of the high-order bits. */
+ nibbleValue = BitUtils.maskHighOrderBits(nibbleValue);
+ }
+
+ return nibbleValue;
+ }
+
+ /**
+ * Allocates or uses a specified number of elements (half-bytes).
+ * If needed, this method automatically increases the vector's capacity.
+ * @param size The number of elements (half-bytes) to be allocated.
+ * @return The index to the beginning of the allocated elements (half-bytes).
+ */
+ private int alloc(final int size) {
+ final int index = this.nextIndex;
+ final int minimumCapacity = this.nextIndex + size;
+ final int minimumByteCapacity = computeByteCapacity(minimumCapacity);
+ final int bytesToAdd = minimumByteCapacity - this.backingVector.length();
+ this.backingVector.alloc(bytesToAdd);
+ this.nextIndex += size;
+ return index;
+ }
+
+ /**
+ * Sets the capacity of this vector equal to its size, to that there is no
+ * unused capacity.
+ */
+ public void trimToSize() {
+ this.backingVector.trimToSize();
+ }
+
+ /**
+ * Returns the index of the first occurrence of a specified value in the vector.
+ * @param value The value whose index is sought.
+ * @param startingIndex The index in the vector at which the search should be started.
+ * @return The index to the first occurrence of {@code value} at or after {@code startingIndex}, or -1 if it does
+ * not occur in the vector.
+ */
+ public int indexOf(final byte value, final int startingIndex) {
+ validateInput(value);
+ for (int i = startingIndex; i < this.nextIndex; i++) {
+ if (this.get(i) == value) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Ensures that an input byte is in the correct range, throwing an
+ * {@link IllegalArgumentException} if it is not.
+ * @param inputByte The byte to be tested for suitability in a packed vector.
+ */
+ private void validateInput(final byte inputByte) {
+ if (inputByte < 0
+ || inputByte > WellKnownConstants.MAX_4_BIT_UNSIGNED_BYTE) {
+ throw new IllegalArgumentException("Expected val in the range 0x0 to 0xF: "
+ + inputByte);
+ }
+ }
+
+ @Override
+ public NibbleSequence subSequence(final int start, final int end) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public byte[] toArray() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public NibblePrimitiveIterator iterator() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public NibblePrimitiveIterator iteratorReverse() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int binarySearch(final byte value) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public int indexOf(final byte nibble) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public boolean contains(final byte nibble) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public byte firstElement() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public byte lastElement() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public byte nibbleAt(final int index) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public NibbleSequencePlus asPlus() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public NibbleSequenceMutable asMutable() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void swap(final int index1, final int index2) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setLength(final int newLength) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNibbleAt(final int index, final byte newNibble) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void sort() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public NibbleSequenceMutable append(final byte newItem) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public NibbleSequenceMutable append(final byte... newItems) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public NibbleSequenceMutable append(final NibbleSequence sequence) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public NibbleSequenceMutable append(final NibbleSequence sequence, final int start, final int end) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public byte push(final byte newItem) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public byte pop() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public byte peek() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public boolean empty() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public NibbleSequencePlus toImmutable() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Deleted: trunk/foray/foray-common/src/test/java/org/foray/common/data/NibbleArrayBuilderTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/NibbleArrayBuilderTests.java 2022-06-20 17:30:22 UTC (rev 12667)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/NibbleArrayBuilderTests.java 2022-06-20 18:32:41 UTC (rev 12668)
@@ -1,121 +0,0 @@
-/*
- * Copyright 2008 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.data;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Arrays;
-
-/**
- * JUnit test class for the class {@link NibbleArrayBuilder}.
- */
-public class NibbleArrayBuilderTests {
-
- /** An array of test bytes. */
- private static byte[] testSequence01 = new byte[] {
- 0x0, 0x1, 0x2, 0x3,
- 0x4, 0x5, 0x6, 0x7,
- 0x8, 0x9, 0xA, 0xB,
- 0xC, 0xD, 0xE, 0xF,
- 0x1, 0xF, 0x2, 0xE
- };
-
- /**
- * Functional test of the class as a whole.
- */
- @Test
- public void testClass01() {
- final NibbleArrayBuilder testVector = new NibbleArrayBuilder();
-
- /* Put the content into a vector. */
- testVector.add(NibbleArrayBuilderTests.testSequence01);
- Assert.assertEquals(NibbleArrayBuilderTests.testSequence01.length, testVector.length());
- Assert.assertEquals(10, testVector.lengthInBytes());
-
- /* Get it back out again. */
- final byte[] actualContent = new byte[NibbleArrayBuilderTests.testSequence01.length];
- for (int i = 0; i < NibbleArrayBuilderTests.testSequence01.length; i++) {
- actualContent[i] = testVector.get(i);
- }
-
- Assert.assertTrue(Arrays.equals(NibbleArrayBuilderTests.testSequence01, actualContent));
- }
-
- /**
- * Test of {@link NibbleArrayBuilder#computeByteIndex(int)}.
- */
- @Test
- public void testComputeByteIndex() {
- final NibbleArrayBuilder testVector = new NibbleArrayBuilder();
-
- /* Index 0 & 1 should be in byte index 0. */
- Assert.assertEquals(0, testVector.computeByteIndex(0));
- Assert.assertEquals(0, testVector.computeByteIndex(1));
-
- /* Index 2 & 3 should be in byte index 1. */
- Assert.assertEquals(1, testVector.computeByteIndex(2));
- Assert.assertEquals(1, testVector.computeByteIndex(3));
-
- /* Index 4 & 5 should be in byte index 2. */
- Assert.assertEquals(2, testVector.computeByteIndex(4));
- Assert.assertEquals(2, testVector.computeByteIndex(5));
- }
-
- /**
- * Test of {@link NibbleArrayBuilder#indexOf(byte, int)}.
- */
- @Test
- public void testIndexOf() {
- final NibbleArrayBuilder testVector = new NibbleArrayBuilder();
- testVector.add(NibbleArrayBuilderTests.testSequence01);
-
- /* Straightforward search from the start. */
- int actualIndex = testVector.indexOf((byte) 0xF, 0);
- Assert.assertEquals(15, actualIndex);
-
- /* Start the search in a different place. The result should be the same. */
- actualIndex = testVector.indexOf((byte) 0xF, 7);
- Assert.assertEquals(15, actualIndex);
-
- /* Start the search on the first occurrence. The result should still be the same. */
- actualIndex = testVector.indexOf((byte) 0xF, 15);
- Assert.assertEquals(15, actualIndex);
-
- /* Now start the search just past the first occurrence. The second occurrence should be
- * returned. */
- actualIndex = testVector.indexOf((byte) 0xF, 16);
- Assert.assertEquals(17, actualIndex);
-
- /* Now test one that is not there. */
- actualIndex = testVector.indexOf((byte) 0x7, 16);
- Assert.assertEquals(-1, actualIndex);
- }
-
-}
Copied: trunk/foray/foray-common/src/test/java/org/foray/common/sequence/NibbleArrayBuilderTests.java (from rev 12650, trunk/foray/foray-common/src/test/java/org/foray/common/data/NibbleArrayBuilderTests.java)
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/sequence/NibbleArrayBuilderTests.java (rev 0)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/sequence/NibbleArrayBuilderTests.java 2022-06-20 18:32:41 UTC (rev 12668)
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2008 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.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * JUnit test class for the class {@link NibbleArrayBuilder}.
+ */
+public class NibbleArrayBuilderTests {
+
+ /** An array of test bytes. */
+ private static byte[] testSequence01 = new byte[] {
+ 0x0, 0x1, 0x2, 0x3,
+ 0x4, 0x5, 0x6, 0x7,
+ 0x8, 0x9, 0xA, 0xB,
+ 0xC, 0xD, 0xE, 0xF,
+ 0x1, 0xF, 0x2, 0xE
+ };
+
+ /**
+ * Functional test of the class as a whole.
+ */
+ @Test
+ public void testClass01() {
+ final NibbleArrayBuilder testVector = new NibbleArrayBuilder();
+
+ /* Put the content into a vector. */
+ testVector.add(NibbleArrayBuilderTests.testSequence01);
+ Assert.assertEquals(NibbleArrayBuilderTests.testSequence01.length, testVector.length());
+ Assert.assertEquals(10, testVector.lengthInBytes());
+
+ /* Get it back out again. */
+ final byte[] actualContent = new byte[NibbleArrayBuilderTests.testSequence01.length];
+ for (int i = 0; i < NibbleArrayBuilderTests.testSequence01.length; i++) {
+ actualContent[i] = testVector.get(i);
+ }
+
+ Assert.assertTrue(Arrays.equals(NibbleArrayBuilderTests.testSequence01, actualContent));
+ }
+
+ /**
+ * Test of {@link NibbleArrayBuilder#computeByteIndex(int)}.
+ */
+ @Test
+ public void testComputeByteIndex() {
+ final NibbleArrayBuilder testVector = new NibbleArrayBuilder();
+
+ /* Index 0 & 1 should be in byte index 0. */
+ Assert.assertEquals(0, testVector.computeByteIndex(0));
+ Assert.assertEquals(0, testVector.computeByteIndex(1));
+
+ /* Index 2 & 3 should be in byte index 1. */
+ Assert.assertEquals(1, testVector.computeByteIndex(2));
+ Assert.assertEquals(1, testVector.computeByteIndex(3));
+
+ /* Index 4 & 5 should be in byte index 2. */
+ Assert.assertEquals(2, testVector.computeByteIndex(4));
+ Assert.assertEquals(2, testVector.computeByteIndex(5));
+ }
+
+ /**
+ * Test of {@link NibbleArrayBuilder#indexOf(byte, int)}.
+ */
+ @Test
+ public void testIndexOf() {
+ final NibbleArrayBuilder testVector = new NibbleArrayBuilder();
+ testVector.add(NibbleArrayBuilderTests.testSequence01);
+
+ /* Straightforward search from the start. */
+ int actualIndex = testVector.indexOf((byte) 0xF, 0);
+ Assert.assertEquals(15, actualIndex);
+
+ /* Start the search in a different place. The result should be the same. */
+ actualIndex = testVector.indexOf((byte) 0xF, 7);
+ Assert.assertEquals(15, actualIndex);
+
+ /* Start the search on the first occurrence. The result should still be the same. */
+ actualIndex = testVector.indexOf((byte) 0xF, 15);
+ Assert.assertEquals(15, actualIndex);
+
+ /* Now start the search just past the first occurrence. The second occurrence should be
+ * returned. */
+ actualIndex = testVector.indexOf((byte) 0xF, 16);
+ Assert.assertEquals(17, actualIndex);
+
+ /* Now test one that is not there. */
+ actualIndex = testVector.indexOf((byte) 0x7, 16);
+ Assert.assertEquals(-1, actualIndex);
+ }
+
+}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java 2022-06-20 17:30:22 UTC (rev 12667)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java 2022-06-20 18:32:41 UTC (rev 12668)
@@ -33,10 +33,10 @@
package org.foray.orthography;
-import org.foray.common.data.NibbleArrayBuilder;
import org.foray.common.data.TernaryTree;
import org.foray.common.primitive.BitUtils;
import org.foray.common.primitive.StringUtils;
+import org.foray.common.sequence.NibbleArrayBuilder;
import org.axsl.orthography.OrthographyException;
@@ -151,16 +151,13 @@
}
/**
- * Packs the interletter values by storing each one of them in 4 bits, two
- * values into a byte, in big endian order, that is, the higher order byte
- * into the high order 4-bits, and storing these packed values in
+ * Packs the interletter values by storing each one of them in 4 bits, two values into a byte, in big endian order,
+ * that is, the higher order byte into the high order 4-bits, and storing these packed values in
* {@link #patternValues}.
- * @param values A string of digits from '0' to '9' representing the
- * interletter values.
- * @return The index into {@link #patternValues} where the packed values
- * are stored.
+ * @param values A string of digits from '0' to '9' representing the interletter values.
+ * @return The index into {@link #patternValues} where the packed values are stored.
*/
- private int packValues(final String values) {
+ private int packValues(final CharSequence values) {
final int start = this.patternValues.length();
for (int stringIndex = 0; stringIndex < values.length(); stringIndex++) {
/* Convert an ASCII numeral to its numeric value. For example, an ASCII numeral 0 (0x30)
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/PatternTreeTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/PatternTreeTests.java 2022-06-20 17:30:22 UTC (rev 12667)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/PatternTreeTests.java 2022-06-20 18:32:41 UTC (rev 12668)
@@ -94,7 +94,7 @@
/**
* Tests of {@link PatternTree#hyphenate(CharSequence, int, int)} for a four-syllable word that <em>is</em> found in
- * the patterns, "hy-phen-a-tion".
+ * the patterns: "hy-phen-a-tion".
* @throws IOException For error creating hyphenation server.
* @throws OrthographyException For error getting the hyphenation tree.
*/
@@ -108,7 +108,7 @@
/**
* Tests of {@link PatternTree#hyphenate(CharSequence, int, int)} for a one-syllable word that <em>is</em> found in
- * the patterns "times". This word was chosen because it at one time returned a hyphenation point at position 0,
+ * the patterns: "times". This word was chosen because it at one time returned a hyphenation point at position 0,
* essentially suggesting that there was a discretionary hyphenation point at the very beginning of the word.
* @throws IOException For error creating hyphenation server.
* @throws OrthographyException For error getting the hyphenation tree.
@@ -120,4 +120,17 @@
Assert.assertNull(actual);
}
+ /**
+ * Tests of {@link PatternTree#hyphenate(CharSequence, int, int)} for a one-syllable word that <em>is</em> found in
+ * the patterns: "friends".
+ * @throws IOException For error creating hyphenation server.
+ * @throws OrthographyException For error getting the hyphenation tree.
+ */
+ @Test
+ public void hyphenateTest04() throws IOException, OrthographyException {
+ final String testString = "friends";
+ final StringWord actual = PatternTreeTests.patternTree.hyphenate(testString, 0, testString.length());
+ Assert.assertNull(actual);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|