Java 8 ParsePosition - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ParsePosition class.

This code example shows how to use the following methods: getIndex, setErrorIndex, setIndex
     * @param text the text string to parse 
     * @return the parsed Date value 
     * @throws DataParseException if an error occurs during parsing 
     */ 
    public Date parseDate(String text) throws DataParseException {
        m_pos.setErrorIndex(0);
        m_pos.setIndex(0);
         
        // parse the data value, convert to the wrapper type 
        Date d = null;
        try { 
            d = Date.valueOf(text);
            m_pos.setIndex(text.length());
        } catch ( IllegalArgumentException e ) {
            d = null;
        } 
        if ( d == null ) {
            java.util.Date d1 = m_dfmt.parse(text, m_pos);
            if ( d1 != null ) {
                d = new Date(d1.getTime());

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getErrorIndex, getIndex
	} 
 
	@Override 
	public Number parse(String text, Locale locale) throws ParseException {
		NumberFormat format = getNumberFormat(locale);
		ParsePosition position = new ParsePosition(0);
		Number number = format.parse(text, position);
		if (position.getErrorIndex() != -1) {
			throw new ParseException(text, position.getIndex());
		} 
		if (!this.lenient) {
			if (text.length() != position.getIndex()) {
				// indicates a part of the string that was not parsed 
				throw new ParseException(text, position.getIndex());
			} 
		} 
		return number;
	} 
 
	/** 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getIndex, setErrorIndex, setIndex
     * @param text the text string to parse 
     * @return the parsed Date value 
     * @throws DataParseException if an error occurs during parsing 
     */ 
    public Date parseDate(String text) throws DataParseException {
        m_pos.setErrorIndex(0);
        m_pos.setIndex(0);
         
        // parse the data value, convert to the wrapper type 
        Date d = null;
        try { 
            d = Date.valueOf(text);
            m_pos.setIndex(text.length());
        } catch ( IllegalArgumentException e ) {
            d = null;
        } 
        if ( d == null ) {
            java.util.Date d1 = m_dfmt.parse(text, m_pos);
            if ( d1 != null ) {
                d = new Date(d1.getTime());

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getErrorIndex
     * @param argument The object to parse 
     * @return The object 
     */ 
    @SuppressWarnings("unchecked") 
    Object transform(final Format format, final String argument) {
        ParsePosition position = new ParsePosition(0);
        Object result = format.parseObject(argument, position);
        if (position.getErrorIndex() != -1) {
            throw new CucumberException("Can't parse '" + argument + "' using format " + format);
        } 
        return result; 
    } 
 
    @Override 
    public String toString(Object obj) {
        return getFormats().get(0).format(obj);
    } 
 
    @Override 
    public boolean canConvert(Class type) {
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getErrorIndex, getIndex

Related Java 8 ParsePosition Questions & Answers:

See Code Examples for Java 8 ParsePosition Methods: