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

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

Introduction

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

Prototype

public static Boolean xor(final Boolean... array) 

Source Link

Document

Performs an xor on an array of Booleans.

 BooleanUtils.xor(new Boolean[] { Boolean.TRUE, Boolean.TRUE })   = Boolean.FALSE BooleanUtils.xor(new Boolean[] { Boolean.FALSE, Boolean.FALSE }) = Boolean.FALSE BooleanUtils.xor(new Boolean[] { Boolean.TRUE, Boolean.FALSE })  = Boolean.TRUE 

Usage

From source file:com.music.service.EmailService.java

@Async
public void send(EmailDetails details) {
    if (details.getSubject() == null || !BooleanUtils
            .xor(ArrayUtils.toArray(details.getMessage() != null, details.getMessageTemplate() != null))) {
        throw new IllegalStateException(
                "Either subject or subjectKey / either template/message/messageKey should be specified");
    }//from  ww  w.  j ava 2  s  .c  o m
    Validate.notBlank(details.getFrom());

    Email email = createEmail(details.isHtml());
    String subject = constructSubject(details);
    email.setSubject(subject);

    String emailMessage = constructEmailMessages(details);

    try {
        if (details.isHtml()) {
            ((HtmlEmail) email).setHtmlMsg(emailMessage);
        } else {
            email.setMsg(emailMessage);
        }

        for (String to : details.getTo()) {
            email.addTo(to);
        }
        email.setFrom(details.getFrom());

        email.send();
    } catch (EmailException ex) {
        logger.error("Exception occurred when sending email to " + details.getTo(), ex);
    }
}

From source file:com.marand.thinkmed.medications.dao.openehr.OpenEhrMedicationsDao.java

@Override
public List<Pair<MedicationOrderComposition, MedicationInstructionInstruction>> findMedicationInstructions(
        final long patientId, final Interval searchInterval, final Long centralCaseId) {
    Preconditions/*www.java 2 s  . co  m*/
            .checkArgument(BooleanUtils.xor(new Boolean[] { centralCaseId != null, searchInterval != null }));

    final String ehrId = currentSession().findEhr(patientId);
    if (!StringUtils.isEmpty(ehrId)) {
        currentSession().useEhr(ehrId);
        final StringBuilder sb = new StringBuilder();
        sb.append("SELECT c, i/name/value FROM EHR[ehr_id/value='").append(ehrId).append("']")
                .append(" CONTAINS Composition c[openEHR-EHR-COMPOSITION.encounter.v1]")
                .append(" CONTAINS Instruction i[openEHR-EHR-INSTRUCTION.medication.v1]")
                .append(" WHERE c/name/value = 'Medication order'");
        if (searchInterval != null) {
            appendMedicationTimingIntervalCriterion(sb, searchInterval);
        }
        if (centralCaseId != null) {
            sb.append(" AND ").append(
                    "c/context/other_context[at0001]/items[openEHR-EHR-CLUSTER.composition_context_detail.v1]/items[at0001]/value = '"
                            + Long.toString(centralCaseId) + "'");
        }
        sb.append(" ORDER BY c/context/start_time");

        return queryEhrContent(sb.toString(),
                new ResultRowProcessor<Object[], Pair<MedicationOrderComposition, MedicationInstructionInstruction>>() {
                    @Override
                    public Pair<MedicationOrderComposition, MedicationInstructionInstruction> process(
                            final Object[] resultRow, final boolean hasNext) throws ProcessingException {
                        final MedicationOrderComposition composition = RmoToTdoConverter
                                .convert(MedicationOrderComposition.class, (RmObject) resultRow[0]);
                        final MedicationInstructionInstruction instruction = MedicationsEhrUtils
                                .getMedicationInstructionByEhrName(composition, (String) resultRow[1]);
                        return Pair.of(composition, instruction);
                    }
                });
    }
    return Lists.newArrayList();
}

From source file:io.cloudex.framework.config.PartitionConfig.java

/**
 * Determine if this instance is valid//from  ww w.ja v  a  2 s  .c o  m
 * @return true if valid, false otherwise
 */
public boolean valid() {

    return ObjectUtils.isValid(PartitionConfig.class, this) && ((PartitionType.COUNT.equals(this.type)
            && ((this.count != null) || StringUtils.isNotBlank(this.countRef)))
            || ((PartitionType.ITEMS.equals(this.type)
                    || (PartitionType.FUNCTION.equals(this.type) && StringUtils.isNotBlank(this.output)
                            && BooleanUtils.xor(new boolean[] { StringUtils.isBlank(this.className),
                                    StringUtils.isBlank(this.functionName) })))
                    && ((this.input != null) && (this.input.get(PartitionFunction.ITEMS_KEY) != null))));

}

From source file:io.cloudex.framework.config.PartitionConfig.java

/**
 * Get any validation errors/*from w ww.  j a v a 2s . com*/
 * @return a list of validation messages
 */
public List<String> getValidationErrors() {

    List<String> messages = ObjectUtils.getValidationErrors(PartitionConfig.class, this);

    if (PartitionType.FUNCTION.equals(this.type)) {
        if (StringUtils.isBlank(this.output)) {

            messages.add("output is required for Function type partition");
        }

        if (!BooleanUtils.xor(new boolean[] { StringUtils.isBlank(this.className),
                StringUtils.isBlank(this.functionName) })) {

            messages.add("either functionName or className is required");
        }

    } else if (PartitionType.COUNT.equals(this.type)
            && !BooleanUtils.xor(new boolean[] { this.count == null, StringUtils.isBlank(this.countRef) })) {

        messages.add("either count or countRef is required for Function type count");
    }

    if (!PartitionType.COUNT.equals(this.type)) {

        if (this.input == null) {
            messages.add("input may not be null");

        } else if (this.input.get(PartitionFunction.ITEMS_KEY) == null) {
            messages.add("expecting an input with key items");
        }
    }

    return messages;
}

From source file:com.marand.thinkmed.medications.dao.openehr.MedicationsOpenEhrDao.java

public List<Pair<MedicationOrderComposition, MedicationInstructionInstruction>> findMedicationInstructions(
        final String patientId, final Interval searchInterval, final String centralCaseId) {
    Preconditions//  w  w w  .  j av  a 2 s .  co m
            .checkArgument(BooleanUtils.xor(new Boolean[] { centralCaseId != null, searchInterval != null }));

    final String ehrId = currentSession().findEhr(patientId);
    if (!StringUtils.isEmpty(ehrId)) {
        currentSession().useEhr(ehrId);
        final StringBuilder sb = new StringBuilder();
        sb.append("SELECT c, i/name/value FROM EHR[ehr_id/value='").append(ehrId).append("']")
                .append(" CONTAINS Composition c[openEHR-EHR-COMPOSITION.encounter.v1]")
                .append(" CONTAINS Instruction i[openEHR-EHR-INSTRUCTION.medication.v1]")
                .append(" WHERE c/name/value = 'Medication order'");
        if (searchInterval != null) {
            appendMedicationTimingIntervalCriterion(sb, searchInterval);
        }
        if (centralCaseId != null) {
            sb.append(" AND ").append(
                    "c/context/other_context[at0001]/items[openEHR-EHR-CLUSTER.composition_context_detail.v1]/items[at0001]/value = '"
                            + centralCaseId + "'");
        }
        sb.append(" ORDER BY c/context/start_time");

        return queryEhrContent(sb.toString(), (resultRow, hasNext) -> {
            final MedicationOrderComposition composition = RmoToTdoConverter
                    .convert(MedicationOrderComposition.class, (RmObject) resultRow[0]);
            final MedicationInstructionInstruction instruction = MedicationsEhrUtils
                    .getMedicationInstructionByEhrName(composition, (String) resultRow[1]);
            return Pair.of(composition, instruction);
        });
    }
    return Lists.newArrayList();
}

From source file:org.sejda.cli.transformer.MergeCliArgumentsTransformer.java

private MultiplePdfMergeInputAdapter extractPdfMergeInputs(MergeTaskCliArguments taskCliArguments) {
    // input files can be specified in 3 ways: explicitly, via a folder or via a config file
    List<PdfFileSource> inputFiles = null;
    if (taskCliArguments.isDirectory()) {
        if (taskCliArguments.isMatchingRegEx()) {
            inputFiles = taskCliArguments.getDirectory().filter(taskCliArguments.getMatchingRegEx())
                    .getFileSourceList();
        } else {//  w ww  . j  a  v a  2s  . c om
            inputFiles = taskCliArguments.getDirectory().getFileSourceList();
        }

    } else if (taskCliArguments.isFiles()) {
        inputFiles = extractFiles(taskCliArguments.getFiles());
    } else if (taskCliArguments.isFilesListConfig()) {
        inputFiles = taskCliArguments.getFilesListConfig().getFileSourceList();
    }

    if (!BooleanUtils.or(new boolean[] { taskCliArguments.isDirectory(), taskCliArguments.isFiles(),
            taskCliArguments.isFilesListConfig() })) {
        throw new SejdaRuntimeException(
                "No option given for input. Please use one of the following options: --directory --filesListConfig --file");
    }

    if (!BooleanUtils.xor(new boolean[] { taskCliArguments.isDirectory(), taskCliArguments.isFiles(),
            taskCliArguments.isFilesListConfig() })) {
        throw new SejdaRuntimeException(
                "Too many options given for input. Please use only one of the following options: --directory --filesListConfig --file");
    }

    if (inputFiles == null) {
        throw new SejdaRuntimeException("No input files specified");
    }

    MultiplePdfMergeInputAdapter mergeInputsAdapter = new MultiplePdfMergeInputAdapter(inputFiles,
            taskCliArguments.getPageSelection().ranges());
    return mergeInputsAdapter;
}

From source file:yoyo.framework.standard.shared.commons.lang.BooleanUtilsTest.java

@Test
public void test() {
    assertThat(BooleanUtils.and(new boolean[] { true }), is(true));
    assertThat(BooleanUtils.and(new boolean[] { true, false }), is(false));
    assertThat(BooleanUtils.isFalse(false), is(true));
    assertThat(BooleanUtils.isNotFalse(false), is(false));
    assertThat(BooleanUtils.isNotTrue(true), is(false));
    assertThat(BooleanUtils.isTrue(true), is(true));
    assertThat(BooleanUtils.negate(Boolean.FALSE), is(true));
    assertThat(BooleanUtils.or(new boolean[] { true }), is(true));
    assertThat(BooleanUtils.or(new boolean[] { true, false }), is(true));
    assertThat(BooleanUtils.toBoolean(Boolean.TRUE), is(true));
    assertThat(BooleanUtils.toBoolean(0), is(false));
    assertThat(BooleanUtils.toBoolean(1), is(true));
    assertThat(BooleanUtils.toBoolean((String) null), is(false));
    assertThat(BooleanUtils.toBoolean("true"), is(true));
    assertThat(BooleanUtils.toBoolean("hoge"), is(false));
    assertThat(BooleanUtils.toBooleanDefaultIfNull(null, false), is(false));
    assertThat(BooleanUtils.toBooleanObject(0), is(Boolean.FALSE));
    assertThat(BooleanUtils.toBooleanObject(1), is(Boolean.TRUE));
    assertThat(BooleanUtils.toInteger(true), is(1));
    assertThat(BooleanUtils.toInteger(false), is(0));
    assertThat(BooleanUtils.toIntegerObject(true), is(Integer.valueOf(1)));
    assertThat(BooleanUtils.toIntegerObject(false), is(Integer.valueOf(0)));
    assertThat(BooleanUtils.toString(true, "true", "false"), is("true"));
    assertThat(BooleanUtils.toString(false, "true", "false"), is("false"));
    assertThat(BooleanUtils.toStringOnOff(true), is("on"));
    assertThat(BooleanUtils.toStringOnOff(false), is("off"));
    assertThat(BooleanUtils.toStringTrueFalse(true), is("true"));
    assertThat(BooleanUtils.toStringTrueFalse(false), is("false"));
    assertThat(BooleanUtils.toStringYesNo(true), is("yes"));
    assertThat(BooleanUtils.toStringYesNo(false), is("no"));
    assertThat(BooleanUtils.xor(new boolean[] { true }), is(true));
    assertThat(BooleanUtils.xor(new boolean[] { true, false }), is(true));
    assertThat(BooleanUtils.xor(new boolean[] { true, true }), is(false));
}