use of java.text.ParsePosition in project logging-log4j2 by apache.
the class FastDateParser_MoreOrLessTest method testInputHasWrongTimeZone.
@Test
public void testInputHasWrongTimeZone() {
final FastDateParser parser = new FastDateParser("mm:ss z", NEW_YORK, Locale.US);
final String input = "11:23 Pacific Standard Time";
final ParsePosition parsePosition = new ParsePosition(0);
Assert.assertNotNull(parser.parse(input, parsePosition));
Assert.assertEquals(input.length(), parsePosition.getIndex());
parsePosition.setIndex(0);
Assert.assertNull(parser.parse("11:23 Pacific Standard ", parsePosition));
Assert.assertEquals(6, parsePosition.getErrorIndex());
}
use of java.text.ParsePosition in project logging-log4j2 by apache.
the class FastDateParser_MoreOrLessTest method testInputHasWrongDay.
@Test
public void testInputHasWrongDay() {
final FastDateParser parser = new FastDateParser("EEEE, MM/dd/yyy", NEW_YORK, Locale.US);
final String input = "Thursday, 03/23/61";
final ParsePosition parsePosition = new ParsePosition(0);
Assert.assertNotNull(parser.parse(input, parsePosition));
Assert.assertEquals(input.length(), parsePosition.getIndex());
parsePosition.setIndex(0);
Assert.assertNull(parser.parse("Thorsday, 03/23/61", parsePosition));
Assert.assertEquals(0, parsePosition.getErrorIndex());
}
use of java.text.ParsePosition in project lucene-solr by apache.
the class TestBackwardsCompatibility method testCreateSortedIndex.
// ant test -Dtestcase=TestBackwardsCompatibility -Dtestmethod=testCreateSortedIndex -Dtests.codec=default -Dtests.useSecurityManager=false -Dtests.bwcdir=/tmp/sorted
public void testCreateSortedIndex() throws Exception {
Path indexDir = getIndexDir().resolve("sorted");
Files.deleteIfExists(indexDir);
Directory dir = newFSDirectory(indexDir);
LogByteSizeMergePolicy mp = new LogByteSizeMergePolicy();
mp.setNoCFSRatio(1.0);
mp.setMaxCFSSegmentSizeMB(Double.POSITIVE_INFINITY);
MockAnalyzer analyzer = new MockAnalyzer(random());
analyzer.setMaxTokenLength(TestUtil.nextInt(random(), 1, IndexWriter.MAX_TERM_LENGTH));
// TODO: remove randomness
IndexWriterConfig conf = new IndexWriterConfig(analyzer);
conf.setMergePolicy(mp);
conf.setUseCompoundFile(false);
conf.setIndexSort(new Sort(new SortField("dateDV", SortField.Type.LONG, true)));
IndexWriter writer = new IndexWriter(dir, conf);
LineFileDocs docs = new LineFileDocs(random());
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
parser.setTimeZone(TimeZone.getTimeZone("UTC"));
ParsePosition position = new ParsePosition(0);
Field dateDVField = null;
for (int i = 0; i < 50; i++) {
Document doc = docs.nextDoc();
String dateString = doc.get("date");
position.setIndex(0);
Date date = parser.parse(dateString, position);
if (position.getErrorIndex() != -1) {
throw new AssertionError("failed to parse \"" + dateString + "\" as date");
}
if (position.getIndex() != dateString.length()) {
throw new AssertionError("failed to parse \"" + dateString + "\" as date");
}
if (dateDVField == null) {
dateDVField = new NumericDocValuesField("dateDV", 0l);
doc.add(dateDVField);
}
dateDVField.setLongValue(date.getTime());
if (i == 250) {
writer.commit();
}
writer.addDocument(doc);
}
writer.forceMerge(1);
writer.close();
dir.close();
}
use of java.text.ParsePosition in project lucene-solr by apache.
the class TrecContentSource method getDateFormatInfo.
private DateFormatInfo getDateFormatInfo() {
DateFormatInfo dfi = dateFormats.get();
if (dfi == null) {
dfi = new DateFormatInfo();
dfi.dfs = new SimpleDateFormat[DATE_FORMATS.length];
for (int i = 0; i < dfi.dfs.length; i++) {
dfi.dfs[i] = new SimpleDateFormat(DATE_FORMATS[i], Locale.ENGLISH);
dfi.dfs[i].setLenient(true);
}
dfi.pos = new ParsePosition(0);
dateFormats.set(dfi);
}
return dfi;
}
use of java.text.ParsePosition in project logging-log4j2 by apache.
the class Format method parseObject.
public Object parseObject(final String source) throws ParseException {
final ParsePosition pos = new ParsePosition(0);
final Object result = parseObject(source, pos);
if (pos.getIndex() == 0) {
throw new ParseException("Format.parseObject(String) failed", pos.getErrorIndex());
}
return result;
}
Aggregations