Example usage for java.lang Integer getInteger

List of usage examples for java.lang Integer getInteger

Introduction

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

Prototype

public static Integer getInteger(String nm) 

Source Link

Document

Determines the integer value of the system property with the specified name.

Usage

From source file:Main.java

public static void main(String[] args) {
    String myKey = "MyKey";
    System.setProperty(myKey, "102");
    System.out.println(Integer.getInteger(myKey));
}

From source file:Main.java

public static void main(String[] args) {
    String myKey = "MyKey";
    System.setProperty(myKey, "102");
    System.out.println(Integer.getInteger(myKey));
    System.out.println(Integer.getInteger("NoExist", 999));
}

From source file:Main.java

public static void main(String[] args) {
    String myKey = "MyKey";
    System.setProperty(myKey, "102");
    System.out.println(Integer.getInteger(myKey));
    System.out.println(Integer.getInteger("NoExist", new Integer(999)));
}

From source file:Main.java

public static void main(String[] args) {
    System.setProperty("app.major.version", "1");
    System.setProperty("app.minor.version", "19");

    Integer major = Integer.getInteger("app.major.version");
    Integer minor = Integer.getInteger("app.minor.version");
    System.out.println("App version = " + major + "." + minor);
}

From source file:PropView.java

public static void main(String args[]) throws Exception {
    Properties properties = System.getProperties();
    properties.list(System.out);/*from   ww w. ja  v  a 2  s.c o  m*/

    FileInputStream in = null;

    in = new FileInputStream(args[0]);
    properties.load(in);

    System.getProperties().list(System.out);
    System.out.println("\nValue of local.animal.defined is " + Boolean.getBoolean("local.animal.defined"));
    System.out.println("\nValue of local.animal.legcount is " + Integer.getInteger("local.animal.legcount"));
}

From source file:org.dspace.health.Report.java

public static void main(String[] args) {
    log.info("Starting healthcheck report...");

    final String option_help = "h";
    final String option_email = "e";
    final String option_check = "c";
    final String option_last_n = "f";
    final String option_verbose = "v";

    // command line options
    Options options = new Options();
    options.addOption(option_help, "help", false, "Show available checks and their index.");
    options.addOption(option_email, "email", true, "Send report to this email address.");
    options.addOption(option_check, "check", true, "Perform only specific check (use index starting from 0).");
    options.addOption(option_last_n, "for", true, "For last N days.");
    options.addOption(option_verbose, "verbose", false, "Verbose report.");

    CommandLine cmdline = null;/*  ww w  .j a  v a 2  s . c  o m*/
    try {
        cmdline = new PosixParser().parse(options, args);
    } catch (ParseException e) {
        log.fatal("Invalid command line " + e.toString(), e);
        System.exit(1);
    }

    if (cmdline.hasOption(option_help)) {
        String checks_summary = "";
        int pos = 0;
        for (String check_name : checks().keySet()) {
            checks_summary += String.format("%d. %s\n", pos++, check_name);
        }
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("dspace healthcheck", options);
        System.out.println("\nAvailable checks:\n" + checks_summary);
        return;
    }

    // what to perform
    List<Integer> to_perform = null;
    if (null != cmdline.getOptionValues(option_check)) {
        to_perform = new ArrayList<>();
        for (String s : cmdline.getOptionValues('c')) {
            to_perform.add(Integer.valueOf(s));
        }
    }

    try {

        // last n days
        int for_last_n_days = ConfigurationManager.getIntProperty("healthcheck", "last_n_days");
        if (cmdline.hasOption(option_last_n)) {
            for_last_n_days = Integer.getInteger(cmdline.getOptionValue(option_last_n));
        }
        ReportInfo ri = new ReportInfo(for_last_n_days);
        if (cmdline.hasOption(option_verbose)) {
            ri.verbose(true);
        }

        // run report
        Report r = new Report();
        r.run(to_perform, ri);
        log.info("reports generated...");

        // send/output the report
        if (cmdline.hasOption(option_email)) {
            String to = cmdline.getOptionValue(option_email);
            if (!to.contains("@")) {
                to = ConfigurationManager.getProperty(to);
            }
            try {
                String dspace_dir = ConfigurationManager.getProperty("dspace.dir");
                String email_path = dspace_dir.endsWith("/") ? dspace_dir : dspace_dir + "/";
                email_path += Report.EMAIL_PATH;
                log.info(String.format("Looking for email template at [%s]", email_path));
                Email email = Email.getEmail(email_path);
                email.addRecipient(to);
                email.addArgument(r.toString());
                email.send();
            } catch (Exception e) {
                log.fatal("Error sending email:", e);
                System.err.println("Error sending email:\n" + e.getMessage());
                System.exit(1);
            }
        }

    } catch (Exception e) {
        log.fatal(e);
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Gets an integer property as a privileged action.
 *
 * @param property_name the integer property name
 *
 * @return the property value/*from w w w  . j av  a  2  s .  c o  m*/
 */
public static Integer getPrivilegedInteger(final String property_name) {
    return AccessController.doPrivileged(new PrivilegedAction<Integer>() {
        public Integer run() {
            return Integer.getInteger(property_name);
        }
    });
}

From source file:Main.java

/**
 * Uses the non-portable system property sun.arch.data.model to help
 * determine if we are running on a 32-bit JVM. Since the majority of modern
 * systems are 64 bits, this method "assumes" 64 bits and only returns true
 * if sun.arch.data.model explicitly indicates a 32-bit JVM.
 *
 * @return true if we can determine definitively that this is a 32-bit JVM,
 *         otherwise false// w w  w.j a v a 2s  .com
 */
private static boolean is32BitJvm() {
    Integer bits = Integer.getInteger("sun.arch.data.model");
    return bits != null && bits == 32;
}

From source file:org.LexGrid.LexBIG.caCore.utils.LexEVSCaCoreUtils.java

public static Object setFieldValue(Object input, Object value, String fieldName) throws Exception {
    Class searchClass = input.getClass();

    while (searchClass != null) {
        Field[] fields = searchClass.getDeclaredFields();
        for (Field field : fields) {
            if (field.getName().equals(fieldName)) {
                field.setAccessible(true);
                //Check to see if we're trying to set a int, long, etc with a String
                if (field.getType().getName().equals("java.lang.Long")) {
                    if (value instanceof String) {
                        field.set(input, Long.getLong((String) value));
                    } else {
                        field.set(input, value);
                    }//from   w  w  w. j  a v a2s. c om
                } else if (field.getType().getName().equals("java.lang.Integer")) {
                    if (value instanceof String) {
                        field.set(input, Integer.getInteger((String) value));
                    } else {
                        field.set(input, value);
                    }
                } else {
                    field.set(input, value);
                }
            }
        }
        searchClass = searchClass.getSuperclass();
    }
    return input;
}

From source file:net.certifi.audittablegen.PostgresqlDMR.java

/**
 * Generate a Postgresql DataSource from Properties 
 * @param props/*from  w  w w . j ava 2  s  .  com*/
 * @return BasicDataSource as DataSource
 */
static DataSource getRunTimeDataSource(Properties props) {

    //BasicDataSource dataSource = new BasicDataSource();
    PGPoolingDataSource dataSource = new PGPoolingDataSource();
    //PGSimpleDataSource dataSource = new PGSimpleDataSource();
    int port;
    dataSource.setUser(props.getProperty("username"));
    dataSource.setPassword(props.getProperty("password"));
    //dataSource.setInitialConnections(2);
    //dataSource.setApplicationName("AuditTableGen");
    dataSource.setServerName(props.getProperty("server"));
    dataSource.setDatabaseName(props.getProperty("database"));
    if (props.containsKey("port")) {
        port = Integer.getInteger(props.getProperty("port", "5432"));
        dataSource.setPortNumber(port);
    }

    //dataSource.setDriverClassName("org.postgresql.Driver");
    //dataSource.setUsername(props.getProperty("username"));
    //dataSource.setPassword(props.getProperty("password"));
    //dataSource.setUrl(props.getProperty("url"));
    //dataSource.setMaxActive(10);
    //dataSource.setMaxIdle(5);
    //dataSource.setInitialSize(5);
    //dataSource.setValidationQuery("SELECT 1");

    return dataSource;
}