Track Java 6's BreakIterator API changes.
Bug: 2497395
Change-Id: Iaef75bbd946bebe6201b5f52564bcaf8a4d0e56e
diff --git a/libcore/text/src/main/java/java/text/BreakIterator.java b/libcore/text/src/main/java/java/text/BreakIterator.java
index 55ef31d..969a09e 100644
--- a/libcore/text/src/main/java/java/text/BreakIterator.java
+++ b/libcore/text/src/main/java/java/text/BreakIterator.java
@@ -234,12 +234,6 @@
*/
public static final int DONE = -1;
- private static final int LONG_LENGTH = 8;
-
- private static final int INT_LENGTH = 4;
-
- private static final int SHORT_LENGTH = 2;
-
// the wrapped ICU implementation
NativeBreakIterator wrapped;
@@ -503,88 +497,4 @@
throw new AssertionError(e); // android-changed
}
}
-
- /**
- * Gets a long value from the given byte array, starting from the given
- * offset.
- *
- * @param buf
- * the bytes to be converted.
- * @param offset
- * the start position of the conversion.
- * @return the converted long value.
- * @throws NullPointerException
- * if {@code buf} is {@code null}.
- * @throws ArrayIndexOutOfBoundsException
- * if {@code offset < 0} or {@code offset + LONG_LENGTH} is
- * greater than the length of {@code buf}.
- */
- protected static long getLong(byte[] buf, int offset) {
- // Force a buf null check first!
- if (buf.length - offset < LONG_LENGTH || offset < 0) {
- // text.1E=Offset out of bounds \: {0}
- throw new ArrayIndexOutOfBoundsException(Messages.getString("text.1E", offset)); //$NON-NLS-1$
- }
- long result = 0;
- for (int i = offset; i < offset + LONG_LENGTH; i++) {
- result = (result << 8) | (buf[i] & 0xff);
- }
- return result;
- }
-
- /**
- * Gets an int value from the given byte array, starting from the given
- * offset.
- *
- * @param buf
- * the bytes to be converted.
- * @param offset
- * the start position of the conversion.
- * @return the converted int value.
- * @throws NullPointerException
- * if {@code buf} is {@code null}.
- * @throws ArrayIndexOutOfBoundsException
- * if {@code offset < 0} or {@code offset + INT_LENGTH} is
- * greater than the length of {@code buf}.
- */
- protected static int getInt(byte[] buf, int offset) {
- // Force buf null check first!
- if (buf.length - INT_LENGTH < offset || offset < 0) {
- // text.1E=Offset out of bounds \: {0}
- throw new ArrayIndexOutOfBoundsException(Messages.getString("text.1E", offset)); //$NON-NLS-1$
- }
- int result = 0;
- for (int i = offset; i < offset + INT_LENGTH; i++) {
- result = (result << 8) | (buf[i] & 0xff);
- }
- return result;
- }
-
- /**
- * Gets a short value from the given byte array, starting from the given
- * offset.
- *
- * @param buf
- * the bytes to be converted.
- * @param offset
- * the start position of the conversion.
- * @return the converted short value.
- * @throws NullPointerException
- * if {@code buf} is {@code null}.
- * @throws ArrayIndexOutOfBoundsException
- * if {@code offset < 0} or {@code offset + SHORT_LENGTH} is
- * greater than the length of {@code buf}.
- */
- protected static short getShort(byte[] buf, int offset) {
- // Force buf null check first!
- if (buf.length - SHORT_LENGTH < offset || offset < 0) {
- // text.1E=Offset out of bounds \: {0}
- throw new ArrayIndexOutOfBoundsException(Messages.getString("text.1E", offset)); //$NON-NLS-1$
- }
- short result = 0;
- for (int i = offset; i < offset + SHORT_LENGTH; i++) {
- result = (short) ((result << 8) | (buf[i] & 0xff));
- }
- return result;
- }
}
diff --git a/libcore/text/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java b/libcore/text/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java
index f3b0b31..b64bafb 100644
--- a/libcore/text/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java
+++ b/libcore/text/src/test/java/org/apache/harmony/text/tests/java/text/BreakIteratorTest.java
@@ -127,23 +127,6 @@
assertEquals(iterator.first(), iterator.current());
}
- /**
- * @tests java.text.BreakIterator#BreakIterator() Test of method
- * java.text.BreakIterator#BreakIterator().
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "BreakIterator",
- args = {}
- )
- public void testConstructor() {
- try {
- new MockBreakIterator();
- } catch (Exception e) {
- fail("Unexpected exception " + e.toString());
- }
- }
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
@@ -513,185 +496,6 @@
}
/**
- * @tests java.text.BreakIterator.getShort(byte[], int)
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getShort",
- args = {byte[].class, int.class}
- )
- public void test_getShort() {
- try {
- MockBreakIterator.publicGetShort(null, 0);
- fail("should throw NPE.");
- } catch (NullPointerException e) {
- }
- try {
- MockBreakIterator.publicGetShort(null, -1);
- fail("should throw NPE.");
- } catch (NullPointerException e) {
- }
- try {
- MockBreakIterator.publicGetShort(new byte[] { 0, 0, 0, 1, 1 }, -1);
- fail("should throw ArrayIndexOutOfBoundsException.");
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- try {
- MockBreakIterator.publicGetShort(new byte[] { 0, 0 }, 1);
- fail("should throw ArrayIndexOutOfBoundsException.");
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- assertEquals(0, MockBreakIterator
- .publicGetShort(new byte[] { 0, 0 }, 0));
- assertEquals(1, MockBreakIterator
- .publicGetShort(new byte[] { 0, 1 }, 0));
- assertEquals(-1, MockBreakIterator.publicGetShort(new byte[] {
- (byte) 0xff, (byte) 0xff }, 0));
- assertEquals(1, MockBreakIterator.publicGetShort(new byte[] { 1, 0, 1,
- 0 }, 1));
- assertEquals(1, MockBreakIterator.publicGetShort(new byte[] { 0, 0, 1,
- 0 }, 1));
- assertEquals(1, MockBreakIterator.publicGetShort(new byte[] { 0, 0, 1,
- 1 }, 1));
- assertEquals(257, MockBreakIterator.publicGetShort(
- new byte[] { 0, 1, 1 }, 1));
-
- // regression for Harmony-944
- try {
- MockBreakIterator.publicGetShort(new byte[] { 0, 0 },
- Integer.MAX_VALUE);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- MockBreakIterator.publicGetShort(new byte[] { 0, 0 },
- Short.MAX_VALUE);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * @tests java.text.BreakIterator.getInt(byte[], int)
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInt",
- args = {byte[].class, int.class}
- )
- public void test_getInt() {
- try {
- MockBreakIterator.publicGetInt(null, 0);
- fail("should throw NPE.");
- } catch (NullPointerException e) {
- }
- try {
- MockBreakIterator.publicGetInt(null, -1);
- fail("should throw NPE.");
- } catch (NullPointerException e) {
- }
- try {
- MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 1, 1 }, -1);
- fail("should throw ArrayIndexOutOfBoundsException.");
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- try {
- MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 0 }, 1);
- fail("should throw ArrayIndexOutOfBoundsException.");
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- assertEquals(0, MockBreakIterator.publicGetInt(
- new byte[] { 0, 0, 0, 0 }, 0));
- assertEquals(1, MockBreakIterator.publicGetInt(
- new byte[] { 0, 0, 0, 1 }, 0));
- assertEquals(-1, MockBreakIterator.publicGetInt(new byte[] {
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }, 0));
- assertEquals(1, MockBreakIterator.publicGetInt(new byte[] { 1, 0, 0, 0,
- 1, 0 }, 1));
- assertEquals(1, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 0,
- 1, 0 }, 1));
- assertEquals(1, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0, 0,
- 1, 1 }, 1));
- assertEquals(257, MockBreakIterator.publicGetInt(new byte[] { 0, 0, 0,
- 1, 1 }, 1));
-
- // regression for Harmony-944
- try {
- MockBreakIterator.publicGetInt(new byte[] { 0, 0 },
- Integer.MAX_VALUE);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * @tests java.text.BreakIterator.getLong(byte[], int)
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLong",
- args = {byte[].class, int.class}
- )
- public void test_getLong() {
- try {
- MockBreakIterator.publicGetLong(null, 0);
- fail("should throw NPE.");
- } catch (NullPointerException e) {
- }
- try {
- MockBreakIterator.publicGetLong(null, -1);
- fail("should throw NPE.");
- } catch (NullPointerException e) {
- }
- try {
- MockBreakIterator.publicGetLong(
- new byte[] { 0, 0, 0, 0, 0, 0, 1, 1 }, -1);
- fail("should throw ArrayIndexOutOfBoundsException.");
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- try {
- MockBreakIterator.publicGetLong(
- new byte[] { 0, 0, 0, 0, 0, 0, 1, 1 }, 1);
- fail("should throw ArrayIndexOutOfBoundsException.");
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- assertEquals(0, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0,
- 0, 0, 0, 0, 0 }, 0));
- assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0,
- 0, 0, 0, 0, 1 }, 0));
- assertEquals(-1, MockBreakIterator.publicGetLong(new byte[] {
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }, 0));
- assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 1, 0, 0,
- 0, 0, 0, 0, 0, 1, 0 }, 1));
- assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 0 }, 1));
- assertEquals(1, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0,
- 0, 0, 0, 0, 0, 1, 1 }, 1));
- assertEquals(257, MockBreakIterator.publicGetLong(new byte[] { 0, 0, 0,
- 0, 0, 0, 0, 1, 1 }, 1));
-
- // regression for Harmony-944
- try {
- MockBreakIterator.publicGetLong(new byte[] { 0, 1 },
- Integer.MAX_VALUE);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
* @tests java.text.BreakIterator#getCharacterInstance(Locale)
*/
@TestTargetNew(
@@ -747,57 +551,4 @@
} catch (NullPointerException e) {
}
}
-
- private static class MockBreakIterator extends BreakIterator {
- public MockBreakIterator() {
- super();
- }
-
- public static int publicGetInt(byte[] buf, int offset) {
- return BreakIterator.getInt(buf, offset);
- }
-
- public static long publicGetLong(byte[] buf, int offset) {
- return BreakIterator.getLong(buf, offset);
- }
-
- public static short publicGetShort(byte[] buf, int offset) {
- return BreakIterator.getShort(buf, offset);
- }
-
- public int current() {
- return 0;
- }
-
- public int first() {
- return 0;
- }
-
- public int following(int offset) {
- return 0;
- }
-
- public CharacterIterator getText() {
- return null;
- }
-
- public int last() {
- return 0;
- }
-
- public int next() {
- return 0;
- }
-
- public int next(int n) {
- return 0;
- }
-
- public int previous() {
- return 0;
- }
-
- public void setText(CharacterIterator newText) {
- }
- }
}