Example usage for java.lang Boolean compare

List of usage examples for java.lang Boolean compare

Introduction

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

Prototype

public static int compare(boolean x, boolean y) 

Source Link

Document

Compares two boolean values.

Usage

From source file:io.appform.jsonrules.utils.ComparisonUtils.java

static int compare(JsonNode evaluatedNode, Object value) {
    int comparisonResult = 0;
    if (evaluatedNode.isNumber()) {
        if (Number.class.isAssignableFrom(value.getClass())) {
            Number nValue = (Number) value;
            if (evaluatedNode.isIntegralNumber()) {
                comparisonResult = Long.compare(evaluatedNode.asLong(), nValue.longValue());
            } else if (evaluatedNode.isFloatingPointNumber()) {
                comparisonResult = Double.compare(evaluatedNode.asDouble(), nValue.doubleValue());
            }/* ww w. ja v  a  2  s. c om*/
        } else {
            throw new IllegalArgumentException("Type mismatch between operator and operand");
        }
    } else if (evaluatedNode.isBoolean()) {
        if (Boolean.class.isAssignableFrom(value.getClass())) {
            Boolean bValue = Boolean.parseBoolean(value.toString());
            comparisonResult = Boolean.compare(evaluatedNode.asBoolean(), bValue);
        } else {
            throw new IllegalArgumentException("Type mismatch between operator and operand");
        }

    } else if (evaluatedNode.isTextual()) {
        if (String.class.isAssignableFrom(value.getClass())) {
            comparisonResult = evaluatedNode.asText().compareTo(String.valueOf(value));
        } else {
            throw new IllegalArgumentException("Type mismatch between operator and operand");
        }
    } else if (evaluatedNode.isObject()) {
        throw new IllegalArgumentException("Object comparisons not supported");
    }
    return comparisonResult;
}

From source file:com.squarespace.template.JsonUtils.java

/**
 * Compare two JsonNode objects and return an integer.
 *
 * @return  a negative integer, zero, or a positive integer as this object
 *          is less than, equal to, or greater than the specified object.
 *///from   w  ww  .j a  v a2  s. co  m
public static int compare(JsonNode left, JsonNode right) {
    if (left.isLong() || left.isInt()) {
        return Long.compare(left.asLong(), right.asLong());

    } else if (left.isDouble() || left.isFloat()) {
        return Double.compare(left.asDouble(), right.asDouble());

    } else if (left.isTextual()) {
        return left.asText().compareTo(right.asText());

    } else if (left.isBoolean()) {
        return Boolean.compare(left.asBoolean(), right.asBoolean());
    }

    // Not comparable in a relative sense, default to equals.
    return left.equals(right) ? 0 : -1;
}

From source file:org.eclipse.php.internal.ui.editor.contentassist.PHPCompletionProposalSorter.java

@Override
public int compare(ICompletionProposal p1, ICompletionProposal p2) {
    if (p1 instanceof AbstractScriptCompletionProposal && p2 instanceof AbstractScriptCompletionProposal) {
        AbstractScriptCompletionProposal cp1 = (AbstractScriptCompletionProposal) p1;
        AbstractScriptCompletionProposal cp2 = (AbstractScriptCompletionProposal) p2;

        IModelElement el1 = cp1.getModelElement();
        IModelElement el2 = cp2.getModelElement();

        if (el1.getElementType() == IModelElement.TYPE && el2.getElementType() == IModelElement.TYPE) {
            try {
                int result = Boolean.compare(PHPFlags.isNamespace(((IType) el1).getFlags()),
                        PHPFlags.isNamespace(((IType) el2).getFlags()));
                if (result != 0) {
                    return result;
                }//from   w ww  .ja  v a 2  s  .  c  o  m
            } catch (ModelException e) {
                Logger.logException(e);
            }
        }

        if (el1.getElementName().equals(el2.getElementName())) {
            String parent1 = getParentQualifier(el1.getParent());
            String parent2 = getParentQualifier(el2.getParent());

            if (parent1 == null && parent2 == null) {
                return 0;
            } else if (parent1 == null) {
                return -1;
            } else if (parent2 == null) {
                return 1;
            }

            int segments1 = StringUtils.countMatches(parent1, "\\"); //$NON-NLS-1$
            int segments2 = StringUtils.countMatches(parent2, "\\"); //$NON-NLS-1$
            // bump up elements in global namespace
            if (segments1 == 0 || segments2 == 0) {
                return Integer.compare(segments1, segments2);
            }
            return parent1.compareToIgnoreCase(parent2);
        }
        return 0;
    }
    return 0;
}

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.model.reports.SwarmCluster.java

private void sortNodes() {
    nodes.sort((node1, node2) -> {//from w  w w .  j  a v a2 s . c  o  m
        final int leaderCompareResult = Boolean.compare(node2.isLeader(), node1.isLeader());
        if (leaderCompareResult == 0) {
            final int compareResult = Boolean.compare(node2.isManager(), node1.isManager());
            if (compareResult == 0) {
                return node1.getHostname().compareTo(node2.getHostname());
            }
            return compareResult;
        }
        return leaderCompareResult;
    });
}

From source file:com.kegare.caveworld.util.CaveConfiguration.java

@Override
public int compare(String o1, String o2) {
    int result = CaveUtils.compareWithNull(o1, o2);

    if (result == 0 && o1 != null && o2 != null) {
        boolean flag1 = NumberUtils.isNumber(o1);
        boolean flag2 = NumberUtils.isNumber(o2);
        result = Boolean.compare(flag1, flag2);

        if (result == 0) {
            if (flag1 && flag2) {
                result = Integer.compare(NumberUtils.toInt(o1), NumberUtils.toInt(o2));
            } else if (!flag1 && !flag2) {
                result = o1.compareTo(o2);
            }//from w  w  w  .  j  a va  2 s .  c o m
        }
    }

    return result;
}

From source file:net.mintern.primitive.pair.BooleanPair.java

/**
 * Compares the pair based on the left element followed by the right element.
 *
 * @param other  the other pair, not null
 * @return negative if this is less, zero if equal, positive if greater
 *//* w  w w .  ja  v a  2 s  . c  om*/
@Override
public int compareTo(BooleanPair other) {
    int cmp = Boolean.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Boolean.compare(getRight(), other.getRight());
}

From source file:net.mintern.primitive.pair.BooleanIntPair.java

/**
 * Compares the pair based on the left element followed by the right element.
 *
 * @param other  the other pair, not null
 * @return negative if this is less, zero if equal, positive if greater
 */// ww w . ja  v a2 s.  c o m
@Override
public int compareTo(BooleanIntPair other) {
    int cmp = Boolean.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Integer.compare(getRight(), other.getRight());
}

From source file:net.mintern.primitive.pair.BooleanLongPair.java

/**
 * Compares the pair based on the left element followed by the right element.
 *
 * @param other  the other pair, not null
 * @return negative if this is less, zero if equal, positive if greater
 *//* ww w . ja  v  a2  s  . c om*/
@Override
public int compareTo(BooleanLongPair other) {
    int cmp = Boolean.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Long.compare(getRight(), other.getRight());
}

From source file:net.mintern.primitive.pair.ByteBooleanPair.java

/**
 * Compares the pair based on the left element followed by the right element.
 *
 * @param other  the other pair, not null
 * @return negative if this is less, zero if equal, positive if greater
 *//*from   ww  w .  j a  v a2s  .c o  m*/
@Override
public int compareTo(ByteBooleanPair other) {
    int cmp = Byte.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Boolean.compare(getRight(), other.getRight());
}

From source file:net.mintern.primitive.pair.IntBooleanPair.java

/**
 * Compares the pair based on the left element followed by the right element.
 *
 * @param other  the other pair, not null
 * @return negative if this is less, zero if equal, positive if greater
 */// ww  w  .ja v  a2s  .  co  m
@Override
public int compareTo(IntBooleanPair other) {
    int cmp = Integer.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Boolean.compare(getRight(), other.getRight());
}