LUCENE-4199: fix more locale violations

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4199@1358791 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-07-08 17:27:56 +00:00
parent 9e7880eaa4
commit 9c742d4de4
9 changed files with 52 additions and 29 deletions

View File

@ -61,12 +61,12 @@ public class TestDateTools extends LuceneTestCase {
public void testStringtoTime() throws ParseException {
long time = DateTools.stringToTime("197001010000");
Calendar cal = new GregorianCalendar();
// we use default locale since LuceneTestCase randomizes it
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.getDefault());
cal.clear();
cal.set(1970, 0, 1, // year=1970, month=january, day=1
0, 0, 0); // hour, minute, second
cal.set(Calendar.MILLISECOND, 0);
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
assertEquals(cal.getTime().getTime(), time);
cal.set(1980, 1, 2, // year=1980, month=february, day=2
11, 5, 0); // hour, minute, second
@ -76,9 +76,9 @@ public class TestDateTools extends LuceneTestCase {
}
public void testDateAndTimetoString() throws ParseException {
Calendar cal = new GregorianCalendar();
// we use default locale since LuceneTestCase randomizes it
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.getDefault());
cal.clear();
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
22, 8, 56); // hour, minute, second
cal.set(Calendar.MILLISECOND, 333);
@ -141,9 +141,9 @@ public class TestDateTools extends LuceneTestCase {
}
public void testRound() {
Calendar cal = new GregorianCalendar();
// we use default locale since LuceneTestCase randomizes it
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.getDefault());
cal.clear();
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
22, 8, 56); // hour, minute, second
cal.set(Calendar.MILLISECOND, 333);

View File

@ -19,8 +19,10 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.TimeZone;
import java.util.TreeMap;
import org.apache.lucene.document.DateTools;
@ -230,10 +232,12 @@ public class TestCustomSearcherSort extends LuceneTestCase {
private class RandomGen {
RandomGen(Random random) {
this.random = random;
base.set(1980, 1, 1);
}
private Random random;
private Calendar base = new GregorianCalendar(1980, 1, 1);
// we use the default Locale/TZ since LuceneTestCase randomizes it
private Calendar base = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
// Just to generate some different Lucene Date strings
private String getLuceneDate() {

View File

@ -19,6 +19,8 @@ package org.apache.lucene.queries;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@ -56,7 +58,8 @@ public class ChainedFilterTest extends LuceneTestCase {
super.setUp();
directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), directory);
Calendar cal = new GregorianCalendar();
// we use the default Locale/TZ since LuceneTestCase randomizes it
Calendar cal = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
cal.clear();
cal.setTimeInMillis(1041397200000L); // 2003 January 01

View File

@ -316,7 +316,8 @@ public abstract class QueryParserBase {
}
/**
* Set locale used by date range parsing.
* Set locale used by date range parsing, lowercasing, and other
* locale-sensitive operations.
*/
public void setLocale(Locale locale) {
this.locale = locale;
@ -658,8 +659,8 @@ public abstract class QueryParserBase {
boolean endInclusive) throws ParseException
{
if (lowercaseExpandedTerms) {
part1 = part1==null ? null : part1.toLowerCase();
part2 = part2==null ? null : part2.toLowerCase();
part1 = part1==null ? null : part1.toLowerCase(locale);
part2 = part2==null ? null : part2.toLowerCase(locale);
}
@ -935,7 +936,7 @@ public abstract class QueryParserBase {
if (!allowLeadingWildcard && (termStr.startsWith("*") || termStr.startsWith("?")))
throw new ParseException("'*' or '?' not allowed as first character in WildcardQuery");
if (lowercaseExpandedTerms) {
termStr = termStr.toLowerCase();
termStr = termStr.toLowerCase(locale);
}
Term t = new Term(field, termStr);
return newWildcardQuery(t);
@ -964,7 +965,7 @@ public abstract class QueryParserBase {
protected Query getRegexpQuery(String field, String termStr) throws ParseException
{
if (lowercaseExpandedTerms) {
termStr = termStr.toLowerCase();
termStr = termStr.toLowerCase(locale);
}
Term t = new Term(field, termStr);
return newRegexpQuery(t);
@ -998,7 +999,7 @@ public abstract class QueryParserBase {
if (!allowLeadingWildcard && termStr.startsWith("*"))
throw new ParseException("'*' not allowed as first character in PrefixQuery");
if (lowercaseExpandedTerms) {
termStr = termStr.toLowerCase();
termStr = termStr.toLowerCase(locale);
}
Term t = new Term(field, termStr);
return newPrefixQuery(t);
@ -1018,7 +1019,7 @@ public abstract class QueryParserBase {
protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException
{
if (lowercaseExpandedTerms) {
termStr = termStr.toLowerCase();
termStr = termStr.toLowerCase(locale);
}
Term t = new Term(field, termStr);
return newFuzzyQuery(t, minSimilarity, fuzzyPrefixLength);

View File

@ -26,6 +26,7 @@ import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
@ -393,9 +394,9 @@ public class TestPrecedenceQueryParser extends LuceneTestCase {
private String getLocalizedDate(int year, int month, int day,
boolean extendLastDate) {
// we use the default Locale since LuceneTestCase randomizes it
// we use the default Locale/TZ since LuceneTestCase randomizes it
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
Calendar calendar = new GregorianCalendar();
Calendar calendar = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
calendar.set(year, month, day);
if (extendLastDate) {
calendar.set(Calendar.HOUR_OF_DAY, 23);
@ -409,7 +410,8 @@ public class TestPrecedenceQueryParser extends LuceneTestCase {
public void testDateRange() throws Exception {
String startDate = getLocalizedDate(2002, 1, 1, false);
String endDate = getLocalizedDate(2002, 1, 4, false);
Calendar endDateExpected = new GregorianCalendar();
// we use the default Locale/TZ since LuceneTestCase randomizes it
Calendar endDateExpected = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
endDateExpected.set(2002, 1, 4, 23, 59, 59);
endDateExpected.set(Calendar.MILLISECOND, 999);
final String defaultField = "default";

View File

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@ -694,9 +695,9 @@ public class TestQPHelper extends LuceneTestCase {
}
private String getLocalizedDate(int year, int month, int day) {
// we use the default Locale since LuceneTestCase randomizes it
// we use the default Locale/TZ since LuceneTestCase randomizes it
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
Calendar calendar = new GregorianCalendar();
Calendar calendar = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
calendar.clear();
calendar.set(year, month, day);
calendar.set(Calendar.HOUR_OF_DAY, 23);
@ -709,7 +710,8 @@ public class TestQPHelper extends LuceneTestCase {
public void testDateRange() throws Exception {
String startDate = getLocalizedDate(2002, 1, 1);
String endDate = getLocalizedDate(2002, 1, 4);
Calendar endDateExpected = new GregorianCalendar();
// we use the default Locale/TZ since LuceneTestCase randomizes it
Calendar endDateExpected = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
endDateExpected.clear();
endDateExpected.set(2002, 1, 4, 23, 59, 59);
endDateExpected.set(Calendar.MILLISECOND, 999);

View File

@ -24,6 +24,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
@ -592,9 +593,9 @@ public abstract class QueryParserTestBase extends LuceneTestCase {
}
private String getLocalizedDate(int year, int month, int day) {
// we use the default Locale since LuceneTestCase randomizes it
// we use the default Locale/TZ since LuceneTestCase randomizes it
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
Calendar calendar = new GregorianCalendar();
Calendar calendar = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
calendar.clear();
calendar.set(year, month, day);
calendar.set(Calendar.HOUR_OF_DAY, 23);
@ -607,7 +608,8 @@ public abstract class QueryParserTestBase extends LuceneTestCase {
public void testDateRange() throws Exception {
String startDate = getLocalizedDate(2002, 1, 1);
String endDate = getLocalizedDate(2002, 1, 4);
Calendar endDateExpected = new GregorianCalendar();
// we use the default Locale/TZ since LuceneTestCase randomizes it
Calendar endDateExpected = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
endDateExpected.clear();
endDateExpected.set(2002, 1, 4, 23, 59, 59);
endDateExpected.set(Calendar.MILLISECOND, 999);

View File

@ -35,6 +35,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
import java.util.zip.GZIPInputStream;
@ -149,11 +150,18 @@ public class JaspellTernarySearchTrie {
/** The base node in the trie. */
private TSTNode rootNode;
private final Locale locale;
/**
* Constructs an empty Ternary Search Trie.
*/
public JaspellTernarySearchTrie() {
this(Locale.ROOT);
}
public JaspellTernarySearchTrie(Locale locale) {
this.locale = locale;
}
// for loading
@ -214,7 +222,7 @@ public class JaspellTernarySearchTrie {
occur = Float.parseFloat(word.substring(pos + 1).trim());
word = word.substring(0, pos);
}
String key = word.toLowerCase();
String key = word.toLowerCase(locale);
if (rootNode == null) {
rootNode = new TSTNode(key.charAt(0), null);
}
@ -244,7 +252,7 @@ public class JaspellTernarySearchTrie {
if (occur2 != null) {
occur += occur2.floatValue();
}
currentNode = getOrCreateNode(word.trim().toLowerCase());
currentNode = getOrCreateNode(word.trim().toLowerCase(locale));
currentNode.data = occur;
}
}
@ -384,7 +392,7 @@ public class JaspellTernarySearchTrie {
*@return The <code>Float</code> retrieved from the Ternary Search Trie.
*/
public Float getAndIncrement(String key) {
String key2 = key.trim().toLowerCase();
String key2 = key.trim().toLowerCase(locale);
TSTNode node = getNode(key2);
if (node == null) {
return null;
@ -765,7 +773,7 @@ public class JaspellTernarySearchTrie {
* the Trie.
*/
public void remove(String key) {
deleteNode(getNode(key.trim().toLowerCase()));
deleteNode(getNode(key.trim().toLowerCase(locale)));
}
/**

View File

@ -20,6 +20,7 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Random;
import java.util.TimeZone;
@ -45,7 +46,7 @@ public class AlcoholicMergePolicy extends LogMergePolicy {
private final Calendar calendar;
public AlcoholicMergePolicy(TimeZone tz, Random random) {
this.calendar = new GregorianCalendar(tz);
this.calendar = new GregorianCalendar(tz, Locale.ROOT);
this.random = random;
maxMergeSize = _TestUtil.nextInt(random, 1024*1024, Integer.MAX_VALUE);
}