LUCENE-1257: Move messages package to Java 1.5, thanks Robert Muir!

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@821447 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-10-03 23:36:23 +00:00
parent c70555f62d
commit 8dcc6d68b5
19 changed files with 43 additions and 43 deletions

View File

@ -58,7 +58,7 @@ public class QueryNodeParseException extends QueryNodeException {
public void setQuery(CharSequence query) {
this.query = query;
this.message = new MessageImpl(
QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, new Object[] {query, ""});
QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, query, "");
}
public CharSequence getQuery() {

View File

@ -175,9 +175,9 @@ public class QueryTreeBuilder implements QueryBuilder {
if (builder == null) {
throw new QueryNodeException(new MessageImpl(
QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, new Object[]{node
QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, node
.toQueryString(new EscapeQuerySyntaxImpl()), node.getClass()
.getName()}));
.getName()));
}

View File

@ -51,7 +51,7 @@ public class BoostQueryNode extends QueryNodeImpl {
public BoostQueryNode(QueryNode query, float value) throws QueryNodeException {
if (query == null) {
throw new QueryNodeError(new MessageImpl(
QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, new Object[]{"query", "null"}));
QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
}
this.value = value;

View File

@ -42,7 +42,7 @@ public class GroupQueryNode extends QueryNodeImpl {
public GroupQueryNode(QueryNode query) {
if (query == null) {
throw new QueryNodeError(new MessageImpl(
QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, new Object[]{"query", "null"}));
QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, "query", "null"));
}
allocate();

View File

@ -94,7 +94,7 @@ public class ModifierQueryNode extends QueryNodeImpl {
public ModifierQueryNode(QueryNode query, Modifier mod) {
if (query == null) {
throw new QueryNodeError(new MessageImpl(
QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, new Object[]{"query", "null"}));
QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, "query", "null"));
}
allocate();

View File

@ -40,7 +40,7 @@ public class PhraseSlopQueryNode extends QueryNodeImpl implements FieldableNode
throws QueryNodeException {
if (query == null) {
throw new QueryNodeError(new MessageImpl(
QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, new Object[]{"query", "null"}));
QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
}
this.value = value;

View File

@ -109,8 +109,8 @@ public class ProximityQueryNode extends BooleanQueryNode {
if (type == Type.NUMBER) {
if (distance <= 0) {
throw new QueryNodeError(new MessageImpl(
QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, new Object[]{"distance",
distance}));
QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, "distance",
distance));
} else {
this.distance = distance;

View File

@ -47,7 +47,7 @@ public class SlopQueryNode extends QueryNodeImpl implements FieldableNode {
public SlopQueryNode(QueryNode query, int value) {
if (query == null) {
throw new QueryNodeError(new MessageImpl(
QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, new Object[]{"query", "null"}));
QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
}
this.value = value;

View File

@ -67,9 +67,9 @@ public class BooleanQueryNodeBuilder implements StandardQueryBuilder {
} catch (TooManyClauses ex) {
throw new QueryNodeException(new MessageImpl(
QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, new Object[]{BooleanQuery
QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery
.getMaxClauseCount(), queryNode
.toQueryString(new EscapeQuerySyntaxImpl())}), ex);
.toQueryString(new EscapeQuerySyntaxImpl())), ex);
}

View File

@ -40,9 +40,9 @@ public class MatchAllDocsQueryNodeBuilder implements StandardQueryBuilder {
// validates node
if (!(queryNode instanceof MatchAllDocsQueryNode)) {
throw new QueryNodeException(new MessageImpl(
QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, new Object[]{queryNode
QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, queryNode
.toQueryString(new EscapeQuerySyntaxImpl()), queryNode.getClass()
.getName()}));
.getName()));
}
return new MatchAllDocsQuery();

View File

@ -40,9 +40,9 @@ public class MatchNoDocsQueryNodeBuilder implements StandardQueryBuilder {
// validates node
if (!(queryNode instanceof MatchNoDocsQueryNode)) {
throw new QueryNodeException(new MessageImpl(
QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, new Object[]{queryNode
QueryParserMessages.LUCENE_QUERY_CONVERSION_ERROR, queryNode
.toQueryString(new EscapeQuerySyntaxImpl()), queryNode.getClass()
.getName()}));
.getName()));
}
return new BooleanQuery();

View File

@ -68,9 +68,9 @@ public class StandardBooleanQueryNodeBuilder implements StandardQueryBuilder {
} catch (TooManyClauses ex) {
throw new QueryNodeException(new MessageImpl(
QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, new Object[]{BooleanQuery
QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES, BooleanQuery
.getMaxClauseCount(), queryNode
.toQueryString(new EscapeQuerySyntaxImpl())}), ex);
.toQueryString(new EscapeQuerySyntaxImpl())), ex);
}

View File

@ -289,7 +289,7 @@ public class EscapeQuerySyntaxImpl implements EscapeQuerySyntax {
return c - 'A' + 10;
} else {
throw new ParseException(new MessageImpl(
QueryParserMessages.INVALID_SYNTAX_ESCAPE_NONE_HEX_UNICODE, new Object[]{c}));
QueryParserMessages.INVALID_SYNTAX_ESCAPE_NONE_HEX_UNICODE, c));
}
}

View File

@ -47,8 +47,8 @@ public class ParseException extends QueryNodeParseException {
*/
public ParseException(Token currentTokenVal,
int[][] expectedTokenSequencesVal, String[] tokenImageVal) {
super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, new Object[]{initialise(
currentTokenVal, expectedTokenSequencesVal, tokenImageVal)}));
super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, initialise(
currentTokenVal, expectedTokenSequencesVal, tokenImageVal)));
this.currentToken = currentTokenVal;
this.expectedTokenSequences = expectedTokenSequencesVal;
this.tokenImage = tokenImageVal;
@ -59,7 +59,7 @@ public class ParseException extends QueryNodeParseException {
}
public ParseException() {
super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, new Object[]{"Error"}));
super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, "Error"));
}
/**

View File

@ -68,7 +68,7 @@ public class StandardSyntaxParser implements SyntaxParser, StandardSyntaxParserC
throw tme;
}
catch (Error tme) {
Message message = new MessageImpl(QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, new Object[]{query, tme.getMessage()});
Message message = new MessageImpl(QueryParserMessages.INVALID_SYNTAX_CANNOT_PARSE, query, tme.getMessage());
QueryNodeParseException e = new QueryNodeParseException(tme);
e.setQuery(query);
e.setNonLocalizedMessage(message);

View File

@ -74,8 +74,8 @@ public class AllowLeadingWildcardProcessor extends QueryNodeProcessorImpl {
case '*':
case '?':
throw new QueryNodeException(new MessageImpl(
QueryParserMessages.LEADING_WILDCARD_NOT_ALLOWED, new Object[]{node
.toQueryString(new EscapeQuerySyntaxImpl())}));
QueryParserMessages.LEADING_WILDCARD_NOT_ALLOWED, node
.toQueryString(new EscapeQuerySyntaxImpl())));
}
}

View File

@ -36,7 +36,7 @@ public class MessageImpl implements Message {
}
public MessageImpl(String key, Object[] args) {
public MessageImpl(String key, Object... args) {
this(key);
this.arguments = args;
}

View File

@ -45,8 +45,8 @@ import java.util.ResourceBundle;
*/
public class NLS {
private static Map/*<String, Class<Object>>*/ bundles = new HashMap/*<String, Class<Object>>*/(
0);
private static Map<String, Class<Object>> bundles =
new HashMap<String, Class<Object>>(0);
protected NLS() {
// Do not instantiate
@ -66,7 +66,7 @@ public class NLS {
}
public static String getLocalizedMessage(String key, Locale locale,
Object[] args) {
Object... args) {
String str = getLocalizedMessage(key, locale);
if (args.length > 0) {
@ -76,7 +76,7 @@ public class NLS {
return str;
}
public static String getLocalizedMessage(String key, Object[] args) {
public static String getLocalizedMessage(String key, Object... args) {
return getLocalizedMessage(key, Locale.getDefault(), args);
}
@ -89,7 +89,7 @@ public class NLS {
* @param clazz
* where constants will reside
*/
//@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
protected static void initializeMessages(String bundleName, Class clazz) {
try {
load(clazz);
@ -105,8 +105,8 @@ public class NLS {
// slow resource checking
// need to loop thru all registered resource bundles
for (Iterator/*<String>*/ it = bundles.keySet().iterator(); it.hasNext();) {
Class/*<Object>*/ clazz = (Class) bundles.get((String)it.next());
for (Iterator<String> it = bundles.keySet().iterator(); it.hasNext();) {
Class<Object> clazz = bundles.get(it.next());
ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(),
locale);
if (resourceBundle != null) {
@ -126,14 +126,14 @@ public class NLS {
/**
* @param clazz
*/
private static void load(Class/*<Object>*/ clazz) {
private static void load(Class<Object> clazz) {
final Field[] fieldArray = clazz.getDeclaredFields();
boolean isFieldAccessible = (clazz.getModifiers() & Modifier.PUBLIC) != 0;
// build a map of field names to Field objects
final int len = fieldArray.length;
Map/*<String, Field>*/ fields = new HashMap/*<String, Field>*/(len * 2);
Map<String, Field> fields = new HashMap<String, Field>(len * 2);
for (int i = 0; i < len; i++) {
fields.put(fieldArray[i].getName(), fieldArray[i]);
loadfieldValue(fieldArray[i], isFieldAccessible, clazz);
@ -145,7 +145,7 @@ public class NLS {
* @param isFieldAccessible
*/
private static void loadfieldValue(Field field, boolean isFieldAccessible,
Class/*<Object>*/ clazz) {
Class<Object> clazz) {
int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC;
int MOD_MASK = MOD_EXPECTED | Modifier.FINAL;
if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED)
@ -168,7 +168,7 @@ public class NLS {
* @param key
* - Message Key
*/
private static void validateMessage(String key, Class/*<Object>*/ clazz) {
private static void validateMessage(String key, Class<Object> clazz) {
// Test if the message is present in the resource bundle
try {
ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(),
@ -192,7 +192,7 @@ public class NLS {
/*
* Make a class field accessible
*/
//@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
private static void makeAccessible(final Field field) {
if (System.getSecurityManager() == null) {
field.setAccessible(true);

View File

@ -26,13 +26,13 @@ import junit.framework.TestCase;
public class TestNLS extends TestCase {
public void testMessageLoading() {
Message invalidSyntax = new MessageImpl(
MessagesTestBundle.Q0001E_INVALID_SYNTAX, new Object[]{"XXX"});
MessagesTestBundle.Q0001E_INVALID_SYNTAX, "XXX");
assertEquals("Syntax Error: XXX", invalidSyntax.getLocalizedMessage());
}
public void testMessageLoading_ja() {
Message invalidSyntax = new MessageImpl(
MessagesTestBundle.Q0001E_INVALID_SYNTAX, new Object[]{"XXX"});
MessagesTestBundle.Q0001E_INVALID_SYNTAX, "XXX");
assertEquals("構文エラー: XXX", invalidSyntax
.getLocalizedMessage(Locale.JAPANESE));
}
@ -43,7 +43,7 @@ public class TestNLS extends TestCase {
assertEquals("Truncated unicode escape sequence.", message);
message = NLS.getLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX,
new Object[]{"XXX"});
"XXX");
assertEquals("Syntax Error: XXX", message);
}
@ -54,7 +54,7 @@ public class TestNLS extends TestCase {
assertEquals("切り捨てられたユニコード・エスケープ・シーケンス。", message);
message = NLS.getLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX,
Locale.JAPANESE, new Object[]{"XXX"});
Locale.JAPANESE, "XXX");
assertEquals("構文エラー: XXX", message);
}
@ -66,7 +66,7 @@ public class TestNLS extends TestCase {
assertEquals("Truncated unicode escape sequence.", message);
message = NLS.getLocalizedMessage(MessagesTestBundle.Q0001E_INVALID_SYNTAX,
locale, new Object[]{"XXX"});
locale, "XXX");
assertEquals("Syntax Error: XXX", message);
}