import java.util.Locale;
+import org.apache.harmony.text.internal.nls.Messages;
+
/**
* Locates boundaries in text. This class defines a protocol for objects that
* break up a piece of natural-language text according to a set of criteria.
* greater than the length of {@code buf}.
*/
protected static long getLong(byte[] buf, int offset) {
- if (null == buf) {
- throw new NullPointerException();
- }
- if (offset < 0 || buf.length - offset < LONG_LENGTH) {
- throw new ArrayIndexOutOfBoundsException();
+ // 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++) {
* greater than the length of {@code buf}.
*/
protected static int getInt(byte[] buf, int offset) {
- if (null == buf) {
- throw new NullPointerException();
- }
- if (offset < 0 || buf.length - INT_LENGTH < offset) {
- throw new ArrayIndexOutOfBoundsException();
+ // 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++) {
* greater than the length of {@code buf}.
*/
protected static short getShort(byte[] buf, int offset) {
- if (null == buf) {
- throw new NullPointerException();
- }
- if (offset < 0 || buf.length - SHORT_LENGTH < offset) {
- throw new ArrayIndexOutOfBoundsException();
+ // 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++) {
package java.text;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.Comparator;
import java.util.Locale;
import java.util.Vector;
-import org.apache.harmony.luni.util.PriviAction;
-
/**
* Performs locale-sensitive string comparison. A concrete subclass,
* {@link RuleBasedCollator}, allows customization of the collation ordering by
static {
// CACHE_SIZE includes key and value, so needs to be double
String cacheSize = AccessController
- .doPrivileged(new PriviAction<String>("collator.cache")); //$NON-NLS-1$
+ .doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty("collator.cache"); //$NON-NLS-1$
+ }
+ });
if (cacheSize != null) {
try {
CACHE_SIZE = Integer.parseInt(cacheSize);
public Date parse(String string) throws ParseException {
ParsePosition position = new ParsePosition(0);
Date date = parse(string, position);
- if (position.getErrorIndex() != -1 || position.getIndex() == 0) {
+ if (position.getIndex() == 0) {
// text.19=Unparseable date: {0}
throw new ParseException(
Messages.getString("text.19", string), position.getErrorIndex()); //$NON-NLS-1$
public Object parseObject(String string) throws ParseException {
ParsePosition position = new ParsePosition(0);
Object result = parseObject(string, position);
- if (position.getErrorIndex() != -1 || position.getIndex() == 0) {
- throw new ParseException(null, position.getErrorIndex());
+ if (position.getIndex() == 0) {
+ // text.1C=Format.parseObject(String) parse failure
+ throw new ParseException(
+ Messages.getString("text.1C"), position.getErrorIndex()); //$NON-NLS-1$
}
return result;
}
public Object[] parse(String string) throws ParseException {
ParsePosition position = new ParsePosition(0);
Object[] result = parse(string, position);
- if (position.getErrorIndex() != -1 || position.getIndex() == 0) {
- throw new ParseException(null, position.getErrorIndex());
+ if (position.getIndex() == 0) {
+ // text.1B=MessageFormat.parseObject(String) parse failure
+ throw new ParseException(
+ Messages.getString("text.1B"), position.getErrorIndex()); //$NON-NLS-1$
}
return result;
}
public Number parse(String string) throws ParseException {
ParsePosition pos = new ParsePosition(0);
Number number = parse(string, pos);
- if (pos.getErrorIndex() != -1 || pos.getIndex() == 0) {
- throw new ParseException(null, pos.getErrorIndex());
+ if (pos.getIndex() == 0) {
+ // text.1D=Unparseable number: {0}
+ throw new ParseException(
+ Messages.getString("text.1D", string), pos.getErrorIndex()); //$NON-NLS-1$
}
return number;
}
text.18=Not a valid {0}, subclass should override readResolve()
text.19=Unparseable date: {0}
text.1A=position is null
-
+text.1B=MessageFormat.parseObject(String) parse failure
+text.1C=Format.parseObject(String) parse failure
+text.1D=Unparseable number: {0}
+text.1E=Offset out of bounds \: {0}
args = {java.lang.String.class, int.class}
)
public void test_ConstructorLjava_lang_StringI() {
- // Test for method java.text.ParseException(java.lang.String, int)
- // SM
try {
DateFormat df = DateFormat.getInstance();
df.parse("HelloWorld");
+ fail("ParseException not created/thrown.");
} catch (ParseException e) {
- return;
+ // expected
}
- fail("ParseException not created/thrown.");
}
/**
args = {}
)
public void test_getErrorOffset() {
- // Test for method int java.text.ParseException.getErrorOffset()
- // SM
try {
DateFormat df = DateFormat.getInstance();
df.parse("1999HelloWorld");
assertEquals("getErrorOffsetFailed.", 4, e.getErrorOffset());
}
}
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
}