本文整理汇总了Java中java.time.format.SignStyle类的典型用法代码示例。如果您正苦于以下问题:Java SignStyle类的具体用法?Java SignStyle怎么用?Java SignStyle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SignStyle类属于java.time.format包,在下文中一共展示了SignStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_signStyle
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider = "signStyle")
public void test_signStyle(LocalDate localDate, SignStyle style, Class<?> expectedEx, String expectedStr) {
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
DateTimeFormatter formatter = builder.appendValue(ChronoField.YEAR, 2, 4, style)
.toFormatter();
formatter = formatter.withZone(ZoneOffset.UTC);
if (expectedEx == null) {
String output = formatter.format(localDate);
assertEquals(output, expectedStr);
} else {
try {
formatter.format(localDate);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
}
示例2: test_pad_NOT_NEGATIVE
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="Pad")
public void test_pad_NOT_NEGATIVE(int minPad, int maxPad, long value, String result) throws Exception {
try {
getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.NOT_NEGATIVE).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
if (result == null || value < 0) {
fail("Expected exception");
}
assertEquals(buf.toString(), result);
} catch (DateTimeException ex) {
if (result == null || value < 0) {
assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
} else {
throw ex;
}
}
}
示例3: test_pad_EXCEEDS_PAD
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="Pad")
public void test_pad_EXCEEDS_PAD(int minPad, int maxPad, long value, String result) throws Exception {
try {
getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.EXCEEDS_PAD).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
if (result == null) {
fail("Expected exception");
return; // unreachable
}
if (result.length() > minPad || value < 0) {
result = (value < 0 ? "-" + result : "+" + result);
}
assertEquals(buf.toString(), result);
} catch (DateTimeException ex) {
if (result != null) {
throw ex;
}
assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
示例4: test_parse_fresh
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="parseData")
public void test_parse_fresh(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
ParsePosition ppos = new ParsePosition(pos);
DateTimeFormatter dtf = getFormatter(DAY_OF_MONTH, minWidth, maxWidth, signStyle);
if (subsequentWidth > 0) {
// hacky, to reserve space
dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withDecimalStyle(decimalStyle);
}
TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
if (ppos.getErrorIndex() != -1) {
assertEquals(ppos.getErrorIndex(), expectedPos);
} else {
assertTrue(subsequentWidth >= 0);
assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
assertEquals(parsed.getLong(DAY_OF_MONTH), expectedValue);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}
示例5: test_parse_textField
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="parseData")
public void test_parse_textField(int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth, String text, int pos, int expectedPos, long expectedValue) {
ParsePosition ppos = new ParsePosition(pos);
DateTimeFormatter dtf = getFormatter(DAY_OF_WEEK, minWidth, maxWidth, signStyle);
if (subsequentWidth > 0) {
// hacky, to reserve space
dtf = builder.appendValue(DAY_OF_YEAR, subsequentWidth).toFormatter(locale).withDecimalStyle(decimalStyle);
}
TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
if (ppos.getErrorIndex() != -1) {
assertEquals(ppos.getErrorIndex(), expectedPos);
} else {
assertTrue(subsequentWidth >= 0);
assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
assertEquals(parsed.getLong(DAY_OF_WEEK), expectedValue);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}
示例6: test_parseDigitsAdjacentLenient
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="parseDigitsAdjacentLenient")
public void test_parseDigitsAdjacentLenient(String input, int parseLen, Integer parseMonth, Integer parsedDay) throws Exception {
setStrict(false);
ParsePosition pos = new ParsePosition(0);
DateTimeFormatter f = builder
.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL)
.appendValue(DAY_OF_MONTH, 2).toFormatter(locale).withDecimalStyle(decimalStyle);
TemporalAccessor parsed = f.parseUnresolved(input, pos);
if (pos.getErrorIndex() != -1) {
assertEquals(pos.getErrorIndex(), parseLen);
} else {
assertEquals(pos.getIndex(), parseLen);
assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}
示例7: test_parseStrict
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="parseStrict")
public void test_parseStrict(String text, int expectedIndex, int expectedErrorIndex, Number expectedMonth) {
builder.padNext(3, '#').appendValue(MONTH_OF_YEAR, 1, 3, SignStyle.NORMAL);
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
assertEquals(pos.getIndex(), expectedIndex);
assertEquals(pos.getErrorIndex(), expectedErrorIndex);
if (expectedMonth != null) {
assertEquals(parsed.isSupported(MONTH_OF_YEAR), true);
assertEquals(parsed.getLong(MONTH_OF_YEAR), expectedMonth.longValue());
} else {
assertEquals(parsed, null);
}
}
示例8: test_parseLenient
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="parseLenient")
public void test_parseLenient(String text, int expectedIndex, int expectedErrorIndex, Number expectedMonth) {
builder.parseLenient().padNext(3, '#').appendValue(MONTH_OF_YEAR, 1, 3, SignStyle.NORMAL);
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
assertEquals(pos.getIndex(), expectedIndex);
assertEquals(pos.getErrorIndex(), expectedErrorIndex);
if (expectedMonth != null) {
assertEquals(parsed.isSupported(MONTH_OF_YEAR), true);
assertEquals(parsed.getLong(MONTH_OF_YEAR), expectedMonth.longValue());
} else {
assertEquals(parsed, null);
}
}
示例9: test_parse_decoratedStartsWithPad_number
import java.time.format.SignStyle; //导入依赖的package包/类
@Test
public void test_parse_decoratedStartsWithPad_number() {
builder.padNext(3, '-').appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL);
TemporalAccessor parsed = builder.toFormatter().parseUnresolved("--2", pos);
assertEquals(pos.getIndex(), 3);
assertEquals(pos.getErrorIndex(), -1);
assertEquals(parsed.isSupported(MONTH_OF_YEAR), true);
assertEquals(parsed.getLong(MONTH_OF_YEAR), 2L); // +2, not -2
}
示例10: data_signStyle
import java.time.format.SignStyle; //导入依赖的package包/类
@DataProvider(name="signStyle")
Object[][] data_signStyle() {
return new Object[][] {
{LocalDate.of(0, 10, 2), SignStyle.ALWAYS, null, "+00"},
{LocalDate.of(2001, 10, 2), SignStyle.ALWAYS, null, "+2001"},
{LocalDate.of(-2001, 10, 2), SignStyle.ALWAYS, null, "-2001"},
{LocalDate.of(2001, 10, 2), SignStyle.NORMAL, null, "2001"},
{LocalDate.of(-2001, 10, 2), SignStyle.NORMAL, null, "-2001"},
{LocalDate.of(2001, 10, 2), SignStyle.NEVER, null, "2001"},
{LocalDate.of(-2001, 10, 2), SignStyle.NEVER, null, "2001"},
{LocalDate.of(2001, 10, 2), SignStyle.NOT_NEGATIVE, null, "2001"},
{LocalDate.of(-2001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},
{LocalDate.of(0, 10, 2), SignStyle.EXCEEDS_PAD, null, "00"},
{LocalDate.of(1, 10, 2), SignStyle.EXCEEDS_PAD, null, "01"},
{LocalDate.of(-1, 10, 2), SignStyle.EXCEEDS_PAD, null, "-01"},
{LocalDate.of(20001, 10, 2), SignStyle.ALWAYS, DateTimeException.class, ""},
{LocalDate.of(20001, 10, 2), SignStyle.NORMAL, DateTimeException.class, ""},
{LocalDate.of(20001, 10, 2), SignStyle.NEVER, DateTimeException.class, ""},
{LocalDate.of(20001, 10, 2), SignStyle.EXCEEDS_PAD, DateTimeException.class, ""},
{LocalDate.of(20001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""},
};
}
示例11: test_pad_NEVER
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="Pad")
public void test_pad_NEVER(int minPad, int maxPad, long value, String result) throws Exception {
try {
getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.NEVER).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
if (result == null) {
fail("Expected exception");
}
assertEquals(buf.toString(), result);
} catch (DateTimeException ex) {
if (result != null) {
throw ex;
}
assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
示例12: test_pad_NORMAL
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="Pad")
public void test_pad_NORMAL(int minPad, int maxPad, long value, String result) throws Exception {
try {
getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.NORMAL).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
if (result == null) {
fail("Expected exception");
}
assertEquals(buf.toString(), (value < 0 ? "-" + result : result));
} catch (DateTimeException ex) {
if (result != null) {
throw ex;
}
assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
示例13: test_pad_ALWAYS
import java.time.format.SignStyle; //导入依赖的package包/类
@Test(dataProvider="Pad")
public void test_pad_ALWAYS(int minPad, int maxPad, long value, String result) throws Exception {
try {
getFormatter(DAY_OF_MONTH, minPad, maxPad, SignStyle.ALWAYS).formatTo(new MockFieldValue(DAY_OF_MONTH, value), buf);
if (result == null) {
fail("Expected exception");
}
assertEquals(buf.toString(), (value < 0 ? "-" + result : "+" + result));
} catch (DateTimeException ex) {
if (result != null) {
throw ex;
}
assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
示例14: test_withLocale_same
import java.time.format.SignStyle; //导入依赖的package包/类
@Test
public void test_withLocale_same() throws Exception {
DateTimeFormatter base =
new DateTimeFormatterBuilder().appendLiteral("ONE")
.appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE)
.toFormatter(Locale.ENGLISH)
.withDecimalStyle(DecimalStyle.STANDARD);
DateTimeFormatter test = base.withLocale(Locale.ENGLISH);
assertSame(test, base);
}
示例15: test_appendValue_subsequent2_parse3
import java.time.format.SignStyle; //导入依赖的package包/类
@Test
public void test_appendValue_subsequent2_parse3() throws Exception {
builder.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NORMAL).appendValue(DAY_OF_MONTH, 2);
DateTimeFormatter f = builder.toFormatter();
assertEquals(f.toString(), "Value(MonthOfYear,1,2,NORMAL)Value(DayOfMonth,2)");
TemporalAccessor parsed = f.parseUnresolved("123", new ParsePosition(0));
assertEquals(parsed.getLong(MONTH_OF_YEAR), 1L);
assertEquals(parsed.getLong(DAY_OF_MONTH), 23L);
}