当前位置: 首页>>代码示例>>Java>>正文


Java Format.parseObject方法代码示例

本文整理汇总了Java中java.text.Format.parseObject方法的典型用法代码示例。如果您正苦于以下问题:Java Format.parseObject方法的具体用法?Java Format.parseObject怎么用?Java Format.parseObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.Format的用法示例。


在下文中一共展示了Format.parseObject方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import java.text.Format; //导入方法依赖的package包/类
/**
 * <p>Parse the value with the specified <code>Format</code>.</p>
 *
 * @param value The value to be parsed.
 * @param formatter The Format to parse the value with.
 * @return The parsed value if valid or <code>null</code> if invalid.
 */
protected Object parse(String value, Format formatter) {

    ParsePosition pos = new ParsePosition(0);
    Object parsedValue = formatter.parseObject(value, pos);
    if (pos.getErrorIndex() > -1) {
        return null;
    }

    if (isStrict() && pos.getIndex() < value.length()) {
        return null;
    }

    if (parsedValue != null) {
        parsedValue = processParsedValue(parsedValue, formatter);
    }

    return parsedValue;

}
 
开发者ID:Ilhasoft,项目名称:data-binding-validator,代码行数:27,代码来源:AbstractFormatValidator.java

示例2: test_toFormat_parseObject_String

import java.text.Format; //导入方法依赖的package包/类
@Test
public void test_toFormat_parseObject_String() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30");
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TCKDateTimeFormatter.java

示例3: test_toFormat_parseObject_String_parseError

import java.text.Format; //导入方法依赖的package包/类
@Test(expectedExceptions=ParseException.class)
public void test_toFormat_parseObject_String_parseError() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    try {
        format.parseObject("ONEXXX");
    } catch (ParseException ex) {
        assertEquals(ex.getMessage().contains("ONEXXX"), true);
        assertEquals(ex.getErrorOffset(), 3);
        throw ex;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:TCKDateTimeFormatter.java

示例4: test_toFormat_parseObject_String_parseErrorLongText

import java.text.Format; //导入方法依赖的package包/类
@Test(expectedExceptions=ParseException.class)
public void test_toFormat_parseObject_String_parseErrorLongText() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    try {
        format.parseObject("ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
    } catch (DateTimeParseException ex) {
        assertEquals(ex.getMessage().contains("ONEXXX6789012345678901234567890123456789012345678901234567890123..."), true);
        assertEquals(ex.getParsedString(), "ONEXXX67890123456789012345678901234567890123456789012345678901234567890123456789");
        assertEquals(ex.getErrorIndex(), 3);
        throw ex;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:TCKDateTimeFormatter.java

示例5: test_toFormat_parseObject_StringParsePosition_parseError

import java.text.Format; //导入方法依赖的package包/类
@Test
public void test_toFormat_parseObject_StringParsePosition_parseError() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONEXXX", pos);
    assertEquals(pos.getIndex(), 0);  // TODO: is this right?
    assertEquals(pos.getErrorIndex(), 3);
    assertEquals(result, null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TCKDateTimeFormatter.java

示例6: test_toFormat_parseObject_StringParsePosition_nullString

import java.text.Format; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_toFormat_parseObject_StringParsePosition_nullString() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    format.parseObject((String) null, pos);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TCKDateTimeFormatter.java

示例7: test_toFormat_parseObject_StringParsePosition_nullParsePosition

import java.text.Format; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_toFormat_parseObject_StringParsePosition_nullParsePosition() throws Exception {
    // SimpleDateFormat has this behavior
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.parseObject("ONE30", (ParsePosition) null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKDateTimeFormatter.java

示例8: test_toFormat_parseObject_StringParsePosition

import java.text.Format; //导入方法依赖的package包/类
@Test
public void test_toFormat_parseObject_StringParsePosition() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor result = (TemporalAccessor) format.parseObject("ONE30XXX", pos);
    assertEquals(pos.getIndex(), 5);
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(result.isSupported(DAY_OF_MONTH), true);
    assertEquals(result.getLong(DAY_OF_MONTH), 30L);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TCKDateTimeFormatter.java

示例9: test_toFormat_parseObject_String_null

import java.text.Format; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_toFormat_parseObject_String_null() throws Exception {
    DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
    Format format = test.toFormat();
    format.parseObject((String) null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TCKDateTimeFormatter.java

示例10: test_toFormat_Query_parseObject_String

import java.text.Format; //导入方法依赖的package包/类
@Test
public void test_toFormat_Query_parseObject_String() throws Exception {
    Format format = DATE_FORMATTER.toFormat(LocalDate::from);
    LocalDate result = (LocalDate) format.parseObject("ONE2012 07 27");
    assertEquals(result, LocalDate.of(2012, 7, 27));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TCKDateTimeFormatter.java

示例11: test_toFormat_parseObject_StringParsePosition_dateTimeError

import java.text.Format; //导入方法依赖的package包/类
@Test(expectedExceptions=ParseException.class)
public void test_toFormat_parseObject_StringParsePosition_dateTimeError() throws Exception {
    Format format = DATE_FORMATTER.toFormat(LocalDate::from);
    format.parseObject("ONE2012 07 32");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TCKDateTimeFormatter.java


注:本文中的java.text.Format.parseObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。