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
Connect your IDE to all the code out there  Get Codota for Java
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;
	} 
 
	/** 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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) {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getErrorIndex, getIndex
This code example shows how to use the following methods:toString
        return dateFormat.format(new Date(0));
    } 
 
    private Calendar parseDate(Locale l, String fmt, String value) {
        SimpleDateFormat sdf = new SimpleDateFormat(fmt, l);
        ParsePosition pp = new ParsePosition(0);
        Date d = sdf.parse(value, pp);
        if (d == null) {
            fail(pp.toString());
        } 
        Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        c.setTime(d);
        return c;
    } 
 
    // http://code.google.com/p/android/issues/detail?id=13420 
    public void testParsingUncommonTimeZoneAbbreviations() { 
        String fmt = "yyyy-MM-dd HH:mm:ss.SSS z";
        String date = "2010-12-23 12:44:57.0 CET";
        // ICU considers "CET" (Central European Time) to be common in Britain... 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
            if (b.get("$date") instanceof Number) {
                o = new Date(((Number) b.get("$date")).longValue());
            } else { 
                SimpleDateFormat format = new SimpleDateFormat(_msDateFormat);
                format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
                o = format.parse(b.get("$date").toString(), new ParsePosition(0));
 
                if (o == null) {
                    // try older format with no ms 
                    format = new SimpleDateFormat(_secDateFormat);
                    format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));
                    o = format.parse(b.get("$date").toString(), new ParsePosition(0));
                } 
            } 
        } else if (b.containsField("$regex")) {
            o = Pattern.compile((String) b.get("$regex"),
                    BSON.regexFlags((String) b.get("$options")));
        } else if (b.containsField("$ts")) { //Legacy timestamp format
            Integer ts = ((Number) b.get("$ts")).intValue();
            Integer inc = ((Number) b.get("$inc")).intValue();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getIndex, setIndex
     * @param p current parsing position 
     * @return ASCII representation of the string 
     */ 
    @Override 
    public Object parseObject(String string, ParsePosition p) {
        int index = p.getIndex();
        String substring = string.substring(index);
        String result;
        try { 
            result = (String)parseObject(substring);
            p.setIndex(string.length() + 1);
        } catch ( java.text.ParseException e) {
            result = null;
        } 
        return result;
    } 
 
    /** 
     * Accessor method used to convert an ASCII 
     * string into an HTML string. 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getIndex
            } 
        } 
 
        public void parse(String pattern, String input, Date expected, int start, int end) {
            pFormat.applyPattern(pattern);
            ParsePosition position = new ParsePosition(start);
            Date result = pFormat.parse(input, position);
            assertTrue("Wrong result: " + pattern + " input: " + input
                    + " expected: " + expected + " result: " + result, expected
                    .equals(result));
            assertTrue("Wrong end position: " + pattern + " input: " + input,
                    position.getIndex() == end);
        } 
 
        public void verifyFormatTimezone(String timeZoneId, String expected1,
                String expected2, Date date) {
            format.setTimeZone(SimpleTimeZone.getTimeZone(timeZoneId));
            format.applyPattern("z, zzzz");
            assertEquals("Test z for TimeZone : " + timeZoneId, expected1,
                    format.format(date));
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getIndex
		else { 
			nf=(NumberFormat) o;
		} 
		str=optimze(str.toCharArray());
		 
		ParsePosition pp = new ParsePosition(0);
        Number result = nf.parse(str, pp);
		 
        if (pp.getIndex() < str.length()) {
            throw new ExpressionException("can't parse String [" + str + "] against locale ["+LocaleFactory.toString(locale)+"] to a number");
        } 
        if(result==null)
        	throw new ExpressionException("can't parse String [" + str + "] against locale ["+LocaleFactory.toString(locale)+"] to a number");
        return result.doubleValue();
		 
	} 
	 
	 
	private static String optimze(char[] carr) {
		StringBuffer sb=new StringBuffer();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 ParsePosition Questions & Answers:

See Code Examples for Java 8 ParsePosition Methods: