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() 

Source Link

Document

Constructs a NumberFormatException with no detail message.

Usage

From source file:com.haulmont.cuba.gui.app.core.entitylog.EntityLogBrowser.java

public void search() {
    int maxRows;//from w w  w  .j av  a2s . c o  m
    try {
        maxRows = Integer.parseInt(showRowField.getValue().toString());
        if (maxRows >= 0)
            entityLogDs.setMaxResults(maxRows);
        else
            throw new NumberFormatException();
    } catch (Exception e) {
        showNotification(messages.getMessage(getClass(), "invalidNumber"), NotificationType.HUMANIZED);
        return;
    }
    Entity entity = instancePicker.getValue();
    Map<String, Object> params = new HashMap<>();
    if (entity != null) {
        Object entityId = referenceToEntitySupport.getReferenceId(entity);
        if (entityId instanceof UUID) {
            params.put("entityId", entityId);
        } else if (entityId instanceof String) {
            params.put("stringEntityId", entityId);
        } else if (entityId instanceof Integer) {
            params.put("intEntityId", entityId);
        } else if (entityId instanceof Long) {
            params.put("longEntityId", entityId);
        }
    }
    entityLogDs.refresh(params);
}

From source file:net.jmhertlein.alphonseirc.AlphonseBot.java

private int[] handleDestProcessing(String target, String[] args) {
    if (args.length == 4) {
        String xPos = args[2], yPos = args[3];
        int i, j;
        try {// w  w w  .  jav  a  2s.  com
            i = Integer.parseInt(xPos);
            if (i < 0 || i > 2) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException nfe) {
            sendMessage(target,
                    String.format("Invalid integer \"%s\", should be int in range [0,2] inclusive.", xPos));
            return null;
        }
        try {
            j = Integer.parseInt(yPos);
            if (j < 0 || j > 2) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException nfe) {
            sendMessage(target,
                    String.format("Invalid integer \"%s\", should be int in range [0,2] inclusive.", yPos));
            return null;
        }

        return new int[] { i, j };
    } else if (args.length == 3) {
        if (args[2].length() != 1) {
            sendMessage(target, "Label should be a single character between A and I, inclusive.");
            return null;
        }

        char input = args[2].toUpperCase().charAt(0);
        if (input < 'A' || input > 'I') {
            sendMessage(target, "Label should be a single character between A and I, inclusive.");
            return null;
        }

        return TTTGame.decode(input);
    } else {
        sendMessage(target,
                "Incorrect number of args. Usage: !ttt mv (<x> <y>|<label>)  where (0,0) is the top-left");
        return null;
    }
}

From source file:com.archivas.clienttools.arcmover.cli.ArcProfileMgr.java

public Integer validatePort(CommandLine cmdLine) throws ParseException {
    String option = "port";

    if (!cmdLine.hasOption(option)) {
        return null;
    }/*from  w  w w . ja  v a2  s  . c o m*/

    Integer port = null;
    String value = cmdLine.getOptionValue(option);
    if (value != null) {
        try {
            port = Integer.valueOf(value);
            if (port < 0) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException nfe) {
            throw new ParseException("Invalid " + option + " : " + value);
        }
    }
    return port;
}

From source file:com.itude.mobile.android.util.StringUtil.java

/**
 * Get {@link Double} value/*from  ww w .  j  a v  a2s  . c  o m*/
 * @param value value
 * @return double value
 */
public static Double getDoubleValue(String value) {
    if (isBlank(value)) {
        throw new NumberFormatException();
    }

    return Double.parseDouble(value.replaceAll(",", "."));
}

From source file:org.rhq.helpers.rtfilter.filter.RtFilter.java

/**
 * Initialize parameters from the web.xml filter init-params
 *
 * @param conf the filter configuration/*  w  w  w  .ja  va  2 s.  c o  m*/
 */
private void initializeParameters(FilterConfig conf) throws UnavailableException {
    String chop = conf.getInitParameter(InitParams.CHOP_QUERY_STRING);
    if (chop != null) {
        this.chopUrl = Boolean.valueOf(chop.trim()).booleanValue();
    }

    String logDirectoryPath = conf.getInitParameter(InitParams.LOG_DIRECTORY);
    if (logDirectoryPath != null) {
        this.logDirectory = new File(logDirectoryPath.trim());
    } else {
        /*
         * If this is a JBossAS deployed container, or a Standalone TC container, use a logical
         * default (so those plugins can be written in a compatible way).
         * First, try to default to "${JBOSS_SERVER_HOME_DIR_SYSPROP}/JBOSSAS_SERVER_LOG_SUBDIR/rt";
         * If not set try "${TOMCAT_SERVER_HOME_DIR_SYSPROP}/TOMCAT_SERVER_LOG_SUBDIR/rt";
         * If, for some reason, neither property is set, fall back to "${java.io.tmpdir}/rhq/rt".
         */
        File serverLogDir = null;
        String serverHomeDirPath = System.getProperty(JBOSSAS_SERVER_HOME_DIR_SYSPROP);

        if (null != serverHomeDirPath) {
            serverLogDir = new File(serverHomeDirPath, JBOSSAS_SERVER_LOG_SUBDIR);
        } else {
            serverHomeDirPath = System.getProperty(TOMCAT_SERVER_HOME_DIR_SYSPROP);
            if (serverHomeDirPath != null) {
                serverLogDir = new File(serverHomeDirPath, TOMCAT_SERVER_LOG_SUBDIR);
            }
        }

        if (null != serverLogDir) {
            this.logDirectory = new File(serverLogDir, "rt");
        } else {
            this.logDirectory = new File(System.getProperty(JAVA_IO_TMPDIR_SYSPROP), "rhq/rt");
            log.warn(
                    "The 'logDirectory' filter init param was not set. Also, the standard system properties were not set ("
                            + JBOSSAS_SERVER_HOME_DIR_SYSPROP + ", " + TOMCAT_SERVER_HOME_DIR_SYSPROP
                            + "); defaulting RT log directory to '" + this.logDirectory + "'.");
        }
    }

    if (this.logDirectory.exists()) {
        if (!this.logDirectory.isDirectory()) {
            throw new UnavailableException(
                    "Log directory '" + this.logDirectory + "' exists but is not a directory.");
        }
    } else {
        try {
            this.logDirectory.mkdirs();
        } catch (Exception e) {
            throw new UnavailableException(
                    "Unable to create log directory '" + this.logDirectory + "' - cause: " + e);
        }

        if (!logDirectory.exists()) {
            throw new UnavailableException("Unable to create log directory '" + this.logDirectory + "'.");
        }
    }

    String logFilePrefixString = conf.getInitParameter(InitParams.LOG_FILE_PREFIX);
    if (logFilePrefixString != null) {
        this.logFilePrefix = logFilePrefixString.trim();
    }

    String dontLog = conf.getInitParameter(InitParams.DONT_LOG_REG_EX);
    if (dontLog != null) {
        this.dontLogPattern = Pattern.compile(dontLog.trim());
    }

    String flushTimeout = conf.getInitParameter(InitParams.TIME_BETWEEN_FLUSHES_IN_SEC);
    if (flushTimeout != null) {
        try {
            timeBetweenFlushes = Long.parseLong(flushTimeout.trim()) * 1000;
        } catch (NumberFormatException nfe) {
            timeBetweenFlushes = DEFAULT_FLUSH_TIMEOUT;
        }
    }

    String uriOnly = conf.getInitParameter(InitParams.MATCH_ON_URI_ONLY);
    if (uriOnly != null) {
        matchOnUriOnly = Boolean.getBoolean(uriOnly.trim());
    }

    String lines = conf.getInitParameter(InitParams.FLUSH_AFTER_LINES);
    if (lines != null) {
        try {
            flushAfterLines = Long.parseLong(lines.trim());
            if (flushAfterLines <= 0) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException nfe) {
            log.error("Invalid '" + InitParams.FLUSH_AFTER_LINES + "' init parameter: " + lines
                    + " (value must be a positive integer) - using default.");
            flushAfterLines = DEFAULT_FLUSH_AFTER_LINES;
        }
    }

    String maxLogFileSizeString = conf.getInitParameter(InitParams.MAX_LOG_FILE_SIZE);
    if (maxLogFileSizeString != null) {
        try {
            this.maxLogFileSize = Long.parseLong(maxLogFileSizeString.trim());
            if (this.maxLogFileSize <= 0) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            log.error("Invalid '" + InitParams.MAX_LOG_FILE_SIZE + "' init parameter: " + maxLogFileSizeString
                    + " (value must be a positive integer) - using default.");
            this.maxLogFileSize = DEFAULT_MAX_LOG_FILE_SIZE;
        }
    }

    /*
     * Read mappings from a vhost mapping file in the format of a properties file
     * inputhost = mapped host
     * This file needs to live in the search path - e.g. in server/<config>/conf/
     * The name of it must be passed as init-param to the filter. Otherwise the mapping
     * will not be used.
     *  <param-name>vHostMappingFile</param-name>
     */
    String vhostMappingFileString = conf.getInitParameter(InitParams.VHOST_MAPPING_FILE);
    if (vhostMappingFileString != null) {
        InputStream stream = getClass().getClassLoader().getResourceAsStream(vhostMappingFileString);
        if (stream != null) {
            try {
                vhostMappings.load(stream);
            } catch (IOException e) {
                log.warn("Can't read vhost mappings from " + vhostMappingFileString + " :" + e.getMessage());
            } finally {
                if (stream != null)
                    try {
                        stream.close();
                    } catch (Exception e) {
                        log.debug(e);
                    }
            }
        } else {
            log.warn("Can't read vhost mappings from " + vhostMappingFileString);
        }
    }
}

From source file:it.mb.whatshare.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == QR_CODE_SCANNED) {
        if (resultCode == RESULT_OK) {
            String result = data.getStringExtra("SCAN_RESULT");
            try {
                String[] keys = result.split(" ");

                if (keys.length < SHARED_SECRET_SIZE)
                    throw new NumberFormatException();

                int[] sharedSecret = new int[SHARED_SECRET_SIZE];
                for (int i = 0; i < SHARED_SECRET_SIZE; i++) {
                    sharedSecret[i] = Integer.valueOf(keys[i]);
                }//from  w w w  .  j a v a 2s  .co  m

                String space = "";
                StringBuilder deviceName = new StringBuilder();
                for (int i = SHARED_SECRET_SIZE; i < keys.length; i++) {
                    deviceName.append(space);
                    deviceName.append(keys[i]);
                    space = " ";
                }

                tracker.sendEvent("qr", "result", "scan_ok", 0L);
                Dialogs.promptForInboundName(deviceName.toString(), sharedSecret, this);
            } catch (NumberFormatException e) {
                tracker.sendEvent("qr", "result", "scan_fail", 0L);
                Dialogs.onQRFail(this);
            }
        } else if (resultCode == RESULT_CANCELED) {
            tracker.sendEvent("qr", "result", "scan_canceled", 0L);
        }
    }
}

From source file:org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorUtils.java

/**
 * Convert a primitive object to double.
 *//* w  ww .j a  va  2  s.c  o m*/
public static double convertPrimitiveToDouble(Object o, PrimitiveObjectInspector oi) {
    switch (oi.getPrimitiveCategory()) {
    case BOOLEAN:
        return ((BooleanObjectInspector) oi).get(o) ? 1 : 0;
    case BYTE:
        return ((ByteObjectInspector) oi).get(o);
    case SHORT:
        return ((ShortObjectInspector) oi).get(o);
    case INT:
        return ((IntObjectInspector) oi).get(o);
    case LONG:
        return ((LongObjectInspector) oi).get(o);
    case FLOAT:
        return ((FloatObjectInspector) oi).get(o);
    case DOUBLE:
        return ((DoubleObjectInspector) oi).get(o);
    case STRING:
        return Double.valueOf(((StringObjectInspector) oi).getPrimitiveJavaObject(o));
    case TIMESTAMP:
        return ((TimestampObjectInspector) oi).getPrimitiveWritableObject(o).getDouble();
    case DECIMAL:
        return ((HiveDecimalObjectInspector) oi).getPrimitiveJavaObject(o).doubleValue();
    case DATE: // unsupported conversion
    default:
        throw new NumberFormatException();
    }
}

From source file:dhbw.ka.mwi.businesshorizon2.ui.process.parameter.ParameterPresenter.java

/**
 * Methode die sich nach der Auswahl der Iteration um die davon abhaengigen
 * Objekte kuemmert.  Konkret wird aus dem String des
 * Eingabefelds der Integer-Wert gezogen und geprueft ob der eingegebene
 * Wert groesser 1990 ist. Ist einer der beiden Kriterien nicht erfuellt wird
 * eine ClassCastException geworfen, die zu einer Fehlermeldung auf der
 * Benutzeroberflaecher fuehrt.//  w ww  . j a v a  2 s .c o  m
 * 
 * 
 * @author Christian Scherer
 * @param iterations
 *            Anzahl der ausgewaehlten Wiederholungen(Iterationen)
 */
public void iterationChosen(String iterationsString) {

    int iterations;
    try {
        iterations = Integer.parseInt(iterationsString);
        if (iterations >= 1000 && iterations <= 100000) {
            iterationsValid = true;
            getView().setComponentError(false, "iterations", "");
            this.projectProxy.getSelectedProject().setIterations(iterations);
            logger.debug(
                    "Iterationen in Objekten gesetzt: " + this.projectProxy.getSelectedProject().getName());

        } else {
            throw new NumberFormatException();
        }
    } catch (NumberFormatException nfe) {
        iterationsValid = false;
        getView().setComponentError(true, "iterations", errorMessageIterations);
        getView().showErrorMessage(errorMessageIterations);
        logger.debug("Keine gueltige Eingabe in Feld 'Wiederholungen'");
    }

    eventBus.fireEvent(new ValidateContentStateEvent());
}

From source file:org.kchine.rpf.PoolUtils.java

public static final byte[] hexToBytes(String s) throws NumberFormatException, IndexOutOfBoundsException {
    int slen = s.length();
    if ((slen % 2) != 0) {
        s = '0' + s;
    }/*from   ww w .j  a  v a 2 s  .c o  m*/

    byte[] out = new byte[slen / 2];

    byte b1, b2;
    for (int i = 0; i < slen; i += 2) {
        b1 = (byte) Character.digit(s.charAt(i), 16);
        b2 = (byte) Character.digit(s.charAt(i + 1), 16);
        if ((b1 < 0) || (b2 < 0)) {
            throw new NumberFormatException();
        }
        out[i / 2] = (byte) (b1 << 4 | b2);
    }
    return out;
}

From source file:dhbw.ka.mwi.businesshorizon2.ui.process.parameter.ParameterPresenter.java

/**
 * Methode die sich nach der Auswahl der zu Vorherzusagenden Perioden um die
 * davon abhaengigen Objekte kuemmert. Konkret wird aus dem String des
 * Eingabefelds der Integer-Wert gezogen und geprueft ob der eingegebene
 * Wert groesser 0 ist. Ist einer der beiden Kriterien nicht erfuellt wird
 * eine ClassCastException geworfen, die zu einer Fehlermeldung auf der
 * Benutzeroberflaecher fuehrt./*from  w  ww .  j  ava2  s .  co  m*/
 * 
 * @author Christian Scherer
 * @param numberPeriodsToForecast
 *            Anzahl der Perioden die in die Vorhergesagt werden sollen
 */
public void numberPeriodsToForecastChosen(String periodsToForecast) {
    logger.debug("Anwender-Eingabe zu Perioden die vorherzusagen sind");

    int periodsToForecastInt;
    try {
        periodsToForecastInt = Integer.parseInt(periodsToForecast);
        if (periodsToForecastInt > 0) {
            periodsToForecastValid = true;
            getView().setComponentError(false, "periodsToForecast", "");
            this.projectProxy.getSelectedProject().setPeriodsToForecast(periodsToForecastInt);
            logger.debug("Anzahl Perioden die vorherzusagen sind in das Projekt-Objekten gesetzt");
        } else {
            throw new NumberFormatException();
        }
    } catch (NumberFormatException nfe) {
        periodsToForecastValid = false;
        getView().setComponentError(true, "periodsToForecast", errorMessagePeriodsToForecast);
        getView().showErrorMessage(errorMessagePeriodsToForecast);
        logger.debug("Keine gueltige Eingabe in Feld 'Anzahl zu prognostizierender Perioden'");
    }

    eventBus.fireEvent(new ValidateContentStateEvent());
}