Example usage for java.util Properties getProperty

List of usage examples for java.util Properties getProperty

Introduction

In this page you can find the example usage for java.util Properties getProperty.

Prototype

public String getProperty(String key, String defaultValue) 

Source Link

Document

Searches for the property with the specified key in this property list.

Usage

From source file:Main.java

/**
 * Gets the boolean property from the properties object.
 * @param key the key of the boolean property
 * @param defaultValue the default value if the property doesn't exist
 * @param properties the properties object to get the property from
 * @return the property value, defaultValue if the property doesn't exist
 *///from  w w  w  .j a v a 2 s.  co m
public static boolean getBoolean(String key, boolean defaultValue, Properties properties) {
    if (properties.containsKey(key)) {
        return Boolean.valueOf(properties.getProperty(key, "false"));
    } else {
        return defaultValue;
    }
}

From source file:Main.java

public static boolean getBooleanProperty(Properties properties, String key, boolean defaultValue) {
    if (properties != null) {
        String value = properties.getProperty(key, "").trim().toLowerCase();

        if (!value.equals("")) {
            return Boolean.parseBoolean(value);
        }/*from   w w w .j  av a 2  s.  c o  m*/
    }

    return defaultValue;
}

From source file:Main.java

public static int getIntProperty(Properties properties, String key, int defaultValue) {
    if (properties != null) {
        String value = properties.getProperty(key, "").trim();

        if (!value.equals("")) {
            try {
                return Integer.parseInt(value);
            } catch (NumberFormatException var5) {
                ;//from   w w w .j  av a 2s . c o m
            }
        }
    }

    return defaultValue;
}

From source file:Main.java

public static float getFloatProperty(Properties properties, String key, float defaultValue) {
    if (properties != null) {
        String value = properties.getProperty(key, "").trim();

        if (!value.equals("")) {
            try {
                return Float.parseFloat(value);
            } catch (NumberFormatException var5) {
                ;/*from   w  w w  .j  ava2s .c  o m*/
            }
        }
    }

    return defaultValue;
}

From source file:Main.java

public static double getDoubleProperty(Properties properties, String key, double defaultValue) {
    if (properties != null) {
        String value = properties.getProperty(key, "").trim();

        if (!value.equals("")) {
            try {
                return Double.parseDouble(value);
            } catch (NumberFormatException var6) {
                ;//from  ww w .j ava  2s.  com
            }
        }
    }

    return defaultValue;
}

From source file:Main.java

public static String getProperty(String filePath, String fileName, String propertyName, String defaultValue) {
    try {// ww w  . jav  a 2  s.c  om
        Properties p = loadPropertyInstance(filePath, fileName);
        return p.getProperty(propertyName, defaultValue);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static List<String> getPropertyList(String filePath, String fileName, String propertyName,
        String defaultValue) {// w  w  w.  j av a2 s  .  co  m
    try {
        Properties p = loadPropertyInstance(filePath, fileName);
        String v = p.getProperty(propertyName, defaultValue);
        String[] iA = v.split("(?<!\\\\);");
        for (int i = 0; i < iA.length; i++) {
            iA[i] = iA[i].replaceAll("(\\\\)+$", "").replaceAll("\\\\;", ";").replaceAll("\\\\\\\\", "\\\\");
        }
        return Arrays.asList(iA);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

static boolean isTestnet(final Context c) {
    try {//w  w w  .  ja v a  2s  .c  om
        final Properties p = new Properties();
        p.load(new BufferedInputStream(new FileInputStream(getBitcoinConf(c))));
        return p.getProperty("testnet", p.getProperty("regtest", "0")).equals("1");
    } catch (final IOException e) {
        return false;
    }
}

From source file:Main.java

static String getDataDir(final Context c) {
    final String defaultDataDir = String.format("%s/.bitcoin", getDir(c).getAbsolutePath());
    try {/*  w  w w  .j a v a 2 s  . c  o m*/
        final Properties p = new Properties();
        p.load(new BufferedInputStream(new FileInputStream(getBitcoinConf(c))));
        return p.getProperty("datadir", defaultDataDir);
    } catch (final IOException e) {
        return defaultDataDir;
    }
}

From source file:dk.alexandra.fresco.suite.tinytables.online.TinyTablesConfiguration.java

public static ProtocolSuiteConfiguration fromCmdLine(SCEConfiguration sceConf, CommandLine cmd)
        throws ParseException, IllegalArgumentException {

    Options options = new Options();

    TinyTablesConfiguration configuration = new TinyTablesConfiguration();

    String tinyTablesFileOption = "tinytables.file";

    options.addOption(Option.builder("D").desc("The file where the generated TinyTables is leaded from.")
            .longOpt(tinyTablesFileOption).required(false).hasArgs().build());

    Properties p = cmd.getOptionProperties("D");

    String tinyTablesFilePath = p.getProperty(tinyTablesFileOption, "tinytables");
    File tinyTablesFile = new File(tinyTablesFilePath);
    configuration.setTinyTablesFile(tinyTablesFile);

    System.out.println("FromCmdArgs: " + configuration.getTinyTablesFile());

    return configuration;
}