Example usage for java.text ParseException ParseException

List of usage examples for java.text ParseException ParseException

Introduction

In this page you can find the example usage for java.text ParseException ParseException.

Prototype

public ParseException(String s, int errorOffset) 

Source Link

Document

Constructs a ParseException with the specified detail message and offset.

Usage

From source file:com.autsia.bracer.BracerParser.java

/**
 * Evaluates once parsed math expression with no variable included
 *
 * @return <code>String</code> representation of the result
 * @throws <code>ParseException</code> if the input expression is not
 *                                     correct
 * @since 1.0/* www . j  a v  a2  s . com*/
 */
public String evaluate() throws ParseException {
    if (!stackRPN.contains("var")) {
        return evaluate(0);
    }
    throw new ParseException("Unrecognized token: var", 0);
}

From source file:com.athena.peacock.common.core.util.XMLGregorialCalendarUtil.java

/**
 * <pre>// w w  w. j  a  v a  2  s. c  o m
 *    ?? 'yyyyMMddHHmmss' Date   .
 * </pre>
 * 
 * @param date   ?
 * @return ? Date ?
 */
private static Date getDate(String date) throws ParseException {
    if (date == null) {
        return null;
    }

    int yyyy = Integer.parseInt(date.substring(0, 4));
    int mm = Integer.parseInt(date.substring(4, 6));
    int dd = Integer.parseInt(date.substring(6, 8));
    int hh = Integer.parseInt(date.substring(8, 10));
    int mi = Integer.parseInt(date.substring(10, 12));
    int ss = Integer.parseInt(date.substring(12, 14));

    if (yyyy <= 1900 || yyyy >= 2999) {
        throw new ParseException("Invalid year.", yyyy);
    }
    if (mm < 1 || mm > 12) {
        throw new ParseException("Invalid month.", mm);
    }
    if (dd < 1 || dd > 31) {
        throw new ParseException("Invalid Day.", dd);
    }
    if (hh < 0 || hh > 23) {
        throw new ParseException("Invalid hour.", hh);
    }
    if (mi < 0 || mi > 59) {
        throw new ParseException("Invalid minute.", mi);
    }
    if (ss < 0 || ss > 59) {
        throw new ParseException("Invalid second.", ss);
    }

    return new SimpleDateFormat(DEFAULT_DATE_PATTERN).parse(date);
}

From source file:be.brunoparmentier.openbikesharing.app.parsers.BikeNetworkParser.java

public BikeNetworkParser(String toParse, boolean stripIdFromStationName) throws ParseException {
    ArrayList<Station> stations = new ArrayList<>();

    try {/*from ww w.  ja  v a2s. com*/
        JSONObject jsonObject = new JSONObject(toParse);
        JSONObject rawNetwork = jsonObject.getJSONObject("network");

        /* network name & id */
        String networkId = rawNetwork.getString("id");
        String networkName = rawNetwork.getString("name");
        String networkCompany = rawNetwork.getString("company");

        /* network location */
        BikeNetworkLocation networkLocation;
        {
            JSONObject rawLocation = rawNetwork.getJSONObject("location");

            double latitude = rawLocation.getDouble("latitude");
            double longitude = rawLocation.getDouble("longitude");
            String city = rawLocation.getString("city");
            String country = rawLocation.getString("country");

            networkLocation = new BikeNetworkLocation(latitude, longitude, city, country);
        }

        /* stations list */
        {
            JSONArray rawStations = rawNetwork.getJSONArray("stations");

            for (int i = 0; i < rawStations.length(); i++) {
                JSONObject rawStation = rawStations.getJSONObject(i);

                String id = rawStation.getString("id");
                String name = rawStation.getString("name");
                if (stripIdFromStationName)
                    name = name.replaceAll("^[0-9 ]*- *", "");
                String lastUpdate = rawStation.getString("timestamp");
                double latitude = rawStation.getDouble("latitude");
                double longitude = rawStation.getDouble("longitude");
                int freeBikes = rawStation.getInt("free_bikes");
                int emptySlots;
                if (!rawStation.isNull("empty_slots")) {
                    emptySlots = rawStation.getInt("empty_slots");
                } else {
                    emptySlots = -1;
                }

                Station station = new Station(id, name, lastUpdate, latitude, longitude, freeBikes, emptySlots);

                /* extra info */
                if (rawStation.has("extra")) {
                    JSONObject rawExtra = rawStation.getJSONObject("extra");

                    /* address */
                    if (rawExtra.has("address")) {
                        station.setAddress(rawExtra.getString("address"));
                    } else if (rawExtra.has("description")) {
                        station.setAddress(rawExtra.getString("description"));
                    }

                    /* banking */
                    if (rawExtra.has("banking")) { // JCDecaux
                        station.setBanking(rawExtra.getBoolean("banking"));
                    } else if (rawExtra.has("payment")) {
                        if (rawExtra.getString("payment").equals("AVEC_TPE")) { // vlille
                            station.setBanking(true);
                        } else {
                            station.setBanking(false);
                        }
                    } else if (rawExtra.has("ticket")) { // dublinbikes, citycycle
                        station.setBanking(rawExtra.getBoolean("ticket"));
                    }

                    /* bonus */
                    if (rawExtra.has("bonus")) {
                        station.setBonus(rawExtra.getBoolean("bonus"));
                    }

                    /* status */
                    if (rawExtra.has("status")) {
                        String status = rawExtra.getString("status");
                        if (status.equals("CLOSED") // villo
                                || status.equals("CLS") // ClearChannel
                                || status.equals("1") // vlille
                                || status.equals("offline")) { // idecycle
                            station.setStatus(StationStatus.CLOSED);
                        } else {
                            station.setStatus(StationStatus.OPEN);
                        }
                    } else if (rawExtra.has("statusValue")) {
                        if (rawExtra.getString("statusValue").equals("Not In Service")) { // Bike Share
                            station.setStatus(StationStatus.CLOSED);
                        } else {
                            station.setStatus(StationStatus.OPEN);
                        }
                    } else if (rawExtra.has("locked")) {
                        if (rawExtra.getBoolean("locked")) { // bixi
                            station.setStatus(StationStatus.CLOSED);
                        } else {
                            station.setStatus(StationStatus.OPEN);
                        }
                    } else if (rawExtra.has("open")) {
                        if (!rawExtra.getBoolean("open")) { // dublinbikes, citycycle
                            station.setStatus(StationStatus.CLOSED);
                        } else {
                            station.setStatus(StationStatus.OPEN);
                        }
                    }
                }
                stations.add(station);
            }
        }

        bikeNetwork = new BikeNetwork(networkId, networkName, networkCompany, networkLocation, stations);
    } catch (JSONException e) {
        throw new ParseException("Error parsing JSON", 0);
    }
}

From source file:org.tsm.concharto.util.TimeRangeFormat.java

/**
 * Parse a time range from a wide variety of formats.  Some examples:
 * '1941', 'May 2006', '1948 - 1950', 'Jan 23, 2002 10:23 - Feb 2005'
 * @param text to parse//from  w w w  .  j  a  v a 2  s  .  co m
 * @return TimeRange 
 * @throws ParseException if parsing failed
 */
public static TimeRange parse(String text) throws ParseException {
    TimeRange tr = null;
    if (!StringUtils.isEmpty(text)) {
        // first separate the begin and the end
        // we will try the '-' first
        String[] split = StringUtils.split(text, '-');
        boolean isRange;
        if (split.length == 1) {
            isRange = false;
        } else if (split.length == 2) {
            isRange = true;
        } else {
            throw new ParseException(text, 0);
        }

        // if there are two dates, then we parse each one
        if (isRange) {
            tr = parseRange(split);
        } else {
            // turn this single date into a range
            tr = parseSingleDate(text);
        }
    }
    return tr;
}

From source file:NumericTextField.java

public Double getDoubleValue() throws ParseException {
    Number result = getNumberValue();
    if ((result instanceof Long) == false && (result instanceof Double) == false) {
        throw new ParseException("Not a valid double", 0);
    }//w  w  w  .j  a  va 2  s .c o  m

    if (result instanceof Long) {
        result = new Double(result.doubleValue());
    }

    return (Double) result;
}

From source file:com.moz.fiji.mapreduce.lib.bulkimport.CSVBulkImporter.java

/**
 * Wrapper around CSV or TSV parsers based on the configuration of this job builder.
 * @return a list of fields split by the mColumnDelimiter.
 * @param line the line to split/* w ww. jav a 2  s. c  o  m*/
 * @throws ParseException if the parser encounters an error while parsing
 */
private List<String> split(String line) throws ParseException {
    if (CSV_DELIMITER.equals(mColumnDelimiter)) {
        return CSVParser.parseCSV(line);
    } else if (TSV_DELIMITER.equals(mColumnDelimiter)) {
        return CSVParser.parseTSV(line);
    }
    throw new ParseException("Unrecognized delimiter: " + mColumnDelimiter, 0);
}

From source file:org.osaf.cosmo.calendar.ICalDate.java

private void parseDates(String str) throws ParseException {

    if (str.indexOf(',') == -1) {
        date = isDate() ? new Date(str) : new DateTime(str, tz);
        if (isDate() && tz != null)
            throw new ParseException("DATE cannot have timezone", 0);
    }//from  w  w w  .j av a 2 s .  c o  m

    dates = isDate() ? new DateList(str, Value.DATE, tz) : new DateList(str, Value.DATE_TIME, tz);
}

From source file:fi.okm.mpass.idp.authn.impl.ValidateOIDCIDTokenACRTest.java

/**
 * Helper for building {@link SocialUserOpenIdConnectContext}.
 * //from w  w  w. j a va2 s.  c  o  m
 * @param acrs
 * @param jwt
 * @return
 * @throws Exception
 */
protected SocialUserOpenIdConnectContext buildContextWithACR(final List<ACR> acrs, final String jwt)
        throws Exception {
    final SocialUserOpenIdConnectContext suCtx = new SocialUserOpenIdConnectContext();
    suCtx.setAcrs(acrs);
    final OIDCTokenResponse oidcTokenResponse = Mockito.mock(OIDCTokenResponse.class);
    final JWT idToken = Mockito.mock(JWT.class);
    if (jwt == null) {
        Mockito.when(idToken.getJWTClaimsSet()).thenThrow(new ParseException("mockException", 1));
    } else {
        final JWTClaimsSet claimSet = JWTClaimsSet.parse(jwt);
        Mockito.when(idToken.getJWTClaimsSet()).thenReturn(claimSet);
    }
    final OIDCTokens oidcTokens = new OIDCTokens(idToken, new BearerAccessToken(), new RefreshToken());
    Mockito.when(oidcTokenResponse.getOIDCTokens()).thenReturn(oidcTokens);
    suCtx.setOidcTokenResponse(oidcTokenResponse);
    return suCtx;
}

From source file:edu.cornell.kfs.fp.businessobject.USBankRecordFieldUtils.java

/**
 * Extracts a cycle Date from a substring less any ending whitespace for a given beginning and ending position.
 * //w  ww.  j ava2  s  . c  om
 * @param line Superstring
 * @param begin Beginning index
 * @param end Ending index
 * @param lineCount The current line number
 * @return The cycle Date parsed from the trimmed substring
 * @throws ParseException When unable to parse the cycle Date
 */
public static Date extractCycleDate(String line, int begin, int end, int lineCount) throws ParseException {
    String day;
    Calendar cal = Calendar.getInstance();
    Date theDate;
    try {
        day = line.substring(begin, end);
        theDate = KfsDateUtils.newDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), Integer.parseInt(day));
    } catch (StringIndexOutOfBoundsException | IllegalArgumentException e) {
        // May encounter a StringIndexOutOfBoundsException if the string bounds do not match or 
        // an IllegalArgumentException if the Date does not parse correctly
        throw new ParseException("Unable to parse " + line.substring(begin, end)
                + " into a cycle date value on line " + lineCount, lineCount);
    }
    return theDate;
}

From source file:org.deidentifier.arx.DataHandle.java

/**
 * Returns a float value from the specified cell.
 *
 * @param row The cell's row index/*ww  w.j  a  v  a  2  s .  c o  m*/
 * @param col The cell's column index
 * @return the float
 * @throws ParseException the parse exception
 */
public Float getFloat(int row, int col) throws ParseException {
    String value = getValue(row, col);
    DataType<?> type = getDataType(getAttributeName(col));
    if (type instanceof ARXDecimal) {
        Double _double = ((ARXDecimal) type).parse(value);
        return _double == null ? null : _double.floatValue();
    } else if (type instanceof ARXInteger) {
        Long _long = ((ARXInteger) type).parse(value);
        return _long == null ? null : _long.floatValue();
    } else {
        throw new ParseException("Invalid datatype: " + type.getClass().getSimpleName(), col);
    }
}