mirror of
https://github.com/apache/commons-lang.git
synced 2025-03-08 17:20:01 +00:00
replace tabs with spaces
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1668515 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bbfa8eb7df
commit
8bc91a95f9
@ -99,7 +99,7 @@ public class FastDateParser implements DateParser, Serializable {
|
|||||||
*
|
*
|
||||||
* Use {@link FastDateFormat#getInstance(String, TimeZone, Locale)} or another variation of the
|
* Use {@link FastDateFormat#getInstance(String, TimeZone, Locale)} or another variation of the
|
||||||
* factory methods of {@link FastDateFormat} to get a cached FastDateParser instance.
|
* factory methods of {@link FastDateFormat} to get a cached FastDateParser instance.
|
||||||
*
|
*
|
||||||
* @param pattern non-null {@link java.text.SimpleDateFormat} compatible
|
* @param pattern non-null {@link java.text.SimpleDateFormat} compatible
|
||||||
* pattern
|
* pattern
|
||||||
* @param timeZone non-null time zone to use
|
* @param timeZone non-null time zone to use
|
||||||
@ -529,7 +529,7 @@ private Strategy getStrategy(final String formatField, final Calendar definingCa
|
|||||||
case 'y':
|
case 'y':
|
||||||
return formatField.length()>2 ?LITERAL_YEAR_STRATEGY :ABBREVIATED_YEAR_STRATEGY;
|
return formatField.length()>2 ?LITERAL_YEAR_STRATEGY :ABBREVIATED_YEAR_STRATEGY;
|
||||||
case 'X':
|
case 'X':
|
||||||
return ISO8601TimeZoneStrategy.getStrategy(formatField.length());
|
return ISO8601TimeZoneStrategy.getStrategy(formatField.length());
|
||||||
case 'Z':
|
case 'Z':
|
||||||
if (formatField.equals("ZZ")) {
|
if (formatField.equals("ZZ")) {
|
||||||
return ISO_8601_STRATEGY;
|
return ISO_8601_STRATEGY;
|
||||||
@ -840,10 +840,10 @@ else if(value.startsWith("GMT")) {
|
|||||||
|
|
||||||
private static class ISO8601TimeZoneStrategy extends Strategy {
|
private static class ISO8601TimeZoneStrategy extends Strategy {
|
||||||
// Z, +hh, -hh, +hhmm, -hhmm, +hh:mm or -hh:mm
|
// Z, +hh, -hh, +hhmm, -hhmm, +hh:mm or -hh:mm
|
||||||
private final String pattern;
|
private final String pattern;
|
||||||
|
|
||||||
ISO8601TimeZoneStrategy(String pattern) {
|
ISO8601TimeZoneStrategy(String pattern) {
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -871,18 +871,18 @@ void setCalendar(FastDateParser parser, Calendar cal, String value) {
|
|||||||
private static final Strategy ISO_8601_2_STRATEGY = new ISO8601TimeZoneStrategy("(Z|(?:[+-]\\d{2}\\d{2}))");
|
private static final Strategy ISO_8601_2_STRATEGY = new ISO8601TimeZoneStrategy("(Z|(?:[+-]\\d{2}\\d{2}))");
|
||||||
private static final Strategy ISO_8601_3_STRATEGY = new ISO8601TimeZoneStrategy("(Z|(?:[+-]\\d{2}(?::)\\d{2}))");
|
private static final Strategy ISO_8601_3_STRATEGY = new ISO8601TimeZoneStrategy("(Z|(?:[+-]\\d{2}(?::)\\d{2}))");
|
||||||
|
|
||||||
static Strategy getStrategy(int tokenLen) {
|
static Strategy getStrategy(int tokenLen) {
|
||||||
switch(tokenLen) {
|
switch(tokenLen) {
|
||||||
case 1:
|
case 1:
|
||||||
return ISO_8601_1_STRATEGY;
|
return ISO_8601_1_STRATEGY;
|
||||||
case 2:
|
case 2:
|
||||||
return ISO_8601_2_STRATEGY;
|
return ISO_8601_2_STRATEGY;
|
||||||
case 3:
|
case 3:
|
||||||
return ISO_8601_3_STRATEGY;
|
return ISO_8601_3_STRATEGY;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("invalid number of X");
|
throw new IllegalArgumentException("invalid number of X");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Strategy NUMBER_MONTH_STRATEGY = new NumberStrategy(Calendar.MONTH) {
|
private static final Strategy NUMBER_MONTH_STRATEGY = new NumberStrategy(Calendar.MONTH) {
|
||||||
|
@ -272,7 +272,7 @@ protected List<Rule> parsePattern() {
|
|||||||
rule = selectNumberRule(Calendar.HOUR, tokenLen);
|
rule = selectNumberRule(Calendar.HOUR, tokenLen);
|
||||||
break;
|
break;
|
||||||
case 'X': // ISO 8601
|
case 'X': // ISO 8601
|
||||||
rule = Iso8601_Rule.getRule(tokenLen);
|
rule = Iso8601_Rule.getRule(tokenLen);
|
||||||
break;
|
break;
|
||||||
case 'z': // time zone (text)
|
case 'z': // time zone (text)
|
||||||
if (tokenLen >= 4) {
|
if (tokenLen >= 4) {
|
||||||
@ -590,10 +590,10 @@ private void readObject(final ObjectInputStream in) throws IOException, ClassNot
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void appendDigits(final StringBuffer buffer, final int value) {
|
private static void appendDigits(final StringBuffer buffer, final int value) {
|
||||||
buffer.append((char)(value / 10 + '0'));
|
buffer.append((char)(value / 10 + '0'));
|
||||||
buffer.append((char)(value % 10 + '0'));
|
buffer.append((char)(value % 10 + '0'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rules
|
// Rules
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
@ -824,7 +824,7 @@ public final void appendTo(final StringBuffer buffer, final int value) {
|
|||||||
if (value < 10) {
|
if (value < 10) {
|
||||||
buffer.append((char)(value + '0'));
|
buffer.append((char)(value + '0'));
|
||||||
} else {
|
} else {
|
||||||
appendDigits(buffer, value);
|
appendDigits(buffer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1130,7 +1130,7 @@ static String getTimeZoneDisplay(final TimeZone tz, final boolean daylight, fina
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Inner class to output a time zone name.</p>
|
* <p>Inner class to output a time zone name.</p>
|
||||||
*/
|
*/
|
||||||
private static class TimeZoneNameRule implements Rule {
|
private static class TimeZoneNameRule implements Rule {
|
||||||
@ -1246,26 +1246,26 @@ public void appendTo(final StringBuffer buffer, final Calendar calendar) {
|
|||||||
* or {@code +/-HH:MM}.</p>
|
* or {@code +/-HH:MM}.</p>
|
||||||
*/
|
*/
|
||||||
private static class Iso8601_Rule implements Rule {
|
private static class Iso8601_Rule implements Rule {
|
||||||
|
|
||||||
// Sign TwoDigitHours or Z
|
// Sign TwoDigitHours or Z
|
||||||
static final Iso8601_Rule ISO8601_HOURS = new Iso8601_Rule(3);
|
static final Iso8601_Rule ISO8601_HOURS = new Iso8601_Rule(3);
|
||||||
// Sign TwoDigitHours Minutes or Z
|
// Sign TwoDigitHours Minutes or Z
|
||||||
static final Iso8601_Rule ISO8601_HOURS_MINUTES = new Iso8601_Rule(5);
|
static final Iso8601_Rule ISO8601_HOURS_MINUTES = new Iso8601_Rule(5);
|
||||||
// Sign TwoDigitHours : Minutes or Z
|
// Sign TwoDigitHours : Minutes or Z
|
||||||
static final Iso8601_Rule ISO8601_HOURS_COLON_MINUTES = new Iso8601_Rule(6);
|
static final Iso8601_Rule ISO8601_HOURS_COLON_MINUTES = new Iso8601_Rule(6);
|
||||||
|
|
||||||
static Iso8601_Rule getRule(int tokenLen) {
|
static Iso8601_Rule getRule(int tokenLen) {
|
||||||
switch(tokenLen) {
|
switch(tokenLen) {
|
||||||
case 1:
|
case 1:
|
||||||
return Iso8601_Rule.ISO8601_HOURS;
|
return Iso8601_Rule.ISO8601_HOURS;
|
||||||
case 2:
|
case 2:
|
||||||
return Iso8601_Rule.ISO8601_HOURS_MINUTES;
|
return Iso8601_Rule.ISO8601_HOURS_MINUTES;
|
||||||
case 3:
|
case 3:
|
||||||
return Iso8601_Rule.ISO8601_HOURS_COLON_MINUTES;
|
return Iso8601_Rule.ISO8601_HOURS_COLON_MINUTES;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("invalid number of X");
|
throw new IllegalArgumentException("invalid number of X");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final int length;
|
final int length;
|
||||||
|
|
||||||
@ -1275,7 +1275,7 @@ static Iso8601_Rule getRule(int tokenLen) {
|
|||||||
* @param length The number of characters in output (unless Z is output)
|
* @param length The number of characters in output (unless Z is output)
|
||||||
*/
|
*/
|
||||||
Iso8601_Rule(final int length) {
|
Iso8601_Rule(final int length) {
|
||||||
this.length = length;
|
this.length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1292,7 +1292,7 @@ public int estimateLength() {
|
|||||||
@Override
|
@Override
|
||||||
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
|
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
|
||||||
int zoneOffset = calendar.get(Calendar.ZONE_OFFSET);
|
int zoneOffset = calendar.get(Calendar.ZONE_OFFSET);
|
||||||
if (zoneOffset == 0) {
|
if (zoneOffset == 0) {
|
||||||
buffer.append("Z");
|
buffer.append("Z");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1310,7 +1310,7 @@ public void appendTo(final StringBuffer buffer, final Calendar calendar) {
|
|||||||
appendDigits(buffer, hours);
|
appendDigits(buffer, hours);
|
||||||
|
|
||||||
if (length<5) {
|
if (length<5) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length==6) {
|
if (length==6) {
|
||||||
|
@ -558,62 +558,62 @@ public void testLang996() throws ParseException {
|
|||||||
assertEquals(expected.getTime(), fdp.parse("14May2014"));
|
assertEquals(expected.getTime(), fdp.parse("14May2014"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void test1806Argument() {
|
public void test1806Argument() {
|
||||||
getInstance("XXXX");
|
getInstance("XXXX");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Calendar initializeCalendar(TimeZone tz) {
|
private static Calendar initializeCalendar(TimeZone tz) {
|
||||||
Calendar cal = Calendar.getInstance(tz);
|
Calendar cal = Calendar.getInstance(tz);
|
||||||
cal.set(Calendar.YEAR, 2001);
|
cal.set(Calendar.YEAR, 2001);
|
||||||
cal.set(Calendar.MONTH, 1); // not daylight savings
|
cal.set(Calendar.MONTH, 1); // not daylight savings
|
||||||
cal.set(Calendar.DAY_OF_MONTH, 4);
|
cal.set(Calendar.DAY_OF_MONTH, 4);
|
||||||
cal.set(Calendar.HOUR_OF_DAY, 12);
|
cal.set(Calendar.HOUR_OF_DAY, 12);
|
||||||
cal.set(Calendar.MINUTE, 8);
|
cal.set(Calendar.MINUTE, 8);
|
||||||
cal.set(Calendar.SECOND, 56);
|
cal.set(Calendar.SECOND, 56);
|
||||||
cal.set(Calendar.MILLISECOND, 235);
|
cal.set(Calendar.MILLISECOND, 235);
|
||||||
return cal;
|
return cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static enum Expected1806 {
|
private static enum Expected1806 {
|
||||||
India(INDIA, "+05", "+0530", "+05:30", true),
|
India(INDIA, "+05", "+0530", "+05:30", true),
|
||||||
Greenwich(GMT, "Z", "Z", "Z", false),
|
Greenwich(GMT, "Z", "Z", "Z", false),
|
||||||
NewYork(NEW_YORK, "-05", "-0500", "-05:00", false);
|
NewYork(NEW_YORK, "-05", "-0500", "-05:00", false);
|
||||||
|
|
||||||
private Expected1806(TimeZone zone, String one, String two, String three, boolean hasHalfHourOffset) {
|
private Expected1806(TimeZone zone, String one, String two, String three, boolean hasHalfHourOffset) {
|
||||||
this.zone = zone;
|
this.zone = zone;
|
||||||
this.one = one;
|
this.one = one;
|
||||||
this.two = two;
|
this.two = two;
|
||||||
this.three = three;
|
this.three = three;
|
||||||
this.offset = hasHalfHourOffset ?30*60*1000 :0;
|
this.offset = hasHalfHourOffset ?30*60*1000 :0;
|
||||||
}
|
}
|
||||||
|
|
||||||
final TimeZone zone;
|
final TimeZone zone;
|
||||||
final String one;
|
final String one;
|
||||||
final String two;
|
final String two;
|
||||||
final String three;
|
final String three;
|
||||||
final long offset;
|
final long offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test1806() throws ParseException {
|
public void test1806() throws ParseException {
|
||||||
String formatStub = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
String formatStub = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
||||||
String dateStub = "2001-02-04T12:08:56.235";
|
String dateStub = "2001-02-04T12:08:56.235";
|
||||||
|
|
||||||
for (Expected1806 trial : Expected1806.values()) {
|
for (Expected1806 trial : Expected1806.values()) {
|
||||||
Calendar cal = initializeCalendar(trial.zone);
|
Calendar cal = initializeCalendar(trial.zone);
|
||||||
|
|
||||||
String message = trial.zone.getDisplayName()+";";
|
String message = trial.zone.getDisplayName()+";";
|
||||||
|
|
||||||
DateParser parser = getInstance(formatStub+"X", trial.zone);
|
DateParser parser = getInstance(formatStub+"X", trial.zone);
|
||||||
assertEquals(message+trial.one, cal.getTime().getTime(), parser.parse(dateStub+trial.one).getTime()-trial.offset);
|
assertEquals(message+trial.one, cal.getTime().getTime(), parser.parse(dateStub+trial.one).getTime()-trial.offset);
|
||||||
|
|
||||||
parser = getInstance(formatStub+"XX", trial.zone);
|
parser = getInstance(formatStub+"XX", trial.zone);
|
||||||
assertEquals(message+trial.two, cal.getTime(), parser.parse(dateStub+trial.two));
|
assertEquals(message+trial.two, cal.getTime(), parser.parse(dateStub+trial.two));
|
||||||
|
|
||||||
parser = getInstance(formatStub+"XXX", trial.zone);
|
parser = getInstance(formatStub+"XXX", trial.zone);
|
||||||
assertEquals(message+trial.three, cal.getTime(), parser.parse(dateStub+trial.three));
|
assertEquals(message+trial.three, cal.getTime(), parser.parse(dateStub+trial.three));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -276,54 +276,54 @@ public void testTimeZoneAsZ() throws Exception {
|
|||||||
assertEquals("+00:00", colonFormat.format(c));
|
assertEquals("+00:00", colonFormat.format(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Calendar initializeCalendar(TimeZone tz) {
|
private static Calendar initializeCalendar(TimeZone tz) {
|
||||||
Calendar cal = Calendar.getInstance(tz);
|
Calendar cal = Calendar.getInstance(tz);
|
||||||
cal.set(Calendar.YEAR, 2001);
|
cal.set(Calendar.YEAR, 2001);
|
||||||
cal.set(Calendar.MONTH, 1); // not daylight savings
|
cal.set(Calendar.MONTH, 1); // not daylight savings
|
||||||
cal.set(Calendar.DAY_OF_MONTH, 4);
|
cal.set(Calendar.DAY_OF_MONTH, 4);
|
||||||
cal.set(Calendar.HOUR_OF_DAY, 12);
|
cal.set(Calendar.HOUR_OF_DAY, 12);
|
||||||
cal.set(Calendar.MINUTE, 8);
|
cal.set(Calendar.MINUTE, 8);
|
||||||
cal.set(Calendar.SECOND, 56);
|
cal.set(Calendar.SECOND, 56);
|
||||||
cal.set(Calendar.MILLISECOND, 235);
|
cal.set(Calendar.MILLISECOND, 235);
|
||||||
return cal;
|
return cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void test1806Argument() {
|
public void test1806Argument() {
|
||||||
getInstance("XXXX");
|
getInstance("XXXX");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static enum Expected1806 {
|
private static enum Expected1806 {
|
||||||
India(INDIA, "+05", "+0530", "+05:30"), Greenwich(GMT, "Z", "Z", "Z"), NewYork(
|
India(INDIA, "+05", "+0530", "+05:30"), Greenwich(GMT, "Z", "Z", "Z"), NewYork(
|
||||||
NEW_YORK, "-05", "-0500", "-05:00");
|
NEW_YORK, "-05", "-0500", "-05:00");
|
||||||
|
|
||||||
private Expected1806(TimeZone zone, String one, String two, String three) {
|
private Expected1806(TimeZone zone, String one, String two, String three) {
|
||||||
this.zone = zone;
|
this.zone = zone;
|
||||||
this.one = one;
|
this.one = one;
|
||||||
this.two = two;
|
this.two = two;
|
||||||
this.three = three;
|
this.three = three;
|
||||||
}
|
}
|
||||||
|
|
||||||
final TimeZone zone;
|
final TimeZone zone;
|
||||||
final String one;
|
final String one;
|
||||||
final String two;
|
final String two;
|
||||||
final String three;
|
final String three;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test1806() throws ParseException {
|
public void test1806() throws ParseException {
|
||||||
for (Expected1806 trial : Expected1806.values()) {
|
for (Expected1806 trial : Expected1806.values()) {
|
||||||
Calendar cal = initializeCalendar(trial.zone);
|
Calendar cal = initializeCalendar(trial.zone);
|
||||||
|
|
||||||
DatePrinter printer = getInstance("X", trial.zone);
|
DatePrinter printer = getInstance("X", trial.zone);
|
||||||
assertEquals(trial.one, printer.format(cal));
|
assertEquals(trial.one, printer.format(cal));
|
||||||
|
|
||||||
printer = getInstance("XX", trial.zone);
|
printer = getInstance("XX", trial.zone);
|
||||||
assertEquals(trial.two, printer.format(cal));
|
assertEquals(trial.two, printer.format(cal));
|
||||||
|
|
||||||
printer = getInstance("XXX", trial.zone);
|
printer = getInstance("XXX", trial.zone);
|
||||||
assertEquals(trial.three, printer.format(cal));
|
assertEquals(trial.three, printer.format(cal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user