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:org.apache.hadoop.dfs.Balancer.java

private double parseArgs(String[] args) {
    double threshold = 0;
    int argsLen = (args == null) ? 0 : args.length;
    if (argsLen == 0) {
        threshold = 10;/*from  ww  w.j  a  v a2  s .c  om*/
    } else {
        if (argsLen != 2 || !"-threshold".equalsIgnoreCase(args[0])) {
            printUsage();
            throw new IllegalArgumentException(Arrays.toString(args));
        } else {
            try {
                threshold = Double.parseDouble(args[1]);
                if (threshold < 0 || threshold > 100) {
                    throw new NumberFormatException();
                }
                LOG.info("Using a threshold of " + threshold);
            } catch (NumberFormatException e) {
                System.err.println("Expect a double parameter in the range of [0, 100]: " + args[1]);
                printUsage();
                throw e;
            }
        }
    }
    return threshold;
}

From source file:vinci.project2.pkg1.View.java

/**
 * Assigns all jTextFields to their respective variables
 *//*  w  w  w .  j  av  a 2  s.c  o  m*/
private void getVars() {
    String ageTest = ageField.getText();

    try {
        if ("".equals(ageTest)) {
            throw new NumberFormatException();
        }
        age = Integer.parseInt(ageField.getText());
        ageOG = age;
        capRateGains = Double.parseDouble(capRateGainsField.getText());
        iTax = Double.parseDouble(iTaxField.getText());
        retAge = Integer.parseInt(retAgeField.getText());
        preCont = Double.parseDouble(preContField.getText());
        postCont = Double.parseDouble(postContField.getText());
        ror = Double.parseDouble(rorField.getText());
        preBal = Double.parseDouble(preBalField.getText());
        postBal = Double.parseDouble(postBalField.getText());
    } catch (NumberFormatException e) {
    }
}

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

/**
 * Methode die sich nach der Auswahl der Schrittgroesse fuer die Cashflows
 * kuemmert. Konkret wird aus dem String des Eingabefelds der Double-Wert
 * gezogen und geprueft ob dieser groesser 0 ist. Falls nicht wird eine
 * ClassCastException geworfen, die eine Fehlermeldung auf der
 * Benutzeroberflaecher angezeigt und ein ComponentError generiert.
 * //  ww  w . j ava2s. c o m
 * @author Christian Scherer
 * @param cashFlowStepRangeString
 *            Schrittgre der Cashflows fuer die RandomWalk Methode
 */
public void cashFlowStepRangeChosen(String cashFlowStepRangeString) {
    logger.debug("Anwender-Eingabe zu Schrittweite Cashflow");

    try {
        cashFlowStepRange = Double.parseDouble(cashFlowStepRangeString);
        if (cashFlowStepRange >= 0) {
            cashFlowStepRangeValid = true;
            getView().setComponentError(false, "cashFlowStepRange", "");
            this.projectProxy.getSelectedProject().setCashFlowStepRange(this.cashFlowStepRange);
            logger.debug("Schrittweite des Cashflows in das Projekt-Objekten gesetzt");
        } else {
            throw new NumberFormatException();
        }
    } catch (NumberFormatException nfe) {
        cashFlowStepRangeValid = false;
        getView().setComponentError(true, "cashFlowStepRange", errorMessageCashFlowStepRange);
        getView().showErrorMessage(errorMessageCashFlowStepRange);
        logger.debug("Keine gueltige Eingabe in Feld 'Schrittweite Cashflows'");
    }

    eventBus.fireEvent(new ValidateContentStateEvent());
}

From source file:org.shampoo.goldenembed.parser.GoldenEmbedParserMain.java

private long parseTimeStamp(byte[] timeStamp, GoldenCheetah gc) throws NumberFormatException {

    Calendar cal = new GregorianCalendar();

    try {/*from  ww w. java 2s  . c om*/

        int year = 0;
        int month = 0;
        int day = 0;

        int hour;
        int min;
        int sec;
        int i = 0;

        if (isGPS) {
            year = new Byte(timeStamp[i++]);
            month = new Byte(timeStamp[i++]);
            day = new Byte(timeStamp[i++]);
        }

        if (year >= 0 && year <= 99 && month >= 0 && month <= 12 && day >= 0 && day <= 31) {
            hour = new Byte(timeStamp[i++]);
            min = new Byte(timeStamp[i++]);
            sec = new Byte(timeStamp[i++]);

            year += 2000;
        } else
            throw new NumberFormatException();

        if (hour <= 24 && hour >= 0 && min <= 60 && min >= 0 && sec <= 60 && sec >= 0) {

            cal.set(year, --month, day, hour, min, sec);
            gc.setCurrentTime(cal);
        } else
            throw new NumberFormatException();

        long totalSecs = cal.getTimeInMillis() / 1000;

        if (firstRecordedTime == 0)
            firstRecordedTime = totalSecs;

        return totalSecs - firstRecordedTime;

    } catch (NumberFormatException e) {
        throw new NumberFormatException();

    }

}

From source file:org.apache.cassandra.config.DatabaseDescriptor.java

public static void applyConfig(Config config) throws ConfigurationException {
    conf = config;/*from   w  w  w .j av  a2s. c  o m*/

    if (conf.commitlog_sync == null) {
        throw new ConfigurationException("Missing required directive CommitLogSync", false);
    }

    if (conf.commitlog_sync == Config.CommitLogSync.batch) {
        if (conf.commitlog_sync_batch_window_in_ms == null) {
            throw new ConfigurationException(
                    "Missing value for commitlog_sync_batch_window_in_ms: Double expected.", false);
        } else if (conf.commitlog_sync_period_in_ms != null) {
            throw new ConfigurationException(
                    "Batch sync specified, but commitlog_sync_period_in_ms found. Only specify commitlog_sync_batch_window_in_ms when using batch sync",
                    false);
        }
        logger.debug("Syncing log with a batch window of {}", conf.commitlog_sync_batch_window_in_ms);
    } else {
        if (conf.commitlog_sync_period_in_ms == null) {
            throw new ConfigurationException("Missing value for commitlog_sync_period_in_ms: Integer expected",
                    false);
        } else if (conf.commitlog_sync_batch_window_in_ms != null) {
            throw new ConfigurationException(
                    "commitlog_sync_period_in_ms specified, but commitlog_sync_batch_window_in_ms found.  Only specify commitlog_sync_period_in_ms when using periodic sync.",
                    false);
        }
        logger.debug("Syncing log with a period of {}", conf.commitlog_sync_period_in_ms);
    }

    /* evaluate the DiskAccessMode Config directive, which also affects indexAccessMode selection */
    if (conf.disk_access_mode == Config.DiskAccessMode.auto) {
        conf.disk_access_mode = hasLargeAddressSpace() ? Config.DiskAccessMode.mmap
                : Config.DiskAccessMode.standard;
        indexAccessMode = conf.disk_access_mode;
        logger.info("DiskAccessMode 'auto' determined to be {}, indexAccessMode is {}", conf.disk_access_mode,
                indexAccessMode);
    } else if (conf.disk_access_mode == Config.DiskAccessMode.mmap_index_only) {
        conf.disk_access_mode = Config.DiskAccessMode.standard;
        indexAccessMode = Config.DiskAccessMode.mmap;
        logger.info("DiskAccessMode is {}, indexAccessMode is {}", conf.disk_access_mode, indexAccessMode);
    } else {
        indexAccessMode = conf.disk_access_mode;
        logger.info("DiskAccessMode is {}, indexAccessMode is {}", conf.disk_access_mode, indexAccessMode);
    }

    /* Authentication, authorization and role management backend, implementing IAuthenticator, IAuthorizer & IRoleMapper*/
    if (conf.authenticator != null)
        authenticator = FBUtilities.newAuthenticator(conf.authenticator);

    // the configuration options regarding credentials caching are only guaranteed to
    // work with PasswordAuthenticator, so log a message if some other authenticator
    // is in use and non-default values are detected
    if (!(authenticator instanceof PasswordAuthenticator) && (conf.credentials_update_interval_in_ms != -1
            || conf.credentials_validity_in_ms != 2000 || conf.credentials_cache_max_entries != 1000)) {
        logger.info("Configuration options credentials_update_interval_in_ms, credentials_validity_in_ms and "
                + "credentials_cache_max_entries may not be applicable for the configured authenticator ({})",
                authenticator.getClass().getName());
    }

    if (conf.authorizer != null)
        authorizer = FBUtilities.newAuthorizer(conf.authorizer);

    if (!authenticator.requireAuthentication() && authorizer.requireAuthorization())
        throw new ConfigurationException(conf.authenticator + " can't be used with " + conf.authorizer, false);

    if (conf.role_manager != null)
        roleManager = FBUtilities.newRoleManager(conf.role_manager);
    else
        roleManager = new CassandraRoleManager();

    if (authenticator instanceof PasswordAuthenticator && !(roleManager instanceof CassandraRoleManager))
        throw new ConfigurationException("CassandraRoleManager must be used with PasswordAuthenticator", false);

    if (conf.internode_authenticator != null)
        internodeAuthenticator = FBUtilities.construct(conf.internode_authenticator, "internode_authenticator");
    else
        internodeAuthenticator = new AllowAllInternodeAuthenticator();

    authenticator.validateConfiguration();
    authorizer.validateConfiguration();
    roleManager.validateConfiguration();
    internodeAuthenticator.validateConfiguration();

    /* Hashing strategy */
    if (conf.partitioner == null) {
        throw new ConfigurationException("Missing directive: partitioner", false);
    }
    try {
        partitioner = FBUtilities.newPartitioner(System.getProperty("cassandra.partitioner", conf.partitioner));
    } catch (Exception e) {
        throw new ConfigurationException("Invalid partitioner class " + conf.partitioner, false);
    }
    paritionerName = partitioner.getClass().getCanonicalName();

    if (config.gc_log_threshold_in_ms < 0) {
        throw new ConfigurationException("gc_log_threshold_in_ms must be a positive integer");
    }

    if (conf.gc_warn_threshold_in_ms < 0) {
        throw new ConfigurationException("gc_warn_threshold_in_ms must be a positive integer");
    }

    if (conf.max_hint_window_in_ms == null) {
        throw new ConfigurationException("max_hint_window_in_ms cannot be set to null", false);
    }

    /* phi convict threshold for FailureDetector */
    if (conf.phi_convict_threshold < 5 || conf.phi_convict_threshold > 16) {
        throw new ConfigurationException(
                "phi_convict_threshold must be between 5 and 16, but was " + conf.phi_convict_threshold, false);
    }

    /* Thread per pool */
    if (conf.concurrent_reads != null && conf.concurrent_reads < 2) {
        throw new ConfigurationException(
                "concurrent_reads must be at least 2, but was " + conf.concurrent_reads, false);
    }

    if (conf.concurrent_writes != null && conf.concurrent_writes < 2) {
        throw new ConfigurationException(
                "concurrent_writes must be at least 2, but was " + conf.concurrent_writes, false);
    }

    if (conf.concurrent_counter_writes != null && conf.concurrent_counter_writes < 2)
        throw new ConfigurationException(
                "concurrent_counter_writes must be at least 2, but was " + conf.concurrent_counter_writes,
                false);

    if (conf.concurrent_replicates != null)
        logger.warn("concurrent_replicates has been deprecated and should be removed from cassandra.yaml");

    if (conf.file_cache_size_in_mb == null)
        conf.file_cache_size_in_mb = Math.min(512, (int) (Runtime.getRuntime().maxMemory() / (4 * 1048576)));

    if (conf.memtable_offheap_space_in_mb == null)
        conf.memtable_offheap_space_in_mb = (int) (Runtime.getRuntime().maxMemory() / (4 * 1048576));
    if (conf.memtable_offheap_space_in_mb < 0)
        throw new ConfigurationException(
                "memtable_offheap_space_in_mb must be positive, but was " + conf.memtable_offheap_space_in_mb,
                false);
    // for the moment, we default to twice as much on-heap space as off-heap, as heap overhead is very large
    if (conf.memtable_heap_space_in_mb == null)
        conf.memtable_heap_space_in_mb = (int) (Runtime.getRuntime().maxMemory() / (4 * 1048576));
    if (conf.memtable_heap_space_in_mb <= 0)
        throw new ConfigurationException(
                "memtable_heap_space_in_mb must be positive, but was " + conf.memtable_heap_space_in_mb, false);
    logger.info("Global memtable on-heap threshold is enabled at {}MB", conf.memtable_heap_space_in_mb);
    if (conf.memtable_offheap_space_in_mb == 0)
        logger.info("Global memtable off-heap threshold is disabled, HeapAllocator will be used instead");
    else
        logger.info("Global memtable off-heap threshold is enabled at {}MB", conf.memtable_offheap_space_in_mb);

    applyAddressConfig(config);

    if (conf.thrift_framed_transport_size_in_mb <= 0)
        throw new ConfigurationException("thrift_framed_transport_size_in_mb must be positive, but was "
                + conf.thrift_framed_transport_size_in_mb, false);

    if (conf.native_transport_max_frame_size_in_mb <= 0)
        throw new ConfigurationException("native_transport_max_frame_size_in_mb must be positive, but was "
                + conf.native_transport_max_frame_size_in_mb, false);

    // fail early instead of OOMing (see CASSANDRA-8116)
    if (ThriftServer.HSHA.equals(conf.rpc_server_type) && conf.rpc_max_threads == Integer.MAX_VALUE)
        throw new ConfigurationException("The hsha rpc_server_type is not compatible with an rpc_max_threads "
                + "setting of 'unlimited'.  Please see the comments in cassandra.yaml "
                + "for rpc_server_type and rpc_max_threads.", false);
    if (ThriftServer.HSHA.equals(conf.rpc_server_type)
            && conf.rpc_max_threads > (FBUtilities.getAvailableProcessors() * 2 + 1024))
        logger.warn(
                "rpc_max_threads setting of {} may be too high for the hsha server and cause unnecessary thread contention, reducing performance",
                conf.rpc_max_threads);

    /* end point snitch */
    if (conf.endpoint_snitch == null) {
        throw new ConfigurationException("Missing endpoint_snitch directive", false);
    }
    snitch = createEndpointSnitch(conf.endpoint_snitch);
    EndpointSnitchInfo.create();

    localDC = snitch.getDatacenter(FBUtilities.getBroadcastAddress());
    localComparator = new Comparator<InetAddress>() {
        public int compare(InetAddress endpoint1, InetAddress endpoint2) {
            boolean local1 = localDC.equals(snitch.getDatacenter(endpoint1));
            boolean local2 = localDC.equals(snitch.getDatacenter(endpoint2));
            if (local1 && !local2)
                return -1;
            if (local2 && !local1)
                return 1;
            return 0;
        }
    };

    /* Request Scheduler setup */
    requestSchedulerOptions = conf.request_scheduler_options;
    if (conf.request_scheduler != null) {
        try {
            if (requestSchedulerOptions == null) {
                requestSchedulerOptions = new RequestSchedulerOptions();
            }
            Class<?> cls = Class.forName(conf.request_scheduler);
            requestScheduler = (IRequestScheduler) cls.getConstructor(RequestSchedulerOptions.class)
                    .newInstance(requestSchedulerOptions);
        } catch (ClassNotFoundException e) {
            throw new ConfigurationException("Invalid Request Scheduler class " + conf.request_scheduler,
                    false);
        } catch (Exception e) {
            throw new ConfigurationException("Unable to instantiate request scheduler", e);
        }
    } else {
        requestScheduler = new NoScheduler();
    }

    if (conf.request_scheduler_id == RequestSchedulerId.keyspace) {
        requestSchedulerId = conf.request_scheduler_id;
    } else {
        // Default to Keyspace
        requestSchedulerId = RequestSchedulerId.keyspace;
    }

    // if data dirs, commitlog dir, or saved caches dir are set in cassandra.yaml, use that.  Otherwise,
    // use -Dcassandra.storagedir (set in cassandra-env.sh) as the parent dir for data/, commitlog/, and saved_caches/
    if (conf.commitlog_directory == null) {
        conf.commitlog_directory = System.getProperty("cassandra.storagedir", null);
        if (conf.commitlog_directory == null)
            throw new ConfigurationException(
                    "commitlog_directory is missing and -Dcassandra.storagedir is not set", false);
        conf.commitlog_directory += File.separator + "commitlog";
    }

    if (conf.hints_directory == null) {
        conf.hints_directory = System.getProperty("cassandra.storagedir", null);
        if (conf.hints_directory == null)
            throw new ConfigurationException("hints_directory is missing and -Dcassandra.storagedir is not set",
                    false);
        conf.hints_directory += File.separator + "hints";
    }

    if (conf.cdc_raw_directory == null) {
        conf.cdc_raw_directory = System.getProperty("cassandra.storagedir", null);
        if (conf.cdc_raw_directory == null)
            throw new ConfigurationException(
                    "cdc_raw_directory is missing and -Dcassandra.storagedir is not set", false);
        conf.cdc_raw_directory += File.separator + "cdc_raw";
    }

    if (conf.commitlog_total_space_in_mb == null) {
        int preferredSize = 8192;
        int minSize = 0;
        try {
            // use 1/4 of available space.  See discussion on #10013 and #10199
            minSize = Ints
                    .checkedCast((guessFileStore(conf.commitlog_directory).getTotalSpace() / 1048576) / 4);
        } catch (IOException e) {
            logger.debug("Error checking disk space", e);
            throw new ConfigurationException(String.format(
                    "Unable to check disk space available to %s. Perhaps the Cassandra user does not have the necessary permissions",
                    conf.commitlog_directory), e);
        }
        if (minSize < preferredSize) {
            logger.warn(
                    "Small commitlog volume detected at {}; setting commitlog_total_space_in_mb to {}.  You can override this in cassandra.yaml",
                    conf.commitlog_directory, minSize);
            conf.commitlog_total_space_in_mb = minSize;
        } else {
            conf.commitlog_total_space_in_mb = preferredSize;
        }
    }

    if (conf.cdc_total_space_in_mb == null) {
        int preferredSize = 4096;
        int minSize = 0;
        try {
            // use 1/8th of available space.  See discussion on #10013 and #10199 on the CL, taking half that for CDC
            minSize = Ints.checkedCast((guessFileStore(conf.cdc_raw_directory).getTotalSpace() / 1048576) / 8);
        } catch (IOException e) {
            logger.debug("Error checking disk space", e);
            throw new ConfigurationException(String.format(
                    "Unable to check disk space available to %s. Perhaps the Cassandra user does not have the necessary permissions",
                    conf.cdc_raw_directory), e);
        }
        if (minSize < preferredSize) {
            logger.warn(
                    "Small cdc volume detected at {}; setting cdc_total_space_in_mb to {}.  You can override this in cassandra.yaml",
                    conf.cdc_raw_directory, minSize);
            conf.cdc_total_space_in_mb = minSize;
        } else {
            conf.cdc_total_space_in_mb = preferredSize;
        }
    }

    if (conf.cdc_enabled == true) {
        logger.info("cdc_enabled is true. Starting casssandra node with Change-Data-Capture enabled.");
    }

    if (conf.saved_caches_directory == null) {
        conf.saved_caches_directory = System.getProperty("cassandra.storagedir", null);
        if (conf.saved_caches_directory == null)
            throw new ConfigurationException(
                    "saved_caches_directory is missing and -Dcassandra.storagedir is not set", false);
        conf.saved_caches_directory += File.separator + "saved_caches";
    }
    if (conf.data_file_directories == null || conf.data_file_directories.length == 0) {
        String defaultDataDir = System.getProperty("cassandra.storagedir", null);
        if (defaultDataDir == null)
            throw new ConfigurationException(
                    "data_file_directories is not missing and -Dcassandra.storagedir is not set", false);
        conf.data_file_directories = new String[] { defaultDataDir + File.separator + "data" };
    }

    long dataFreeBytes = 0;
    /* data file and commit log directories. they get created later, when they're needed. */
    for (String datadir : conf.data_file_directories) {
        if (datadir.equals(conf.commitlog_directory))
            throw new ConfigurationException(
                    "commitlog_directory must not be the same as any data_file_directories", false);
        if (datadir.equals(conf.hints_directory))
            throw new ConfigurationException(
                    "hints_directory must not be the same as any data_file_directories", false);
        if (datadir.equals(conf.saved_caches_directory))
            throw new ConfigurationException(
                    "saved_caches_directory must not be the same as any data_file_directories", false);

        try {
            dataFreeBytes += guessFileStore(datadir).getUnallocatedSpace();
        } catch (IOException e) {
            logger.debug("Error checking disk space", e);
            throw new ConfigurationException(String.format(
                    "Unable to check disk space available to %s. Perhaps the Cassandra user does not have the necessary permissions",
                    datadir), e);
        }
    }
    if (dataFreeBytes < 64L * 1024 * 1048576) // 64 GB
        logger.warn(
                "Only {} free across all data volumes. Consider adding more capacity to your cluster or removing obsolete snapshots",
                FBUtilities.prettyPrintMemory(dataFreeBytes));

    if (conf.commitlog_directory.equals(conf.saved_caches_directory))
        throw new ConfigurationException(
                "saved_caches_directory must not be the same as the commitlog_directory", false);
    if (conf.commitlog_directory.equals(conf.hints_directory))
        throw new ConfigurationException("hints_directory must not be the same as the commitlog_directory",
                false);
    if (conf.hints_directory.equals(conf.saved_caches_directory))
        throw new ConfigurationException("saved_caches_directory must not be the same as the hints_directory",
                false);

    if (conf.memtable_flush_writers < 1)
        throw new ConfigurationException(
                "memtable_flush_writers must be at least 1, but was " + conf.memtable_flush_writers, false);

    if (conf.memtable_cleanup_threshold == null)
        conf.memtable_cleanup_threshold = (float) (1.0 / (1 + conf.memtable_flush_writers));

    if (conf.memtable_cleanup_threshold < 0.01f)
        throw new ConfigurationException(
                "memtable_cleanup_threshold must be >= 0.01, but was " + conf.memtable_cleanup_threshold,
                false);
    if (conf.memtable_cleanup_threshold > 0.99f)
        throw new ConfigurationException(
                "memtable_cleanup_threshold must be <= 0.99, but was " + conf.memtable_cleanup_threshold,
                false);
    if (conf.memtable_cleanup_threshold < 0.1f)
        logger.warn("memtable_cleanup_threshold is set very low [{}], which may cause performance degradation",
                conf.memtable_cleanup_threshold);

    if (conf.concurrent_compactors == null)
        conf.concurrent_compactors = Math.min(8,
                Math.max(2, Math.min(FBUtilities.getAvailableProcessors(), conf.data_file_directories.length)));

    if (conf.concurrent_compactors <= 0)
        throw new ConfigurationException("concurrent_compactors should be strictly greater than 0, but was "
                + conf.concurrent_compactors, false);

    if (conf.num_tokens == null)
        conf.num_tokens = 1;
    else if (conf.num_tokens > MAX_NUM_TOKENS)
        throw new ConfigurationException(
                String.format("A maximum number of %d tokens per node is supported", MAX_NUM_TOKENS), false);

    if (conf.initial_token != null) {
        Collection<String> tokens = tokensFromString(conf.initial_token);
        if (tokens.size() != conf.num_tokens)
            throw new ConfigurationException(
                    "The number of initial tokens (by initial_token) specified is different from num_tokens value",
                    false);

        for (String token : tokens)
            partitioner.getTokenFactory().validate(token);
    }

    try {
        // if prepared_statements_cache_size_mb option was set to "auto" then size of the cache should be "max(1/256 of Heap (in MB), 10MB)"
        preparedStatementsCacheSizeInMB = (conf.prepared_statements_cache_size_mb == null)
                ? Math.max(10, (int) (Runtime.getRuntime().maxMemory() / 1024 / 1024 / 256))
                : conf.prepared_statements_cache_size_mb;

        if (preparedStatementsCacheSizeInMB <= 0)
            throw new NumberFormatException(); // to escape duplicating error message
    } catch (NumberFormatException e) {
        throw new ConfigurationException(
                "prepared_statements_cache_size_mb option was set incorrectly to '"
                        + conf.prepared_statements_cache_size_mb + "', supported values are <integer> >= 0.",
                false);
    }

    try {
        // if thrift_prepared_statements_cache_size_mb option was set to "auto" then size of the cache should be "max(1/256 of Heap (in MB), 10MB)"
        thriftPreparedStatementsCacheSizeInMB = (conf.thrift_prepared_statements_cache_size_mb == null)
                ? Math.max(10, (int) (Runtime.getRuntime().maxMemory() / 1024 / 1024 / 256))
                : conf.thrift_prepared_statements_cache_size_mb;

        if (thriftPreparedStatementsCacheSizeInMB <= 0)
            throw new NumberFormatException(); // to escape duplicating error message
    } catch (NumberFormatException e) {
        throw new ConfigurationException(
                "thrift_prepared_statements_cache_size_mb option was set incorrectly to '"
                        + conf.thrift_prepared_statements_cache_size_mb
                        + "', supported values are <integer> >= 0.",
                false);
    }

    try {
        // if key_cache_size_in_mb option was set to "auto" then size of the cache should be "min(5% of Heap (in MB), 100MB)
        keyCacheSizeInMB = (conf.key_cache_size_in_mb == null)
                ? Math.min(Math.max(1, (int) (Runtime.getRuntime().totalMemory() * 0.05 / 1024 / 1024)), 100)
                : conf.key_cache_size_in_mb;

        if (keyCacheSizeInMB < 0)
            throw new NumberFormatException(); // to escape duplicating error message
    } catch (NumberFormatException e) {
        throw new ConfigurationException("key_cache_size_in_mb option was set incorrectly to '"
                + conf.key_cache_size_in_mb + "', supported values are <integer> >= 0.", false);
    }

    try {
        // if counter_cache_size_in_mb option was set to "auto" then size of the cache should be "min(2.5% of Heap (in MB), 50MB)
        counterCacheSizeInMB = (conf.counter_cache_size_in_mb == null)
                ? Math.min(Math.max(1, (int) (Runtime.getRuntime().totalMemory() * 0.025 / 1024 / 1024)), 50)
                : conf.counter_cache_size_in_mb;

        if (counterCacheSizeInMB < 0)
            throw new NumberFormatException(); // to escape duplicating error message
    } catch (NumberFormatException e) {
        throw new ConfigurationException("counter_cache_size_in_mb option was set incorrectly to '"
                + conf.counter_cache_size_in_mb + "', supported values are <integer> >= 0.", false);
    }

    // if set to empty/"auto" then use 5% of Heap size
    indexSummaryCapacityInMB = (conf.index_summary_capacity_in_mb == null)
            ? Math.max(1, (int) (Runtime.getRuntime().totalMemory() * 0.05 / 1024 / 1024))
            : conf.index_summary_capacity_in_mb;

    if (indexSummaryCapacityInMB < 0)
        throw new ConfigurationException("index_summary_capacity_in_mb option was set incorrectly to '"
                + conf.index_summary_capacity_in_mb + "', it should be a non-negative integer.", false);

    if (conf.encryption_options != null) {
        logger.warn("Please rename encryption_options as server_encryption_options in the yaml");
        //operate under the assumption that server_encryption_options is not set in yaml rather than both
        conf.server_encryption_options = conf.encryption_options;
    }

    // load the seeds for node contact points
    if (conf.seed_provider == null) {
        throw new ConfigurationException("seeds configuration is missing; a minimum of one seed is required.",
                false);
    }
    try {
        Class<?> seedProviderClass = Class.forName(conf.seed_provider.class_name);
        seedProvider = (SeedProvider) seedProviderClass.getConstructor(Map.class)
                .newInstance(conf.seed_provider.parameters);
    }
    // there are about 5 checked exceptions that could be thrown here.
    catch (Exception e) {
        throw new ConfigurationException(
                e.getMessage()
                        + "\nFatal configuration error; unable to start server.  See log for stacktrace.",
                true);
    }
    if (seedProvider.getSeeds().size() == 0)
        throw new ConfigurationException("The seed provider lists no seeds.", false);

    if (conf.user_defined_function_fail_timeout < 0)
        throw new ConfigurationException("user_defined_function_fail_timeout must not be negative", false);
    if (conf.user_defined_function_warn_timeout < 0)
        throw new ConfigurationException("user_defined_function_warn_timeout must not be negative", false);

    if (conf.user_defined_function_fail_timeout < conf.user_defined_function_warn_timeout)
        throw new ConfigurationException(
                "user_defined_function_warn_timeout must less than user_defined_function_fail_timeout", false);

    // always attempt to load the cipher factory, as we could be in the situation where the user has disabled encryption,
    // but has existing commitlogs and sstables on disk that are still encrypted (and still need to be read)
    encryptionContext = new EncryptionContext(config.transparent_data_encryption_options);

    if (conf.max_mutation_size_in_kb == null)
        conf.max_mutation_size_in_kb = conf.commitlog_segment_size_in_mb * 1024 / 2;
    else if (conf.commitlog_segment_size_in_mb * 1024 < 2 * conf.max_mutation_size_in_kb)
        throw new ConfigurationException(
                "commitlog_segment_size_in_mb must be at least twice the size of max_mutation_size_in_kb / 1024",
                false);

    // native transport encryption options
    if (conf.native_transport_port_ssl != null
            && conf.native_transport_port_ssl.intValue() != conf.native_transport_port.intValue()
            && !conf.client_encryption_options.enabled) {
        throw new ConfigurationException(
                "Encryption must be enabled in client_encryption_options for native_transport_port_ssl", false);
    }

    if (conf.max_value_size_in_mb == null || conf.max_value_size_in_mb <= 0)
        throw new ConfigurationException("max_value_size_in_mb must be positive", false);
}

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

/**
 * Methode die sich nach der Auswahl der Wahrscheinlichkeit fuer eine
 * positive Cashflows-Entwicklung kuemmert. Konkret wird aus dem String des
 * Eingabefelds der Double-Wert gezogen und geprueft ob der Wert zwischen 0
 * und 100 liegt. Vor der Uebergabe wird der uebergebene an das Project-Objekt
 * wird der Wert noch durch 100 geteilt, da die Rechenlogig mit einem 
 * Wert zwischen 0 und 1 arbeitet. Falls nicht wird eine ClassCastException 
 * geworfen, die eine Fehlermeldung auf der Benutzeroberflaecher angezeigt und ein
 * ComponentError generiert. //from w w w  .j  a v  a  2s  .co m
 * 
 * @author Christian Scherer
 * @param cashFlowProbabilityOfRiseString
 *            Wahrscheinlichkeit fuer eine positive Cashflows-Entwicklung
 *            fuer die RandomWalk Methode
 */
public void cashFlowProbabilityOfRiseChosen(String cashFlowProbabilityOfRiseString) {
    logger.debug("Anwender-Eingabe zu Wahrscheinlichkeit f\u00fcr steigende Cashflowentwicklung");

    try {
        cashFlowProbabilityOfRise = Double.parseDouble(cashFlowProbabilityOfRiseString);
        if (cashFlowProbabilityOfRise >= 0 && cashFlowProbabilityOfRise <= 100) {
            cashFlowProbabilityOfRiseValid = true;
            getView().setComponentError(false, "cashFlowProbabilityOfRise", "");
            this.projectProxy.getSelectedProject()
                    .setCashFlowProbabilityOfRise((this.cashFlowProbabilityOfRise / 100));
            logger.debug(
                    "Wahrscheinlichkeit f\u00fcr steigende Cashflowentwicklung in das Projekt-Objekten gesetzt");
        } else {
            throw new NumberFormatException();
        }
    } catch (NumberFormatException nfe) {
        cashFlowProbabilityOfRiseValid = false;
        getView().setComponentError(true, "cashFlowProbabilityOfRise", errorMessageCashFlowProbabilityOfRise);
        getView().showErrorMessage(errorMessageCashFlowProbabilityOfRise);
        logger.debug(
                "Keine gueltige Eingabe in Feld 'Wahrscheinlichkeit f\u00fcr steigende Cashflowentwicklung");
    }

    eventBus.fireEvent(new ValidateContentStateEvent());
}

From source file:edu.usc.scrc.PriorityPruner.CommandLineOptions.java

/**
 * Parses a String-argument to a long value and makes sure it's valid.
 * /*from w w w. jav  a 2  s  .co m*/
 * @param option
 *            name of the Option to which the argument belongs
 * @param argument
 *            String that will be parsed
 * @param min
 *            minimum value allowed for this parameter
 * @param max
 *            maximum value allowed for this parameter
 * @return a long value
 * @throws NumberFormatException
 *             if invalid String-argument were provided
 * @throws PriorityPrunerException
 *             if invalid String-argument were provided
 */
private long getLongArgument(String option, String argument, long min, long max)
        throws PriorityPrunerException {
    try {
        Long longValue = Long.parseLong(argument);
        if (longValue >= min && longValue <= max) {
            return longValue;
        } else {
            // exception gets thrown either if parsing is impossible or
            // values are out of range
            throw new NumberFormatException();
        }
    } catch (NumberFormatException e) {
        throw new PriorityPrunerException(argument + " is not a valid input for option " + option
                + ", please specify an integer value between " + min + " and " + max
                + ". For help type --help.");
    }
}

From source file:org.cimmyt.corehunter.textui.CorehunterTextRunner.java

private boolean parseOptions(String[] args) {
    CommandLineParser parser = new GnuParser();

    try {/*from   w w w . j a  v  a2  s. com*/
        CommandLine cl = parser.parse(opts, args);

        // check for -help
        if (cl.hasOption("help")) {
            showUsage();
            System.exit(0);
        }

        // check for -version
        if (cl.hasOption("version")) {
            showVersion();
            System.exit(0);
        }

        // make sure two required args are present
        if (cl.getArgs().length != 2) {
            System.err.println("\n2 required arguments expected");
            return false;
        }

        // grab the filenames
        collectionFile = cl.getArgs()[0];
        coresubsetFile = cl.getArgs()[1];

        // parse the weights for different measures
        boolean hasMeasures = false;
        for (int i = 0; i < measureNames.length; i++) {
            String m = measureNames[i];
            if (cl.hasOption(m)) {
                try {
                    double weight = Double.parseDouble(cl.getOptionValue(m));
                    if (weight <= 0.0)
                        throw new NumberFormatException();
                    measureWeights.put(m, weight);
                } catch (NumberFormatException nfe) {
                    System.err.println("\nweight for " + measureNames[i] + " must be a positive numeric value");
                    return false;
                }
                hasMeasures = true;
            }
        }

        // ensure at least one measure was set
        if (!hasMeasures) {
            System.err.println("\nAt least one measure must be specified");
            return false;
        }

        // check if specific core size ranges were set
        if (cl.hasOption("sample_size")) {
            try {
                sampleMin = Integer.parseInt(cl.getOptionValues("sample_size")[0]);
                sampleMax = Integer.parseInt(cl.getOptionValues("sample_size")[1]);
                if (sampleMin > sampleMax || sampleMin < 2)
                    throw new NumberFormatException();
                sampleSizesSpecified = true;
            } catch (NumberFormatException nfe) {
                System.err
                        .println("\nsample_size must specify two integer values with max >= min and min >= 2");
                return false;
            }
        }

        // make sure sampling intensity is between 0 and 1 inclusive
        if (cl.hasOption("sample_intensity")) {
            try {
                sampleIntensity = Double.parseDouble(cl.getOptionValue("sample_intensity"));
                if (sampleIntensity < 0.0 || sampleIntensity > 1.0) {
                    throw new NumberFormatException();
                }
            } catch (NumberFormatException nfe) {
                System.err.println("\nsample_intensity must a numeric value in the range [0..1]");
                return false;
            }
        }

        // check for runtime
        if (cl.hasOption("runtime")) {
            try {
                runtime = Double.parseDouble(cl.getOptionValue("runtime"));
                if (runtime <= 0.0)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nruntime must be a positive numeric value");
                return false;
            }
        }

        // check for min_prog
        if (cl.hasOption("min_prog")) {
            try {
                minProg = Double.parseDouble(cl.getOptionValue("min_prog"));
                if (minProg < 0.0)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nmin_prog must be a positive numeric value");
                return false;
            }
        }

        // check for stuck_time
        if (cl.hasOption("stuck_time")) {
            try {
                stuckTime = Double.parseDouble(cl.getOptionValue("stuck_time"));
                if (stuckTime <= 0.0)
                    throw new NumberFormatException();
                stuckTimeSpecified = true;
            } catch (NumberFormatException nfe) {
                System.err.println("\nstuck_time must be a positve numeric value");
                return false;
            }
        }

        // check selected search type

        int j = 0;

        // check for -remc
        remcSearch = cl.hasOption("remc");
        if (remcSearch)
            j++;

        // check for -premc
        parRemcSearch = cl.hasOption("premc");
        if (parRemcSearch)
            j++;

        // check for -exh
        exhSearch = cl.hasOption("exh");
        if (exhSearch)
            j++;

        // check for -rand
        randSearch = cl.hasOption("rand");
        if (randSearch)
            j++;

        // check for -tabu
        tabuSearch = cl.hasOption("tabu");
        if (tabuSearch)
            j++;

        // check for -local
        localSearch = cl.hasOption("local");
        if (localSearch)
            j++;

        // check for -steepest
        steepestDescentSearch = cl.hasOption("steepest");
        if (steepestDescentSearch)
            j++;

        // check for -mstrat
        mstratSearch = cl.hasOption("mstrat");
        if (mstratSearch)
            j++;

        // check for -genetic
        geneticSearch = cl.hasOption("genetic");
        if (geneticSearch)
            j++;

        // check for -mergerep
        mergeReplicaSearch = cl.hasOption("mergerep");
        if (mergeReplicaSearch)
            j++;

        // check for -pmergerep
        parMergeReplicaSearch = cl.hasOption("pmergerep");
        if (parMergeReplicaSearch)
            j++;

        // check for -mixrep
        mixedReplicaSearch = cl.hasOption("mixrep");
        if (mixedReplicaSearch)
            j++;

        // check for -lr
        lrSearch = cl.hasOption("lr");
        if (lrSearch)
            j++;

        // check for -semilr
        semiLrSearch = cl.hasOption("lrsemi");
        if (semiLrSearch)
            j++;

        // check for -sfs
        forwardSelection = cl.hasOption("sfs");
        if (forwardSelection)
            j++;

        // check for -sfssemi
        semiForwardSelection = cl.hasOption("sfssemi");
        if (semiForwardSelection)
            j++;

        // check for -sbs
        backwardSelection = cl.hasOption("sbs");
        if (backwardSelection)
            j++;

        // check if a search type is selected
        if (j == 0) {
            // select default search type = MixRep
            mixedReplicaSearch = true;
        } else if (j > 1) {
            // multiple search types selected
            System.err.println("\nMultiple search types selected. Please select only one.");
            return false;
        }

        // check REMC advanced options

        // check for replicas
        if (cl.hasOption("replicas")) {
            try {
                replicas = Integer.parseInt(cl.getOptionValue("replicas"));
                mergerepNrOfReplicas = replicas; // in case of Merge Replica Search
                if (replicas < 1 || replicas > 100)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nreplicas must be a positive integer in the range [1..100]");
                return false;
            }
        }

        // check for mc_steps
        if (cl.hasOption("mc_steps")) {
            try {
                mcSteps = Integer.parseInt(cl.getOptionValue("mc_steps"));
                mergerepNrOfSteps = mcSteps; // in case of Merge Replica Search
                if (mcSteps < 1 || mcSteps > 1000000)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nmc_steps must be a positive integer in the range [1..1000000]");
                return false;
            }
        }

        // check for min_t
        if (cl.hasOption("min_t")) {
            try {
                minT = Double.parseDouble(cl.getOptionValue("min_t"));
                mixrepMinSimAnTemp = minT; // in case of MixRep
                if (minT <= 0.0)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nmin_t must be a positve numeric value");
                return false;
            }
        }

        // check for max_t
        if (cl.hasOption("max_t")) {
            try {
                maxT = Double.parseDouble(cl.getOptionValue("max_t"));
                mixrepMaxSimAnTemp = maxT; // in case of MixRep
                if (maxT <= minT)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nmax_t must be a postive numeric value, larger than min_t");
                return false;
            }
        }

        // check Tabu advanced options

        // check for list_size
        if (cl.hasOption("list_size")) {
            try {
                tabuListSize = Integer.parseInt(cl.getOptionValue("list_size"));
                if (tabuListSize <= 0)
                    throw new NumberFormatException();
                tabuListSizeSpecified = true;
            } catch (NumberFormatException nfe) {
                System.err.println("\nlist_size must be a postive integer");
                return false;
            }
        }

        // check Genetic Algorithm advanced options

        // check for pop_size
        if (cl.hasOption("pop_size")) {
            try {
                genPopSize = Integer.parseInt(cl.getOptionValue("pop_size"));
                if (genPopSize < 2)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\npop_size must be a postive integer >= 2");
                return false;
            }
        }

        // check for children
        if (cl.hasOption("children")) {
            try {
                genNrOfChildren = Integer.parseInt(cl.getOptionValue("children"));
                mergerepNrOfChildren = genNrOfChildren; // in case of Merge Replica Search
                if (genNrOfChildren < 1)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nchildren must be a postive integer >= 1");
                return false;
            }
        }

        // check for tournament_size
        if (cl.hasOption("tournament_size")) {
            try {
                genTournamentSize = Integer.parseInt(cl.getOptionValue("tournament_size"));
                mergerepTournamentSize = genTournamentSize; // in case of Merge Replica Search
                mixrepTournamentSize = genTournamentSize; // in case of Mixed Replica Search
                if (genTournamentSize < 1)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\ntournament_size must be a postive integer >= 1");
                return false;
            }
        }

        // check for mutation_rate
        if (cl.hasOption("mutation_rate")) {
            try {
                genMutationRate = Double.parseDouble(cl.getOptionValue("mutation_rate"));
                if (genMutationRate < 0.0 || genMutationRate > 1.0)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nmutation_rate must be a real number between 0.0 and 1.0");
                return false;
            }
        }

        // check Genetic Replica Search advanced options

        // check for replicas --> see REMC

        // check for mc_steps --> see REMC

        // check for tournament_size --> see Genetic Algorithm

        // check for children --> see Genetic Algorithm

        // check Mixed Replica Search advanced options

        // check for tabu_replicas
        if (cl.hasOption("tabu_replicas")) {
            try {
                mixrepNrOfTabuReplicas = Integer.parseInt(cl.getOptionValue("tabu_replicas"));
                if (mixrepNrOfTabuReplicas < 1 || mixrepNrOfTabuReplicas > 100)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\ntabu_replicas must be a positive integer in the range [1..100]");
                return false;
            }
        }

        // check for non_tabu_replicas
        if (cl.hasOption("non_tabu_replicas")) {
            try {
                mixrepNrOfNonTabuReplicas = Integer.parseInt(cl.getOptionValue("non_tabu_replicas"));
                if (mixrepNrOfNonTabuReplicas < 1 || mixrepNrOfNonTabuReplicas > 100)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nnon_tabu_replicas must be a positive integer in the range [1..100]");
                return false;
            }
        }

        // check for rounds_without_tabu
        if (cl.hasOption("rounds_without_tabu")) {
            try {
                mixrepRoundsWithoutTabu = Integer.parseInt(cl.getOptionValue("rounds_without_tabu"));
                if (mixrepRoundsWithoutTabu < 0 || mixrepRoundsWithoutTabu > 1000000)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nrounds_without_tabu must be an integer in the range [0..1000000]");
                return false;
            }
        }

        // check for tabu_steps
        if (cl.hasOption("tabu_steps")) {
            try {
                mixrepNrOfTabuSteps = Integer.parseInt(cl.getOptionValue("tabu_steps"));
                if (mixrepNrOfTabuSteps < 1 || mixrepNrOfTabuSteps > 1000000)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\ntabu_steps must be a positive integer in the range [1..1000000]");
                return false;
            }
        }

        // check for tournament_size --> see Genetic Algorithm

        // check for children --> see Genetic Algorithm

        // check for tabu_list --> see Tabu Search

        // check for boost_nr
        if (cl.hasOption("boost_nr")) {
            try {
                mixrepBoostNr = Integer.parseInt(cl.getOptionValue("boost_nr"));
                if (mixrepBoostNr < 1 || mixrepBoostNr > 100)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nboost_nr must be a positive integer in the range [1..100]");
                return false;
            }
        }

        // check for boost_min_prog
        if (cl.hasOption("boost_min_prog")) {
            try {
                mixrepBoostMinProg = Double.parseDouble(cl.getOptionValue("boost_min_prog"));
                if (mixrepBoostMinProg <= 0.0)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nboost_min_prog must be a real number larger than 0.0");
                return false;
            }
        }

        // check for boost_time_factor
        if (cl.hasOption("boost_time_factor")) {
            try {
                mixrepBoostTimeFactor = Integer.parseInt(cl.getOptionValue("boost_time_factor"));
                if (mixrepBoostTimeFactor < 1)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nboost_time_factor must be a positive integer");
                return false;
            }
        }

        // check for min_boost_time
        if (cl.hasOption("min_boost_time")) {
            try {
                mixrepMinBoostTime = Double.parseDouble(cl.getOptionValue("min_boost_time"));
                if (mixrepMinBoostTime < 0.0)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nmin_boost_time must be a real number larger than or equal to 0.0");
                return false;
            }
        }

        // check LR Search advanced options

        // check for l
        if (cl.hasOption("l")) {
            try {
                lr_l = Integer.parseInt(cl.getOptionValue("l"));
                if (lr_l < 1)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nl must be a postive integer >= 1");
                return false;
            }
        }

        // check for r
        if (cl.hasOption("r")) {
            try {
                lr_r = Integer.parseInt(cl.getOptionValue("r"));
                if (lr_r < 1)
                    throw new NumberFormatException();
            } catch (NumberFormatException nfe) {
                System.err.println("\nr must be a postive integer >= 1");
                return false;
            }
        }

        // ensure that l and r are not equal
        if (lr_l == lr_r) {
            System.err.println("l and r cannot be equal");
            return false;
        }

    } catch (ParseException e) {
        System.err.println("");
        System.err.println(e.getMessage());
        return false;
    }

    return true;
}

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

/**
 * Methode die sich nach der Auswahl der Schrittgroesse fuer das
 * Fremdkapital kuemmert. Konkret wird aus dem String des Eingabefelds der
 * Double-Wert gezogen und ueberprueft ob dieser groesser oder gleich 0 ist.
 * Falls nicht wird eine ClassCastException geworfen, die eine Fehlermeldung
 * auf der Benutzeroberflaecher angezeigt und ein ComponentError generiert.
 * /* ww w. j  a v  a 2 s . c om*/
 * @author Christian Scherer
 * @param cashFlowStepRangeString
 *            Schrittgre das Fremdkapital fuer die RandomWalk Methode
 */
public void borrowedCapitalStepRangeChosen(String borrowedCapitalStepRangeString) {
    logger.debug("Anwender-Eingabe zu Schrittweite Cashflow");

    try {
        borrowedCapitalStepRange = Double.parseDouble(borrowedCapitalStepRangeString);
        if (borrowedCapitalStepRange >= 0) {
            borrowedCapitalStepRangeValid = true;
            getView().setComponentError(false, "borrowedCapitalStepRange", "");
            this.projectProxy.getSelectedProject().setBorrowedCapitalStepRange(this.borrowedCapitalStepRange);
            logger.debug("Schrittweite des Fremdkapital in das Projekt-Objekten gesetzt");
        } else {
            throw new NumberFormatException();
        }
    } catch (NumberFormatException nfe) {
        borrowedCapitalStepRangeValid = false;
        getView().setComponentError(true, "borrowedCapitalStepRange", errorMessageBorrowedCapitalStepRange);
        getView().showErrorMessage(errorMessageBorrowedCapitalStepRange);
        logger.debug("Keine gueltige Eingabe in Feld 'Schrittweite Fremdkapital'");
    }

    eventBus.fireEvent(new ValidateContentStateEvent());
}

From source file:edu.usc.scrc.PriorityPruner.CommandLineOptions.java

/**
 * Parses a String-argument to an integer value and makes sure it's valid.
 * //from w  ww.  j av  a  2 s .  com
 * @param option
 *            name of the Option to that the argument belongs
 * @param argument
 *            String that will be parsed
 * @param min
 *            minimum value allowed for this parameter
 * @param max
 *            maximum value allowed for this parameter
 * @return an integer value
 * @throws NumberFormatException
 *             if invalid String-argument were provided
 * @throws PriorityPrunerException
 *             if invalid String-argument were provided
 */
private int getIntegerArgument(String option, String argument, int min, int max)
        throws PriorityPrunerException {
    try {
        Integer intValue = Integer.parseInt(argument);
        if (intValue >= min && intValue <= max) {
            return intValue;
        } else {
            // exception get thrown either if parsing is impossible or
            // values are out of range
            throw new NumberFormatException();
        }
    } catch (NumberFormatException e) {
        throw new PriorityPrunerException("\"" + argument + "\" is not a valid input for option \"" + option
                + "\", please specify an integer value between " + min + " and " + max
                + ".\r\nFor more information type \"-h\".");
    }
}