Example usage for org.apache.commons.lang3 BooleanUtils toBoolean

List of usage examples for org.apache.commons.lang3 BooleanUtils toBoolean

Introduction

In this page you can find the example usage for org.apache.commons.lang3 BooleanUtils toBoolean.

Prototype

public static boolean toBoolean(final String str, final String trueString, final String falseString) 

Source Link

Document

Converts a String to a Boolean throwing an exception if no match found.

 BooleanUtils.toBoolean("true", "true", "false")  = true BooleanUtils.toBoolean("false", "true", "false") = false 

Usage

From source file:com.omertron.bgg.model.OwnerStatus.java

public void setOwn(String own) {
    this.own = BooleanUtils.toBoolean(own, "1", "0");
}

From source file:com.omertron.bgg.model.OwnerStatus.java

public void setPreviouslyOwned(String previouslyOwned) {
    this.previouslyOwned = BooleanUtils.toBoolean(previouslyOwned, "1", "0");
}

From source file:com.omertron.bgg.model.OwnerStatus.java

public void setForTrade(String forTrade) {
    this.forTrade = BooleanUtils.toBoolean(forTrade, "1", "0");
}

From source file:com.omertron.bgg.model.OwnerStatus.java

public void setWant(String want) {
    this.want = BooleanUtils.toBoolean(want, "1", "0");
}

From source file:com.omertron.bgg.model.OwnerStatus.java

public void setWantToPlay(String wantToPlay) {
    this.wantToPlay = BooleanUtils.toBoolean(wantToPlay, "1", "0");
}

From source file:com.omertron.bgg.model.OwnerStatus.java

public void setWantToBuy(String wantToBuy) {
    this.wantToBuy = BooleanUtils.toBoolean(wantToBuy, "1", "0");
}

From source file:com.dsh105.nexus.command.module.admin.ChannelCommand.java

@Override
public boolean onCommand(CommandPerformEvent event) {
    if (event.getArgs().length < 1 || event.getArgs().length > 3) {
        event.errorWithPing("Please specify both a channel and a command to disable ({0}).",
                event.getCommandPrefix() + event.getCommand() + " <channel> <command>");
        return true;
    }/*w w w .j a  v  a  2  s . c o  m*/

    String channel = event.getArgs()[0];
    ChannelConfig channelConfig = Nexus.getInstance().getChannelConfiguration().getChannel(channel);
    if (channelConfig == null) {
        event.errorWithPing("Commands cannot be disabled in a channel I am not present in ({0}).", channel);
        return true;
    }
    channel = channelConfig.getChannelName();

    if (event.getArgs().length == 1) {
        ArrayList<String> disabledCommands = channelConfig.getDisabledCommands();
        if (disabledCommands.isEmpty()) {
            event.respondWithPing("All commands are enabled in {0}.", channel);
        } else {
            event.respondWithPing("Disabled commands in {0}: " + StringUtil.join(disabledCommands, ", "),
                    channel);
        }
        return true;
    }

    String command = event.getArgs()[1];

    if (!command.equalsIgnoreCase("ALL")) {
        // Check if the command is valid
        CommandModule module = event.getManager().getModuleFor(command);
        if (module == null) {
            event.errorWithPing("{0} is not a valid command! Use {1} for help info.", command,
                    event.getCommandPrefix() + "help");
            return true;
        }
        command = module.info().command();
    }

    if (event.getArgs().length == 3) {
        boolean enable = BooleanUtils.toBoolean(event.getArgs()[2], "enable", "disable");
        channelConfig.setCommandStatus(command, enable);
        event.respondWithPing("{0} " + (enable ? "enabled" : "disabled") + " in {1}.",
                (command.equalsIgnoreCase("ALL") ? "All commands" : event.getCommandPrefix() + command),
                channel);
        return true;
    }

    if (command.equalsIgnoreCase("ALL")) {
        event.errorWithPing("Please use {0} to see if a command is disabled in a channel.",
                event.getCommandPrefix() + event.getCommand() + "<channel> <command>");
    }
    boolean enabled = channelConfig.isEnabled(command);
    event.respondWithPing("{0} is currently " + (enabled ? "enabled" : "disabled") + " in {1}.", command,
            channel);
    return true;
}

From source file:com.omertron.bgg.model.OwnerStatus.java

public void setPreordered(String preordered) {
    this.preordered = BooleanUtils.toBoolean(preordered, "1", "0");
}

From source file:ca.on.oicr.pde.workflows.GATKGenotypeGVCFsWorkflow.java

@Override
public void buildWorkflow() {

    final String binDir = this.getWorkflowBaseDir() + "/bin/";
    final Boolean manualOutput = BooleanUtils.toBoolean(getProperty("manual_output"), "true", "false");
    final String queue = getOptionalProperty("queue", "");
    final String java = getProperty("java");
    final String gatk = getOptionalProperty("gatk_jar", binDir);
    final String gatkKey = getProperty("gatk_key");
    final String identifier = getProperty("identifier");
    final String refFasta = getProperty("ref_fasta");
    final Double standCallConf = Double.valueOf(getProperty("stand_call_conf"));
    final Double standEmitConf = Double.valueOf(getProperty("stand_emit_conf"));
    final String dbsnpVcf = getOptionalProperty("gatk_dbsnp_vcf", null);
    final Integer gatkGenotypeGvcfsXmx = Integer.parseInt(getProperty("gatk_genotype_gvcfs_xmx"));
    final String gatkGenotypeGvcfsParams = getOptionalProperty("gatk_genotype_gvcfs_params", null);
    final Integer gatkCombineGVCFsXmx = Integer.parseInt(getProperty("gatk_combine_gvcfs_xmx"));
    final Integer gatkOverhead = Integer.parseInt(getProperty("gatk_sched_overhead_mem"));
    final Integer maxGenotypeGVCFsInputFiles = Integer
            .parseInt(getProperty("gatk_genotype_gvcfs_max_input_files"));
    final Integer maxCombineGVCFsInputFiles = Integer
            .parseInt(getProperty("gatk_combine_gvcfs_max_input_files"));
    final List<String> chrSizesList = Arrays.asList(StringUtils.split(getProperty("chr_sizes"), ","));
    final Set<String> chrSizes = new LinkedHashSet<>(chrSizesList);

    if (chrSizes.size() != chrSizesList.size()) {
        throw new RuntimeException("Duplicate chr_sizes detected.");
    }/* w ww  .j a va2  s.  co  m*/

    // one chrSize record is required, null will result in no parallelization
    if (chrSizes.isEmpty()) {
        chrSizes.add(null);
    }

    List<Pair<String, Job>> combineGvcfs = batchGVCFs(inputFiles, maxGenotypeGVCFsInputFiles,
            maxCombineGVCFsInputFiles, java, gatkCombineGVCFsXmx, gatkOverhead, tmpDir, gatk, gatkKey,
            tmpGVCFsDir, refFasta, queue);

    //use linked hashmap to keep "pairs" in sort order determined by chr_sizes
    LinkedHashMap<String, Pair<GenotypeGVCFs, Job>> vcfs = new LinkedHashMap<>();
    for (String chrSize : chrSizes) {

        //GATK Genotype VCFs( https://www.broadinstitute.org/gatk/gatkdocs/org_broadinstitute_gatk_tools_walkers_variantutils_GenotypeGVCFs.php )
        GenotypeGVCFs.Builder genotypeGvcfsBuilder = new GenotypeGVCFs.Builder(java, gatkGenotypeGvcfsXmx + "g",
                tmpDir, gatk, gatkKey, dataDir)
                        .setReferenceSequence(refFasta)
                        .setOutputFileName(
                                identifier + (chrSize != null ? "." + chrSize.replace(":", "-") : "") + ".raw")
                        .addInterval(chrSize).setStandardCallConfidence(standCallConf)
                        .setStandardEmitConfidence(standEmitConf).setDbsnpFilePath(dbsnpVcf)
                        .setExtraParameters(gatkGenotypeGvcfsParams);
        for (String f : getLeftCollection(combineGvcfs)) {
            genotypeGvcfsBuilder.addInputFile(f);
        }
        GenotypeGVCFs genotypeGvcfsCommand = genotypeGvcfsBuilder.build();

        Job genotypeGvcfsJob = getWorkflow().createBashJob("GATKGenotypeGVCFs")
                .setMaxMemory(Integer.toString((gatkGenotypeGvcfsXmx + gatkOverhead) * 1024)).setQueue(queue);
        genotypeGvcfsJob.getCommand().setArguments(genotypeGvcfsCommand.getCommand());

        // add parents, null if provision file in, not null if parent is a combine gvcf job
        for (Job j : getRightCollection(combineGvcfs)) {
            if (j != null) {
                genotypeGvcfsJob.addParent(j);
            }
        }

        if (vcfs.put(chrSize, Pair.of(genotypeGvcfsCommand, genotypeGvcfsJob)) != null) {
            throw new RuntimeException("Unexpected state: duplicate vcf.");
        }
    }

    if (vcfs.size() > 1) {
        //GATK CatVariants ( https://www.broadinstitute.org/gatk/guide/tooldocs/org_broadinstitute_gatk_tools_CatVariants.php )
        CatVariants.Builder catVariantsBuilder = new CatVariants.Builder(java, gatkCombineGVCFsXmx + "g",
                tmpDir, gatk, gatkKey, dataDir).setReferenceSequence(refFasta)
                        //individual vcf files sorted by genotype gvcfs; order of input vcf concatenation is determined by chr_sizes order (assumed to be sorted)
                        .disableSorting().setOutputFileName(identifier + ".raw");
        for (GenotypeGVCFs cmd : getLeftCollection(vcfs.values())) {
            catVariantsBuilder.addInputFile(cmd.getOutputFile());
        }
        CatVariants catVariantsCommand = catVariantsBuilder.build();

        Job combineGVCFsJob = getWorkflow().createBashJob("GATKCombineGVCFs")
                .setMaxMemory(Integer.toString((gatkCombineGVCFsXmx + gatkOverhead) * 1024)).setQueue(queue);
        combineGVCFsJob.getParents().addAll(getRightCollection(vcfs.values()));
        combineGVCFsJob.getCommand().setArguments(catVariantsCommand.getCommand());
        combineGVCFsJob.addFile(
                createOutputFile(catVariantsCommand.getOutputFile(), "application/vcf-gz", manualOutput));
        combineGVCFsJob.addFile(
                createOutputFile(catVariantsCommand.getOutputIndex(), "application/tbi", manualOutput));
    } else if (vcfs.size() == 1) {
        Pair<GenotypeGVCFs, Job> p = Iterables.getOnlyElement(vcfs.values());
        GenotypeGVCFs cmd = p.getLeft();
        Job genotypeGvcfsJob = p.getRight();
        genotypeGvcfsJob.addFile(createOutputFile(cmd.getOutputFile(), "application/vcf-gz", manualOutput));
        genotypeGvcfsJob.addFile(createOutputFile(cmd.getOutputIndex(), "application/tbi", manualOutput));
    } else {
        throw new RuntimeException("Unexpected state: No VCFs");
    }
}

From source file:ca.on.oicr.pde.workflows.GATKHaplotypeCallerWorkflow.java

@Override
public void buildWorkflow() {

    final String binDir = this.getWorkflowBaseDir() + "/bin/";
    final Boolean manualOutput = BooleanUtils.toBoolean(getProperty("manual_output"), "true", "false");
    final String queue = getOptionalProperty("queue", "");
    final String java = getProperty("java");
    final String gatk = getOptionalProperty("gatk_jar", binDir);
    final String gatkKey = getProperty("gatk_key");
    final String identifier = getProperty("identifier");
    final String refFasta = getProperty("ref_fasta");
    final String dbsnpVcf = getProperty("gatk_dbsnp_vcf");
    final Integer intervalPadding = hasPropertyAndNotNull("interval_padding")
            ? Integer.parseInt(getProperty("interval_padding"))
            : null;//  ww w .j a v  a 2s  .co  m
    final Integer downsamplingCoverage = hasPropertyAndNotNull("downsampling_coverage")
            ? Integer.parseInt(getProperty("downsampling_coverage"))
            : null;
    final String downsamplingType = getOptionalProperty("downsampling_type", null);
    final Integer gatkHaplotypeCallerThreads = Integer.parseInt(getProperty("gatk_haplotype_caller_threads"));
    final Integer gatkHaplotypeCallerXmx = Integer.parseInt(getProperty("gatk_haplotype_caller_xmx"));
    final Integer gatkCombineGVCFsXmx = Integer.parseInt(getProperty("gatk_combine_gvcfs_xmx"));
    final Integer gatkOverhead = Integer.parseInt(getProperty("gatk_sched_overhead_mem"));
    final String haplotypeCallerParams = getOptionalProperty("gatk_haplotype_caller_params", null);

    final List<String> intervalFilesList = Arrays
            .asList(StringUtils.split(getOptionalProperty("interval_files", ""), ","));
    final Set<String> intervalFiles = new HashSet<>(intervalFilesList);
    if (intervalFiles.size() != intervalFilesList.size()) {
        throw new RuntimeException("Duplicate interval_files detected");
    }

    final Set<String> chrSizes;
    if (hasProperty("chr_sizes")) {
        //chr_sizes has been set
        List<String> chrSizesList = Arrays.asList(StringUtils.split(getProperty("chr_sizes"), ","));
        chrSizes = new HashSet<>(chrSizesList);
        if (chrSizes.size() != chrSizesList.size()) {
            throw new RuntimeException("Duplicate chr_sizes detected.");
        }
    } else if (!intervalFiles.isEmpty()) {
        //chr_sizes not set, interval_files has been set - use interval files to calculate chrSizes
        try {
            chrSizes = BEDFileUtils.getChromosomes(intervalFiles);
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    } else {
        //chr_sizes and interval_files not set - can not calculate chrSizes
        chrSizes = new HashSet<>();
    }

    // one chrSize record is required, null will result in no parallelization
    if (chrSizes.isEmpty()) {
        chrSizes.add(null);
    }

    Map<String, Pair<HaplotypeCaller, Job>> gvcfs = new HashMap<>();
    for (String chrSize : chrSizes) {
        //GATK Haplotype Caller ( https://www.broadinstitute.org/gatk/gatkdocs/org_broadinstitute_gatk_tools_walkers_haplotypecaller_HaplotypeCaller.php )
        HaplotypeCaller haplotypeCallerCommand = new HaplotypeCaller.Builder(java,
                Integer.toString(gatkHaplotypeCallerXmx) + "g", tmpDir, gatk, gatkKey, dataDir)
                        .setInputBamFiles(inputBamFiles).setReferenceSequence(refFasta)
                        .setDbsnpFilePath(dbsnpVcf).addInterval(chrSize).addIntervalFiles(intervalFiles)
                        .setIntervalPadding(intervalPadding)
                        .setDownsamplingCoverageThreshold(downsamplingCoverage)
                        .setDownsamplingType(downsamplingType)
                        .setOutputFileName(
                                identifier + (chrSize != null ? "." + chrSize.replace(":", "-") : ""))
                        .setNumCpuThreadsPerDataThread(gatkHaplotypeCallerThreads)
                        .setExtraParameters(haplotypeCallerParams).build();
        Job haplotypeCallerJob = this.getWorkflow().createBashJob("GATKHaplotypeCaller")
                .setMaxMemory(Integer.toString((gatkHaplotypeCallerXmx + gatkOverhead) * 1024)).setQueue(queue);
        haplotypeCallerJob.getCommand().setArguments(haplotypeCallerCommand.getCommand());

        if (gvcfs.put(chrSize, Pair.of(haplotypeCallerCommand, haplotypeCallerJob)) != null) {
            throw new RuntimeException("Unexpected state: Duplicate key.");
        }
    }

    if (gvcfs.size() > 1) {
        //GATK CatVariants ( https://www.broadinstitute.org/gatk/guide/tooldocs/org_broadinstitute_gatk_tools_CatVariants.php )
        CatVariants.Builder catVariantsBuilder = new CatVariants.Builder(java,
                Integer.toString(gatkCombineGVCFsXmx) + "g", tmpDir, gatk, gatkKey, dataDir)
                        .setReferenceSequence(refFasta).setOutputFileName(identifier);
        for (HaplotypeCaller hc : getLeftCollection(gvcfs.values())) {
            catVariantsBuilder.addInputFile(hc.getOutputFile());
        }
        CatVariants catvariantsCommand = catVariantsBuilder.build();
        Job combineGVCFsJob = getWorkflow().createBashJob("GATKCombineGVCFs")
                .setMaxMemory(Integer.toString((gatkCombineGVCFsXmx + gatkOverhead) * 1024)).setQueue(queue);
        combineGVCFsJob.getParents().addAll(getRightCollection(gvcfs.values()));
        combineGVCFsJob.getCommand().setArguments(catvariantsCommand.getCommand());
        combineGVCFsJob.addFile(
                createOutputFile(catvariantsCommand.getOutputFile(), "application/g-vcf-gz", manualOutput));
        combineGVCFsJob.addFile(
                createOutputFile(catvariantsCommand.getOutputIndex(), "application/tbi", manualOutput));
    } else if (gvcfs.size() == 1) {
        Pair<HaplotypeCaller, Job> p = Iterables.getOnlyElement(gvcfs.values());
        HaplotypeCaller hcCmd = p.getLeft();
        Job hcJob = p.getRight();
        hcJob.addFile(createOutputFile(hcCmd.getOutputFile(), "application/g-vcf-gz", manualOutput));
        hcJob.addFile(createOutputFile(hcCmd.getOutputIndex(), "application/tbi", manualOutput));
    } else {
        throw new RuntimeException("Unexpected state: No GVCFs");
    }
}