Example usage for java.lang NumberFormatException NumberFormatException

List of usage examples for java.lang NumberFormatException NumberFormatException

Introduction

In this page you can find the example usage for java.lang NumberFormatException NumberFormatException.

Prototype

public NumberFormatException(String s) 

Source Link

Document

Constructs a NumberFormatException with the specified detail message.

Usage

From source file:com.alibaba.druid.sql.parser.Lexer.java

public Number integerValue() {
    long result = 0;
    boolean negative = false;
    int i = mark, max = mark + bufPos;
    long limit;//from w  w  w .j av a  2s . co m
    long multmin;
    int digit;

    if (charAt(mark) == '-') {
        negative = true;
        limit = Long.MIN_VALUE;
        i++;
    } else {
        limit = -Long.MAX_VALUE;
    }
    multmin = negative ? MULTMIN_RADIX_TEN : N_MULTMAX_RADIX_TEN;
    if (i < max) {
        digit = digits[charAt(i++)];
        result = -digit;
    }
    while (i < max) {
        // Accumulating negatively avoids surprises near MAX_VALUE
        digit = digits[charAt(i++)];
        if (result < multmin) {
            return new BigInteger(numberString());
        }
        result *= 10;
        if (result < limit + digit) {
            return new BigInteger(numberString());
        }
        result -= digit;
    }

    if (negative) {
        if (i > mark + 1) {
            if (result >= Integer.MIN_VALUE) {
                return (int) result;
            }
            return result;
        } else { /* Only got "-" */
            throw new NumberFormatException(numberString());
        }
    } else {
        result = -result;
        if (result <= Integer.MAX_VALUE) {
            return (int) result;
        }
        return result;
    }
}

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Load a boolean property from the file.
 *
 * @param key The name of the property// w  w w .  j  av  a 2  s  . c o m
 * @param defaultValue The default value for this property
 * @return The value loaded from the file or the default value, if it is not
 * specified in the file.
 * @throws NumberFormatException The loaded value can not be converted to
 * boolean
 * @throws NullPointerException The parameter file was not initialized
 * @throws MissingOptionException The parameter is mandatory and it was not
 * found in the parameter file.
 */
private boolean getBooleanProperty(ParameterList key, boolean defaultValue)
        throws NumberFormatException, NullPointerException, MissingOptionException {
    try {
        boolean keyPresent = fileParameters.containsKey(key.name);
        String strValue = keyPresent ? fileParameters.getProperty(key.name).replaceAll("\\s", "") : null;
        if (!keyPresent && key.mandatory) {
            throw new MissingOptionException("The input parameter (" + key.name + ") was not found");
        } else if (!keyPresent || strValue.equals("")) {
            loadedParametersLog.append(key.name).append("=").append(defaultValue).append(" (DEFAULT)\n");
            return defaultValue;
        }
        loadedParametersLog.append(key.name).append("=").append(strValue).append("\n");
        return Boolean.parseBoolean(strValue);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(
                e.getMessage() + "\nThe input parameter (" + key.name + ") could not be converted to boolean.");
    } catch (NullPointerException e) {
        throw new NullPointerException(e.getMessage() + "\nThe parameter file was not initialized.");
    }
}

From source file:op.care.prescription.DlgOnDemand.java

private boolean saveOK() {
    if (ignoreEvent)
        return false;
    boolean OnOK = (cmbDocON.getSelectedIndex() > 0 || cmbHospitalON.getSelectedIndex() > 0);
    //        boolean OffOK = rbActive.isSelected() || jdcAB.getDate() != null;
    boolean sitOK = cmbSit.getSelectedItem() != null;
    boolean medOK = cmbMed.getModel().getSize() == 0 || cmbMed.getSelectedItem() != null;
    boolean intervOK = cmbIntervention.getSelectedItem() != null;

    boolean doseOK = true;
    try {/*from  w ww . j  av a2  s  . c  o m*/
        if (Double.parseDouble(txtEDosis.getText()) == 0d) {
            throw new NumberFormatException("Alle Dosierungen sind 0.");
        }

        if (Integer.parseInt(txtMaxTimes.getText()) == 0) {
            throw new NumberFormatException("Die Anzahl ist Null.");
        }
    } catch (NumberFormatException nfe) {
        doseOK = false;
    }

    String reason = "";
    reason += (OnOK ? ""
            : "Die Informationen zum <b>an</b>setzenden <b>Arzt</b> oder <b>KH</b> sind unvollstndig. ");
    //        reason += (OffOK ? "" : "Sie mssen sagen, wie lange diese Verordnung vorraussichtlich gelten wird. ");
    reason += (medOK ? "" : "Die <b>Medikamentenangabe</b> ist falsch. ");
    reason += (sitOK ? "" : "Sie haben keine <b>Situation</b> angegeben. ");
    reason += (intervOK ? "" : "Die Angaben ber die <b>Massnahmen</b> sind falsch. ");
    reason += (doseOK ? "" : "Sie mssen eine gltige <b>Dosierung</b> angegeben. ");

    if (!reason.isEmpty()) {
        OPDE.getDisplayManager().addSubMessage(new DisplayMessage(reason, DisplayMessage.WARNING));
    }
    return OnOK & medOK & intervOK & doseOK & sitOK;
}

From source file:DateUtils.java

/**
 * Convert string to timestamp including if available it's nanosecond portion 
 * so that it can be safely restored from variable in web page.
 * //from  w w w  .  j  av  a2s . c  o  m
 * @param strTimestamp - timestamp to convert
 * @return Timestamp - restored timestamp
 * @throws NumberFormatException - problem parsing the string
 */
public static Timestamp parseTimestamp(String strTimestamp) throws NumberFormatException {
    long lTime;
    int iNanos;

    if ("0".equals(strTimestamp)) {
        lTime = 0L;
        iNanos = 0;
    } else {
        int iIndex;

        iIndex = strTimestamp.indexOf(NANO_SEPARATOR);
        if (iIndex == -1) {
            throw new NumberFormatException(
                    "The timestamp string doesn't contain nanosecond separator: " + strTimestamp);
        }

        lTime = Long.parseLong(strTimestamp.substring(0, iIndex));
        iNanos = Integer.parseInt(strTimestamp.substring(iIndex + 1));
    }

    return new TimestampCopy(lTime, iNanos);
}

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Load an int property from the file.//from   w  w  w.ja  v  a  2s .c o m
 *
 * @param key The name of the property
 * @param defaultValue The default value for this property
 * @return The value loaded from the file or the default value, if it is not
 * specified in the file.
 * @throws NumberFormatException The loaded value can not be converted to
 * int
 * @throws NullPointerException The parameter file was not initialized
 * @throws MissingOptionException The parameter is mandatory and it was not
 * found in the parameter file.
 */
private int getIntegerProperty(ParameterList key, int defaultValue)
        throws NumberFormatException, NullPointerException, MissingOptionException {
    try {
        boolean keyPresent = fileParameters.containsKey(key.name);
        String strValue = keyPresent ? fileParameters.getProperty(key.name).replaceAll("\\s", "") : null;
        if (!keyPresent && key.mandatory) {
            throw new MissingOptionException("The input parameter (" + key.name + ") was not found");
        } else if (!keyPresent || strValue.equals("")) {
            loadedParametersLog.append(key.name).append("=").append(defaultValue).append(" (DEFAULT)\n");
            return defaultValue;
        }
        loadedParametersLog.append(key.name).append("=").append(strValue).append("\n");
        return Integer.parseInt(strValue);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(
                e.getMessage() + "\nThe input parameter (" + key.name + ") could not be converted to int.");
    } catch (NullPointerException e) {
        throw new NullPointerException(e.getMessage() + "\nThe parameter file was not initialized.");
    }
}

From source file:com.funambol.foundation.items.dao.PIMCalendarDAO.java

/**
 * Updates a calendar.//from  w  w  w . ja  v a  2s  .  c o  m
 *
 * @param cw as a CalendarWrapper object. If its last update time is null,
 *          then it's set to the current time.
 * @return the UID of the contact
 * @throws DAOException
 * @throws java.lang.Exception 
 * @see CalendarWrapper
 */
public String updateItem(CalendarWrapper cw) throws DAOException, Exception {

    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    RecurrencePattern rp = null;
    String id = null;
    String allDay = null;
    String body = null;
    Boolean allDayBoolean = null;
    Short busyStatus = null;
    String categories = null;
    String companies = null;
    int duration = 0;
    Date dend = null;
    short importance = 0;
    String location = null;
    Short meetingStatus = null;
    String mileage = null;
    Date replyTime = null;
    short sensitivity = 0;
    Date dstart = null;
    String subject = null;
    short recurrenceType = -1;
    int interval = 0;
    short monthOfYear = 0;
    short dayOfMonth = 0;
    String dayOfWeekMask = null;
    String priority = null;
    short instance = 0;
    String startDatePattern = null;
    String noEndDate = null;
    String endDatePattern = null;
    int occurrences = -1;
    Reminder reminder = null;
    CalendarContent c = null;
    Date completed = null;
    String complete = null;
    short percentComplete = -1;
    String folder = null;
    String dstartTimeZone = null;
    String dendTimeZone = null;
    String reminderTimeZone = null;

    StringBuffer queryUpdateFunPimCalendar = null;

    try {

        Timestamp lastUpdate = (cw.getLastUpdate() == null) ? new Timestamp(System.currentTimeMillis())
                : cw.getLastUpdate();

        c = cw.getCalendar().getCalendarContent();

        rp = c.getRecurrencePattern();

        id = cw.getId();

        boolean allDayB;
        allDayBoolean = c.getAllDay();
        if (allDayBoolean != null && allDayBoolean.booleanValue()) {
            allDayB = true;
            allDay = "1";
        } else {
            allDayB = false;
            allDay = "0";
        }

        body = Property.stringFrom(c.getDescription());

        if (c.getBusyStatus() != null) {
            busyStatus = new Short(c.getBusyStatus().shortValue());
        }
        categories = Property.stringFrom(c.getCategories());
        companies = Property.stringFrom(c.getOrganizer());
        if (c.getPriority() != null) {
            priority = c.getPriority().getPropertyValueAsString();
            if (priority != null && priority.length() > 0) {
                importance = Short.parseShort(priority);
            } // priority / importance ??
        }
        location = Property.stringFrom(c.getLocation());
        meetingStatus = c.getMeetingStatus();
        if (c.getMileage() != null) {
            mileage = String.valueOf(c.getMileage());
        }

        reminder = c.getReminder();

        String rt = null;
        if (c instanceof Event) {
            rt = Property.stringFrom(((Event) c).getReplyTime());
            replyTime = getDateFromString(allDayB, // @todo or false?
                    rt, "000000");
        }

        if (c.getAccessClass() != null) {

            String classEvent = null;
            classEvent = c.getAccessClass().getPropertyValueAsString();

            if (classEvent != null && classEvent.length() > 0) {
                sensitivity = Short.parseShort(classEvent);
            }
        }

        if (c.getSummary() != null) {

            subject = c.getSummary().getPropertyValueAsString();

        } else if (body != null && body.length() > 0) {

            String tmpBody = body;

            if (tmpBody.indexOf('.') != -1) {
                tmpBody = tmpBody.substring(0, tmpBody.indexOf('.'));
            }

            if (tmpBody.length() > SQL_SUBJECT_DIM) {
                tmpBody = tmpBody.substring(0, SQL_SUBJECT_DIM);
            }

            subject = tmpBody;
        }

        folder = Property.stringFrom(c.getFolder());
        dstartTimeZone = timeZoneFrom(c.getDtStart());
        dendTimeZone = timeZoneFrom(c.getDtEnd());
        reminderTimeZone = timeZoneFrom(c.getReminder());

        String sd = null;
        if (c.getDtStart() != null) {
            sd = c.getDtStart().getPropertyValueAsString();
            dstart = getDateFromString(allDayB, sd, "000000");
        }

        String ed = null;
        if ((sd != null && sd.length() > 0) || (c.getDtEnd() != null)) {

            ed = c.getDtEnd().getPropertyValueAsString();

            //
            // Fix for Siemens S56 end date issue only for event
            // @todo: verify if is really need to do this
            // Due to this fix, in  method getTwinItems() if the incoming 
            // Event has an empty EndDate we seek into the db for Events 
            // with EndDate equal to the StartDate value.
            //
            if (c instanceof Event) {
                if (ed == null || ed.length() == 0) {
                    ed = sd;
                }
            }

            dend = getDateFromString(allDayB, ed, "235900");
        }

        if (rp != null) {

            recurrenceType = rp.getTypeId();
            interval = rp.getInterval();
            monthOfYear = rp.getMonthOfYear();
            dayOfMonth = rp.getDayOfMonth();
            dayOfWeekMask = String.valueOf(rp.getDayOfWeekMask());
            instance = rp.getInstance();
            startDatePattern = rp.getStartDatePattern();

            boolean noEndDateB = rp.isNoEndDate();
            if (noEndDateB) {
                noEndDate = "1";
            } else {
                noEndDate = "0";
            }

            endDatePattern = rp.getEndDatePattern();
            occurrences = rp.getOccurrences();
        }

        String dc = null;
        if (c instanceof Task) {

            Task t = (Task) c;
            if (t.getDateCompleted() != null) {
                dc = t.getDateCompleted().getPropertyValueAsString();
                completed = getDateFromString(allDayB, dc, "000000");
            }

            complete = Property.stringFrom(t.getComplete());
            if (complete != null && "1".equals(complete)) {
                percentComplete = 100;
            } else {
                try {
                    percentComplete = Short.parseShort(Property.stringFrom(t.getPercentComplete()));
                    if (percentComplete < 0 || percentComplete > 100) {
                        throw new NumberFormatException("A percentage can't be " + percentComplete);
                    }
                } catch (NumberFormatException nfe) {
                    percentComplete = -1; // the short must go on
                }
            }

            meetingStatus = getTaskStatus(t);

        }

        queryUpdateFunPimCalendar = new StringBuffer();

        queryUpdateFunPimCalendar.append(SQL_UPDATE_FNBL_PIM_CALENDAR_BEGIN).append(SQL_FIELD_LAST_UPDATE)
                .append(SQL_EQUALS_QUESTIONMARK_COMMA);

        if (allDayBoolean != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_ALL_DAY).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (body != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_BODY).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        queryUpdateFunPimCalendar.append(SQL_FIELD_BUSY_STATUS).append(SQL_EQUALS_QUESTIONMARK_COMMA);

        if (categories != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_CATEGORIES).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (companies != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_COMPANIES).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        queryUpdateFunPimCalendar.append(SQL_FIELD_DURATION).append(SQL_EQUALS_QUESTIONMARK_COMMA);

        if (dend != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_DATE_END).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        } else if (ed != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_DATE_END).append(SQL_EQUALS_NULL_COMMA);
        }

        if (priority != null && priority.length() > 0) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_IMPORTANCE).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (location != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_LOCATION).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (meetingStatus != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_MEETING_STATUS).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (mileage != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_MILEAGE).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (reminder != null) {
            if (reminder.isActive()) {
                queryUpdateFunPimCalendar.append(SQL_FIELD_REMINDER).append(SQL_EQUALS_ONE_COMMA);
            } else {
                queryUpdateFunPimCalendar.append(SQL_FIELD_REMINDER).append(SQL_EQUALS_ZERO_COMMA);
            }
            queryUpdateFunPimCalendar.append(SQL_FIELD_REMINDER_TIME).append(SQL_EQUALS_QUESTIONMARK_COMMA);
            queryUpdateFunPimCalendar.append(SQL_FIELD_REMINDER_REPEAT_COUNT)
                    .append(SQL_EQUALS_QUESTIONMARK_COMMA);
            queryUpdateFunPimCalendar.append(SQL_FIELD_REMINDER_SOUND_FILE)
                    .append(SQL_EQUALS_QUESTIONMARK_COMMA);
            queryUpdateFunPimCalendar.append(SQL_FIELD_REMINDER_OPTIONS).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (replyTime != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_REPLY_TIME).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        } else if (rt != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_REPLY_TIME).append(SQL_EQUALS_NULL_COMMA);
        }

        queryUpdateFunPimCalendar.append(SQL_FIELD_SENSITIVITY).append(SQL_EQUALS_QUESTIONMARK_COMMA);

        if (dstart != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_DATE_START).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        } else if (sd != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_DATE_START).append(SQL_EQUALS_NULL_COMMA);
        }

        if (subject != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_SUBJECT).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        queryUpdateFunPimCalendar.append(SQL_FIELD_RECURRENCE_TYPE).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        queryUpdateFunPimCalendar.append(SQL_FIELD_INTERVAL).append(SQL_EQUALS_QUESTIONMARK_COMMA);

        queryUpdateFunPimCalendar.append(SQL_FIELD_MONTH_OF_YEAR).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        queryUpdateFunPimCalendar.append(SQL_FIELD_DAY_OF_MONTH).append(SQL_EQUALS_QUESTIONMARK_COMMA);

        if (dayOfWeekMask != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_DAY_OF_WEEK_MASK).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        queryUpdateFunPimCalendar.append(SQL_FIELD_INSTANCE).append(SQL_EQUALS_QUESTIONMARK_COMMA);

        if (startDatePattern != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_START_DATE_PATTERN)
                    .append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (noEndDate != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_NO_END_DATE).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (endDatePattern != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_END_DATE_PATTERN).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        } else {
            //
            // When NoEndDate is true, the PatterEndDate must be empty.
            //
            if ("1".equals(noEndDate)) {
                queryUpdateFunPimCalendar.append(SQL_FIELD_END_DATE_PATTERN).append(SQL_EQUALS_EMPTY_COMMA);
            }
        }

        queryUpdateFunPimCalendar.append(SQL_FIELD_OCCURRENCES).append(SQL_EQUALS_QUESTIONMARK_COMMA);

        if (completed != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_COMPLETED).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        } else if (dc != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_COMPLETED).append(SQL_EQUALS_NULL_COMMA);
        }

        if (percentComplete != -1) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_PERCENT_COMPLETE).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        } else if ("0".equals(complete)) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_PERCENT_COMPLETE).append(SQL_PERCENT_COMPLETE_FORMULA);
        }

        if (folder != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_FOLDER).append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (dstartTimeZone != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_START_DATE_TIME_ZONE)
                    .append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (dendTimeZone != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_END_DATE_TIME_ZONE)
                    .append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        if (reminderTimeZone != null) {
            queryUpdateFunPimCalendar.append(SQL_FIELD_REMINDER_TIME_ZONE)
                    .append(SQL_EQUALS_QUESTIONMARK_COMMA);
        }

        queryUpdateFunPimCalendar.append(SQL_FIELD_STATUS).append(SQL_EQUALS_QUESTIONMARK)
                .append(SQL_UPDATE_FNBL_PIM_CALENDAR_END);

        con = getUserDataSource().getRoutedConnection(userId);

        ps = con.prepareStatement(queryUpdateFunPimCalendar.toString());

        int k = 1;

        //
        // lastUpdate
        //
        ps.setLong(k++, lastUpdate.getTime());
        //
        // allDay
        //
        if (allDayBoolean != null) {
            ps.setString(k++, allDay);
        }
        //
        // body
        //
        if (body != null) {
            if (body.length() > SQL_BODY_DIM) {
                body = body.substring(0, SQL_BODY_DIM);
            }
            ps.setString(k++, body);
        }
        //
        // busy status
        //
        if (busyStatus != null) {
            ps.setShort(k++, busyStatus.shortValue());
        } else {
            ps.setNull(k++, Types.SMALLINT);
        }
        //
        // categories
        //
        if (categories != null) {
            if (categories.length() > SQL_CATEGORIES_DIM) {
                categories = categories.substring(0, SQL_CATEGORIES_DIM);
            }
            ps.setString(k++, categories);
        }
        //
        // companies
        //
        if (companies != null) {
            if (companies.length() > SQL_COMPANIES_DIM) {
                companies = companies.substring(0, SQL_COMPANIES_DIM);
            }
            ps.setString(k++, companies);
        }
        //
        // duration
        //
        ps.setInt(k++, duration);
        //
        // date End
        //
        if (dend != null) {
            ps.setTimestamp(k++, new Timestamp(dend.getTime()));
        }
        //
        // priority
        //
        if (priority != null && priority.length() > 0) {
            ps.setShort(k++, importance);
        }
        //
        // location
        //
        if (location != null) {
            if (location.length() > SQL_COMPANIES_DIM) {
                location = location.substring(0, SQL_LOCATION_DIM);
            }
            ps.setString(k++, location);
        }
        //
        // meeting status
        //
        if (meetingStatus != null) {
            ps.setShort(k++, meetingStatus.shortValue());
        }
        //
        // mileage
        //
        if (mileage != null) {
            ps.setString(k++, mileage);
        }
        //
        // reminder
        //
        if (reminder != null) {
            if (reminder.isActive()) {
                ps.setTimestamp(k++, getReminderTime(dstart, reminder));
                ps.setInt(k++, reminder.getRepeatCount());
                String soundFileValue = reminder.getSoundFile();
                if (soundFileValue != null && soundFileValue.length() > SQL_SOUNDFILE_DIM) {

                    soundFileValue = soundFileValue.substring(0, SQL_SOUNDFILE_DIM);
                }
                ps.setString(k++, soundFileValue);
                ps.setInt(k++, reminder.getOptions());
            } else {
                ps.setNull(k++, Types.TIMESTAMP);
                ps.setInt(k++, 0);
                ps.setString(k++, null);
                ps.setInt(k++, 0);
            }
        }
        //
        // reply time
        //
        if (replyTime != null) {
            ps.setTimestamp(k++, new Timestamp(replyTime.getTime()));
        }
        //
        // sensitivity
        //
        ps.setShort(k++, sensitivity);
        //
        // date start
        //
        if (dstart != null) {
            ps.setTimestamp(k++, new Timestamp(dstart.getTime()));
        }
        //
        // subject
        //
        if (subject != null) {
            if (subject.length() > SQL_SUBJECT_DIM) {
                subject = subject.substring(0, SQL_SUBJECT_DIM);
            }
            ps.setString(k++, subject);
        }
        //
        // recurrence Type
        //
        ps.setShort(k++, recurrenceType);
        //
        // interval
        //
        ps.setInt(k++, interval);
        //
        // month of year
        //
        ps.setShort(k++, monthOfYear);
        //
        // day of month
        //
        ps.setShort(k++, dayOfMonth);
        //
        // day of week mask
        //
        if (dayOfWeekMask != null) {
            if (dayOfWeekMask.length() > SQL_DAYOFWEEKMASK_DIM) {
                dayOfWeekMask = dayOfWeekMask.substring(0, SQL_DAYOFWEEKMASK_DIM);
            }
            ps.setString(k++, dayOfWeekMask);
        }
        //
        // instance
        //
        ps.setShort(k++, instance);
        //
        // start date pattern
        //
        if (startDatePattern != null) {
            if (startDatePattern.length() > SQL_STARTDATEPATTERN_DIM) {
                startDatePattern = startDatePattern.substring(0, SQL_STARTDATEPATTERN_DIM);
            }
            ps.setString(k++, startDatePattern);
        }
        //
        // no end date
        //
        if (noEndDate != null) {
            ps.setString(k++, noEndDate);
        }
        //
        // end date pattern
        //
        if (endDatePattern != null) {
            if (endDatePattern.length() > SQL_ENDDATEPATTERN_DIM) {
                endDatePattern = endDatePattern.substring(0, SQL_ENDDATEPATTERN_DIM);
            }
            ps.setString(k++, endDatePattern);
        }
        //
        // occurrences
        //
        ps.setInt(k++, occurrences);
        //
        // completed
        //
        if (completed != null) {
            ps.setTimestamp(k++, new Timestamp(completed.getTime()));
        }
        //
        // percent completed
        //
        if (percentComplete != -1) {
            ps.setShort(k++, percentComplete);
        }
        //
        // folder
        //
        if (folder != null) {
            if (folder.length() > SQL_FOLDER_DIM) {
                folder = folder.substring(0, SQL_FOLDER_DIM);
            }
            ps.setString(k++, folder);
        }
        //
        // time zones
        //
        if (dstartTimeZone != null) {
            if (dstartTimeZone.length() > SQL_TIME_ZONE_DIM) {
                dstartTimeZone = dstartTimeZone.substring(0, SQL_TIME_ZONE_DIM);
            }
            ps.setString(k++, dstartTimeZone);
        }
        if (dendTimeZone != null) {
            if (dendTimeZone.length() > SQL_TIME_ZONE_DIM) {
                dendTimeZone = dendTimeZone.substring(0, SQL_TIME_ZONE_DIM);
            }
            ps.setString(k++, dendTimeZone);
        }
        if (reminderTimeZone != null) {
            if (reminderTimeZone.length() > SQL_TIME_ZONE_DIM) {
                reminderTimeZone = reminderTimeZone.substring(0, SQL_TIME_ZONE_DIM);
            }
            ps.setString(k++, reminderTimeZone);
        }
        //
        // status
        //
        ps.setString(k++, String.valueOf('U'));
        //
        // id
        //
        ps.setLong(k++, Long.parseLong(id));
        //
        // user id
        //
        ps.setString(k++, cw.getUserId());

        ps.executeUpdate();

        DBTools.close(null, ps, null);

        ps = con.prepareStatement(SQL_DELETE_CALENDAR_EXCEPTIONS_BY_CALENDAR);

        ps.setLong(1, Long.parseLong(id));

        ps.executeUpdate();

        DBTools.close(null, ps, null);

        if (recurrenceType != -1) {
            List<ExceptionToRecurrenceRule> exceptions = rp.getExceptions();
            for (ExceptionToRecurrenceRule etrr : exceptions) {

                ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_CALENDAR_EXCEPTION);

                ps.setLong(1, Long.parseLong(id));
                ps.setString(2, (etrr.isAddition() ? "1" : "0"));
                ps.setTimestamp(3,
                        new Timestamp(getDateFromString(allDayB, etrr.getDate(), "000000").getTime()));

                ps.executeUpdate();

                DBTools.close(null, ps, null);
            }
        }

    } catch (Exception e) {
        throw new DAOException("Error updating a calendar item: " + e.getMessage());
    } finally {
        DBTools.close(con, ps, rs);
    }

    return id;
}

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Load a long property from the file.//  w ww  .java 2  s. c om
 *
 * @param key The name of the property
 * @param defaultValue The default value for this property
 * @return The value loaded from the file or the default value, if it is not
 * specified in the file.
 * @throws NumberFormatException The loaded value can not be converted to
 * long
 * @throws NullPointerException The parameter file was not initialized
 * @throws MissingOptionException The parameter is mandatory and it was not
 * found in the parameter file.
 */
private long getLongProperty(ParameterList key, long defaultValue)
        throws NumberFormatException, NullPointerException, MissingOptionException {
    try {
        boolean keyPresent = fileParameters.containsKey(key.name);
        String strValue = keyPresent ? fileParameters.getProperty(key.name).replaceAll("\\s", "") : null;
        if (!keyPresent && key.mandatory) {
            throw new MissingOptionException("The input parameter (" + key.name + ") was not found");
        } else if (!keyPresent || strValue.equals("")) {
            loadedParametersLog.append(key.name).append("=").append(defaultValue).append(" (DEFAULT)\n");
            return defaultValue;
        }
        loadedParametersLog.append(key.name).append("=").append(strValue).append("\n");
        return Integer.parseInt(strValue);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(
                e.getMessage() + "\nThe input parameter (" + key.name + ") could not be converted to long.");
    } catch (NullPointerException e) {
        throw new NullPointerException(e.getMessage() + "\nThe parameter file was not initialized.");
    }
}

From source file:org.firstopen.singularity.devicemgr.interrogator.WaveTrend_IO.java

/**
 * Returns a byte array built from the byte values represented by the input
 * hexadecimal string. That is, each pair of hexadecimal characters in the
 * input string is decoded into the byte value that they represent, and that
 * byte value is appended to a byte array which is ultimately returned. This
 * function doesn't care whether the hexadecimal characters are upper or
 * lower case, and it also can handle odd-length hex strings by assuming a
 * leading zero digit. If any character in the input string is not a valid
 * hexadecimal digit, it throws a NumberFormatException, in keeping with the
 * behavior of Java functions like Integer.parseInt().
 * //www .j av a  2s .com
 * @param hexString
 *            a string of hexadecimal characters
 * @return a byte array built from the bytes indicated by the input string
 * @throws NumberFormatException
 */
public byte[] hexToBuffer(String hexString) throws NumberFormatException {
    int length = hexString.length();
    byte[] buffer = new byte[(length + 1) / 2];
    boolean evenByte = true;
    byte nextByte = 0;
    int bufferOffset = 0;

    // If given an odd-length input string, there is an implicit
    // leading '0' that is not being given to us in the string.
    // In that case, act as if we had processed a '0' first.
    // It's sufficient to set evenByte to false, and leave nextChar
    // as zero which is what it would be if we handled a '0'.
    if ((length % 2) == 1)
        evenByte = false;

    for (int i = 0; i < length; i++) {
        char c = hexString.charAt(i);
        int nibble; // A "nibble" is 4 bits: a decimal 0..15

        if ((c >= '0') && (c <= '9'))
            nibble = c - '0';
        else if ((c >= 'A') && (c <= 'F'))
            nibble = c - 'A' + 0x0A;
        else if ((c >= 'a') && (c <= 'f'))
            nibble = c - 'a' + 0x0A;
        else
            throw new NumberFormatException("Invalid hex digit '" + c + "'.");

        if (evenByte) {
            nextByte = (byte) (nibble << 4);
        } else {
            nextByte += (byte) nibble;
            buffer[bufferOffset++] = nextByte;
        }

        evenByte = !evenByte;
    }

    return buffer;
}

From source file:org.lockss.util.NumberUtil.java

/**
 * Returns a short from a String representing a number in the 
 * Arabic or Roman number system.//from  w  ww.jav a2s . c o m
 * 
 * @param s the String
 * @return the number
 * @throws NumberFormatException if the String does not represent a valid
 *     short in the Arabic or Roman number systems
 */
public static short parseShort(String s) throws NumberFormatException {
    try {
        if (!StringUtil.isNullString(s))
            s = s.trim();
        return Short.parseShort(s);
    } catch (NumberFormatException ex) {
        int value = NumberUtil.parseRomanNumber(s);
        if (value > Short.MAX_VALUE) {
            throw new NumberFormatException("Value out of range. Value:\"" + s + "\"");
        }
        return (short) value;
    }
}

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Load a double property from the file.
 *
 * @param key The name of the property//w  ww  .  j  ava 2 s  .co  m
 * @param defaultValue The default value for this property
 * @return The value loaded from the file or the default value, if it is not
 * specified in the file.
 * @throws NumberFormatException The loaded value can not be converted to
 * double
 * @throws NullPointerException The parameter file was not initialized
 * @throws MissingOptionException The parameter is mandatory and it was not
 * found in the parameter file.
 */
private double getDoubleProperty(ParameterList key, double defaultValue)
        throws NumberFormatException, NullPointerException, MissingOptionException {
    try {
        boolean keyPresent = fileParameters.containsKey(key.name);
        String strValue = keyPresent ? fileParameters.getProperty(key.name).replaceAll("\\s", "") : null;
        if (!keyPresent && key.mandatory) {
            throw new MissingOptionException("The input parameter (" + key.name + ") was not found");
        } else if (!keyPresent || strValue.equals("")) {
            loadedParametersLog.append(key.name).append("=").append(defaultValue).append(" (DEFAULT)\n");
            return defaultValue;
        }
        loadedParametersLog.append(key.name).append("=").append(strValue).append("\n");
        return Double.parseDouble(strValue);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(
                e.getMessage() + "\nThe input parameter (" + key.name + ") could not be converted to double.");
    } catch (NullPointerException e) {
        throw new NullPointerException(e.getMessage() + "\nThe parameter file was not initialized.");
    }
}