Example usage for java.lang Boolean parseBoolean

List of usage examples for java.lang Boolean parseBoolean

Introduction

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

Prototype

public static boolean parseBoolean(String s) 

Source Link

Document

Parses the string argument as a boolean.

Usage

From source file:com.netflix.imfutility.itunes.destcontext.wrap.DestContextMapWrapper.java

public Boolean getValueAsBoolean(String paramName) {
    String value = getValue(paramName);
    return value != null && Boolean.parseBoolean(value);
}

From source file:com.netflix.governator.configuration.SystemConfigurationProvider.java

@Override
public Property<Boolean> getBooleanProperty(final ConfigurationKey key, final Boolean defaultValue) {
    return new Property<Boolean>() {
        @Override/*from   w  w w .ja va  2  s . co  m*/
        public Boolean get() {
            String value = System.getProperty(key.getKey(variableValues));
            if (value == null) {
                return defaultValue;
            }
            return Boolean.parseBoolean(value);
        }
    };
}

From source file:org.yamj.common.tools.PropertyTools.java

/**
 * Return the key property as a boolean/*from  w  w w . j av a2  s .  c om*/
 *
 * @param key
 * @param defaultValue
 * @return
 */
public static boolean getBooleanProperty(String key, boolean defaultValue) {
    String property = PROPERTIES.getProperty(key);
    if (property != null) {
        return Boolean.parseBoolean(property.trim());
    }
    return defaultValue;
}

From source file:com.googlecode.jmxtrans.cli.CommonsCliArgumentParser.java

/** Parse the options given on the command line. */
@Nonnull//from  www.j  av a  2  s .  c  om
@Override
public JmxTransConfiguration parseOptions(@Nonnull String[] args)
        throws OptionsException, org.apache.commons.cli.ParseException {
    CommandLineParser parser = new GnuParser();
    CommandLine cl = parser.parse(getOptions(), args);
    Option[] options = cl.getOptions();

    JmxTransConfiguration configuration = new JmxTransConfiguration();

    for (Option option : options) {
        if (option.getOpt().equals("c")) {
            configuration.setContinueOnJsonError(Boolean.parseBoolean(option.getValue()));
        } else if (option.getOpt().equals("j")) {
            File jsonDir = new File(option.getValue());
            if (jsonDir.exists() && jsonDir.isDirectory()) {
                configuration.setJsonDir(jsonDir);
            } else {
                throw new OptionsException("Path to json directory is invalid: " + jsonDir);
            }
        } else if (option.getOpt().equals("f")) {
            File jsonFile = new File(option.getValue());
            if (jsonFile.exists() && jsonFile.isFile()) {
                configuration.setJsonFile(jsonFile);
            } else {
                throw new OptionsException("Path to json file is invalid: " + jsonFile);
            }
        } else if (option.getOpt().equals("e")) {
            configuration.setRunEndlessly(true);
        } else if (option.getOpt().equals("q")) {
            File quartzConfigFile = new File(option.getValue());
            if (quartzConfigFile.exists() && quartzConfigFile.isFile()) {
                configuration.setQuartzPropertiesFile(quartzConfigFile);
            } else {
                throw new OptionsException("Could not find path to the quartz properties file: "
                        + quartzConfigFile.getAbsolutePath());
            }
        } else if (option.getOpt().equals("s")) {
            try {
                configuration.setRunPeriod(Integer.parseInt(option.getValue()));
            } catch (NumberFormatException nfe) {
                throw new OptionsException("Seconds between server job runs must be an integer");
            }
        } else if (option.getOpt().equals("a")) {
            configuration.setAdditionalJars(option.getValuesList());
        } else if (option.getOpt().equals("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar jmxtrans-all.jar", getOptions());
            configuration.setHelp(true);
        }
    }
    if ((!configuration.isHelp()) && (configuration.getJsonDirOrFile() == null)) {
        throw new OptionsException("Please specify either the -f or -j option.");
    }
    return configuration;
}

From source file:com.wso2telco.hub.custom.tier.migration.TierMigartionClient.java

private void updateAppTierConfigsInRegistry() {

    boolean isTierMigration = Boolean.parseBoolean(System.getProperty(ARG_MIGRATE_TIER));
    if (!isTierMigration) {

        if (log.isDebugEnabled()) {
            log.debug("Skipping the Tier configuration update in registry");
        }//from ww w  .j a  v a 2  s.  c om
        return;
    }

    RegistryService registryService = ServiceReferenceHolder.getInstance().getRegistryService();

    UserRegistry govRegistry = null;
    // get governance registry
    try {
        govRegistry = registryService.getGovernanceSystemRegistry();
    } catch (RegistryException e) {
        handleError("Error in getting Governance Registry", e);
    }

    byte[] data;

    String resourcesDirectory = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator
            + "resources";
    // check if a default-tiers.xml is available in the
    // <APIM_HOME>/repository/resources/default-tiers
    File defaultTiersFile = new File(resourcesDirectory + File.separator + DEFAULT_TIERS_FILE);
    if (defaultTiersFile.exists()) {
        data = readDefaultTierConfigFile(resourcesDirectory);
        if (data != null && data.length > 0) {
            // delete the existing application tier config file in the
            // registry
            deleteExistingAppTierConfig(govRegistry);
            // update
            updateAppTierConfigs(govRegistry, data);
            log.info("Successfully updated the Application tiers configuration at " + APP_TIERS_LOCATION);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("No custom " + DEFAULT_TIERS_FILE + " file found at carbon resources directory");
        }
    }
}

From source file:com.aliyun.odps.ogg.handler.datahub.ConfigureReader.java

public static Configure reader(String configueFileName) throws DocumentException {
    logger.info("Begin read configure[" + configueFileName + "]");

    Configure configure = new Configure();
    SAXReader reader = new SAXReader();
    File file = new File(configueFileName);

    Document document = reader.read(file);
    Element root = document.getRootElement();

    String elementText = root.elementTextTrim("batchSize");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setBatchSize(Integer.parseInt(elementText));
    }/*  w w w.  java  2s.c o m*/

    elementText = root.elementTextTrim("dirtyDataContinue");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDirtyDataContinue(Boolean.parseBoolean(elementText));
    }

    elementText = root.elementTextTrim("dirtyDataFile");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDirtyDataFile(elementText);
    }

    elementText = root.elementTextTrim("dirtyDataFileMaxSize");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDirtyDataFileMaxSize(Integer.parseInt(elementText));
    }

    elementText = root.elementTextTrim("retryTimes");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setRetryTimes(Integer.parseInt(elementText));
    }

    elementText = root.elementTextTrim("retryInterval");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setRetryInterval(Integer.parseInt(elementText));
    }

    elementText = root.elementTextTrim("disableCheckPointFile");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setDisableCheckPointFile(Boolean.parseBoolean(elementText));
    }

    elementText = root.elementTextTrim("checkPointFileName");
    if (StringUtils.isNotBlank(elementText)) {
        configure.setCheckPointFileName(elementText);
    }

    Element element = root.element("defaultOracleConfigure");
    if (element == null) {
        throw new RuntimeException("defaultOracleConfigure is null");
    }

    elementText = element.elementTextTrim("sid");
    if (StringUtils.isBlank(elementText)) {
        throw new RuntimeException("defaultOracleConfigure.sid is null");
    }
    configure.setSid(elementText);

    String defaultOracleSchema = element.elementTextTrim("schema");

    SimpleDateFormat defaultSimpleDateFormat;
    elementText = element.elementTextTrim("dateFormat");
    if (StringUtils.isNotBlank(elementText)) {
        defaultSimpleDateFormat = new SimpleDateFormat(elementText);
    } else {
        defaultSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    element = root.element("defalutDatahubConfigure");
    if (element == null) {
        throw new RuntimeException("defalutDatahubConfigure is null");
    }

    String endPoint = element.elementText("endPoint");
    if (StringUtils.isBlank(endPoint)) {
        throw new RuntimeException("defalutDatahubConfigure.endPoint is null");

    }

    String defaultDatahubProject = element.elementText("project");
    String defaultDatahubAccessID = element.elementText("accessId");
    String defaultDatahubAccessKey = element.elementText("accessKey");

    Field defaultCTypeField = null;
    String defaultCTypeColumn = element.elementText("ctypeColumn");
    if (StringUtils.isNotBlank(defaultCTypeColumn)) {
        defaultCTypeField = new Field(defaultCTypeColumn, FieldType.STRING);
    }
    Field defaultCTimeField = null;
    String defaultCTimeColumn = element.elementText("ctimeColumn");
    if (StringUtils.isNotBlank(defaultCTimeColumn)) {
        defaultCTimeField = new Field(defaultCTimeColumn, FieldType.STRING);
    }
    Field defaultCidField = null;
    String defaultCidColumn = element.elementText("cidColumn");
    if (StringUtils.isNotBlank(defaultCidColumn)) {
        defaultCidField = new Field(defaultCidColumn, FieldType.STRING);
    }

    String defaultConstColumnMapStr = element.elementText("constColumnMap");
    Map<String, String> defalutConstColumnMappings = Maps.newHashMap();
    Map<String, Field> defaultConstColumnFieldMappings = Maps.newHashMap();
    parseConstColumnMap(defaultConstColumnMapStr, defalutConstColumnMappings, defaultConstColumnFieldMappings);

    element = root.element("mappings");
    if (element == null) {
        throw new RuntimeException("mappings is null");
    }

    List<Element> mappingElements = element.elements("mapping");
    if (mappingElements == null || mappingElements.size() == 0) {
        throw new RuntimeException("mappings.mapping is null");
    }

    //init table mapping
    for (Element e : mappingElements) {
        String oracleSchema = e.elementTextTrim("oracleSchema");
        if (StringUtils.isNotBlank(oracleSchema)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultOracleSchema)) {
            oracleSchema = defaultOracleSchema;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.oracleSchema and defaultOracleConfigure.schema is null");
        }

        String oracleTable = e.elementTextTrim("oracleTable");
        if (StringUtils.isBlank(oracleTable)) {
            throw new RuntimeException("mappings.mapping.oracleTable is null");
        }

        String datahubProject = e.elementTextTrim("datahubProject");
        if (StringUtils.isNotBlank(datahubProject)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultOracleSchema)) {
            datahubProject = defaultDatahubProject;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.datahubProject and defalutDatahubConfigure.project is null");
        }

        String datahubAccessId = e.elementTextTrim("datahubAccessId");
        if (StringUtils.isNotBlank(datahubAccessId)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultDatahubAccessID)) {
            datahubAccessId = defaultDatahubAccessID;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.datahubAccessId and defalutDatahubConfigure.accessId is null");
        }

        String datahubAccessKey = e.elementTextTrim("datahubAccessKey");
        if (StringUtils.isNotBlank(datahubAccessKey)) {
            //nothing
        } else if (StringUtils.isNotBlank(defaultDatahubAccessKey)) {
            datahubAccessKey = defaultDatahubAccessKey;
        } else {
            throw new RuntimeException(
                    "both mappings.mapping.datahubAccessKey and defalutDatahubConfigure.accessKey is null");
        }

        String topicName = e.elementTextTrim("datahubTopic");
        if (topicName == null) {
            throw new RuntimeException("mappings.mapping.datahubTopic is null");
        }

        String ctypeColumn = e.elementText("ctypeColumn");
        String ctimeColumn = e.elementText("ctimeColumn");
        String cidColumn = e.elementText("cidColumn");

        DatahubConfiguration datahubConfiguration = new DatahubConfiguration(
                new AliyunAccount(datahubAccessId, datahubAccessKey), endPoint);
        Project project = Project.Builder.build(datahubProject, datahubConfiguration);
        Topic topic = project.getTopic(topicName);
        if (topic == null) {
            throw new RuntimeException("Can not find datahub topic[" + topicName + "]");
        } else {
            logger.info(
                    "topic name: " + topicName + ", topic schema: " + topic.getRecordSchema().toJsonString());
        }

        TableMapping tableMapping = new TableMapping();
        tableMapping.setTopic(topic);
        tableMapping.setOracleSchema(oracleSchema.toLowerCase());
        tableMapping.setOracleTableName(oracleTable.toLowerCase());
        tableMapping.setOracleFullTableName(
                tableMapping.getOracleSchema() + "." + tableMapping.getOracleTableName());
        tableMapping
                .setCtypeField(StringUtils.isNotBlank(ctypeColumn) ? new Field(ctypeColumn, FieldType.STRING)
                        : defaultCTypeField);
        tableMapping
                .setCtimeField(StringUtils.isNotBlank(ctimeColumn) ? new Field(ctimeColumn, FieldType.STRING)
                        : defaultCTimeField);
        tableMapping.setCidField(
                StringUtils.isNotBlank(cidColumn) ? new Field(cidColumn, FieldType.STRING) : defaultCidField);

        String constColumnMapStr = e.elementText("constColumnMap");
        Map<String, String> constColumnMappings = Maps.newHashMap();
        Map<String, Field> constColumnFieldMappings = Maps.newHashMap();
        parseConstColumnMap(constColumnMapStr, constColumnMappings, constColumnFieldMappings);

        tableMapping.setConstColumnMappings(
                constColumnMappings.isEmpty() ? defalutConstColumnMappings : constColumnMappings);
        tableMapping.setConstFieldMappings(constColumnFieldMappings.isEmpty() ? defaultConstColumnFieldMappings
                : constColumnFieldMappings);

        Map<String, ColumnMapping> columnMappings = Maps.newHashMap();
        tableMapping.setColumnMappings(columnMappings);

        elementText = e.elementTextTrim("shardId");
        if (StringUtils.isNotBlank(elementText)) {
            tableMapping.setShardId(elementText);
        }

        configure.addTableMapping(tableMapping);

        RecordSchema recordSchema = topic.getRecordSchema();

        Element columnMappingElement = e.element("columnMapping");
        List<Element> columns = columnMappingElement.elements("column");
        for (Element columnElement : columns) {
            String oracleColumnName = columnElement.attributeValue("src");
            if (StringUtils.isBlank(oracleColumnName)) {
                throw new RuntimeException("Topic[" + topicName + "] src attribute is null");
            }

            oracleColumnName = oracleColumnName.toLowerCase();
            ColumnMapping columnMapping = new ColumnMapping();
            columnMappings.put(oracleColumnName, columnMapping);
            columnMapping.setOracleColumnName(oracleColumnName);

            String datahubFieldName = columnElement.attributeValue("dest");
            if (datahubFieldName == null) {
                throw new RuntimeException("Topic[" + topicName + "] dest attribute is null");
            }

            Field field = recordSchema.getField(datahubFieldName.toLowerCase());
            if (field == null) {
                throw new RuntimeException(
                        "Topic[" + topicName + "] Field[" + datahubFieldName + "] is not exist");
            }

            columnMapping.setField(field);

            String datahubOldFieldName = columnElement.attributeValue("destOld");
            if (StringUtils.isNotBlank(datahubOldFieldName)) {
                Field oldField = recordSchema.getField(datahubOldFieldName);

                if (field == null) {
                    throw new RuntimeException(
                            "Topic[" + topicName + "] Field[" + datahubOldFieldName + "] is not exist");
                }
                columnMapping.setOldFiled(oldField);
            }

            String isShardColumn = columnElement.attributeValue("isShardColumn");
            if (StringUtils.isNotBlank(isShardColumn) && Boolean.TRUE.equals(Boolean.valueOf(isShardColumn))) {
                tableMapping.setIsShardHash(true);
                columnMapping.setIsShardColumn(true);
            } else {
                columnMapping.setIsShardColumn(false);
            }

            String isKeyColumn = columnElement.attributeValue("isKeyColumn");
            if (StringUtils.isNotBlank(isKeyColumn) && Boolean.TRUE.equals(Boolean.valueOf(isKeyColumn))) {
                columnMapping.setIsKeyColumn(true);
            } else {
                columnMapping.setIsKeyColumn(false);
            }

            String dateFormat = columnElement.attributeValue("dateFormat");

            if (StringUtils.isNotBlank(dateFormat)) {
                columnMapping.setSimpleDateFormat(new SimpleDateFormat(dateFormat));
            } else {
                columnMapping.setSimpleDateFormat(defaultSimpleDateFormat);
            }

            String isDateFormat = columnElement.attributeValue("isDateFormat");

            if (StringUtils.isNotBlank(isDateFormat) && Boolean.FALSE.equals(Boolean.valueOf(isDateFormat))) {
                columnMapping.setIsDateFormat(false);
            } else {
                columnMapping.setIsDateFormat(true);
            }
        }
    }

    logger.info("Read configure success: " + JsonHelper.beanToJson(configure));
    return configure;
}

From source file:it.govpay.web.rs.dars.anagrafica.iban.input.IdNegozio.java

@Override
protected boolean isRequired(List<RawParamValue> values, Object... objects) {
    String attivatoObepValue = Utils.getValue(values, this.attivatoObepId);

    if (StringUtils.isNotEmpty(attivatoObepValue) && Boolean.parseBoolean(attivatoObepValue)) {
        return true;
    }/*from w  w  w . j av  a  2s  .c o m*/

    return false;
}

From source file:rest.ProjectREST.java

private Project getFormattedDataSingle(Response response) {
    String responseJson = response.readEntity(String.class);
    System.out.println(responseJson);
    ObjectMapper mapper = new ObjectMapper();
    TypeReference<HashMap<String, Object>> typeReference = new TypeReference<HashMap<String, Object>>() {
    };/* w  ww. java 2s .c  om*/
    StringBuilder sb = new StringBuilder();
    try {
        HashMap<String, Object> map = mapper.readValue(responseJson, typeReference);
        if (Boolean.parseBoolean(map.get("found").toString())) {
            return Project.parseProject(map);
            //               
        } else {
            return null;
        }
    } catch (Exception e) {
        return null;
    }
}

From source file:org.centralperf.service.BootstrapService.java

/**
 * Check if it's necessary to launch bootstrap.
 * If the user has already imported sample data or refused it, then it returns false 
 * @return true if already initialized, false otherwise
 *//*from www.  j  a va  2  s .  c o  m*/
public boolean isAlreadyInitialized() {
    Boolean initialized = Boolean
            .parseBoolean(configurationService.getConfigurationValue(Configuration.INITIALIZED));
    return initialized != null ? initialized : false;
}

From source file:eu.fbk.utils.lsa.util.AnvurTest.java

public static void main(String[] args) throws Exception {
    String logConfig = System.getProperty("log-config");
    if (logConfig == null) {
        logConfig = "log-config.txt";
    }/*from w  w  w.jav  a  2  s . c  o m*/

    PropertyConfigurator.configure(logConfig);

    if (args.length != 8) {
        System.out.println(args.length);
        System.out.println(
                "Usage: java -mx2G eu.fbk.utils.lsa.util.AnvurTest root-lsa-en root-lsa-it threshold-lsa size-lsa dim-lsa idf-lsa in-file-tsv fields-tsv\n\n");
        System.exit(1);
    }

    //
    DecimalFormat dec = new DecimalFormat("#.00");

    File enUt = new File(args[0] + "-Ut");
    File enSk = new File(args[0] + "-S");
    File enr = new File(args[0] + "-row");
    File enc = new File(args[0] + "-col");
    File endf = new File(args[0] + "-df");
    File itUt = new File(args[1] + "-Ut");
    File itSk = new File(args[1] + "-S");
    File itr = new File(args[1] + "-row");
    File itc = new File(args[1] + "-col");
    File itdf = new File(args[1] + "-df");

    double threshold = Double.parseDouble(args[2]);
    int size = Integer.parseInt(args[3]);
    int dim = Integer.parseInt(args[4]);
    boolean rescaleIdf = Boolean.parseBoolean(args[5]);

    LSM enLsm = new LSM(enUt, enSk, enr, enc, endf, dim, rescaleIdf);
    LSM itLsm = new LSM(itUt, itSk, itr, itc, itdf, dim, rescaleIdf);

    File in = new File(args[6]);

    if (in.isFile()) {
        run(enLsm, itLsm, args[6], args[7]);
    } else if (in.isDirectory()) {
        FolderScanner fs = new FolderScanner(in);
        fs.setFiler(new TsvFilter());
        int count = 0;
        while (fs.hasNext()) {
            Object[] files = fs.next();
            System.out.println((count++) + " : " + files.length);
            for (int i = 0; i < files.length; i++) {

                String name = ((File) files[i]).getAbsolutePath();
                System.out.println(name);
                run(enLsm, itLsm, name, args[7]);
            } // end for i
        } // end while
    }

}