Example usage for java.lang Integer compare

List of usage examples for java.lang Integer compare

Introduction

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

Prototype

public static int compare(int x, int y) 

Source Link

Document

Compares two int values numerically.

Usage

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);
            }/*w w w .j ava 2  s. c  om*/
        }
    }

    return result;
}

From source file:org.sakaiproject.scorm.model.api.comparator.LearnerExperienceComparator.java

@Override
public int compare(LearnerExperience le1, LearnerExperience le2) {
    // Perform different comparison depending on which comparison type has been selected
    switch (compType) {
    case Learner: {
        return le1.getLearnerName().compareTo(le2.getLearnerName());
    }/*  w ww.  j a v  a 2s .  c  o m*/
    case AttemptDate: {
        return ObjectUtils.compare(le1.getLastAttemptDate(), le2.getLastAttemptDate());
    }
    case Status: {
        return Integer.compare(le1.getStatus(), le2.getStatus());
    }
    case NumberOfAttempts: {
        return Integer.compare(le1.getNumberOfAttempts(), le2.getNumberOfAttempts());
    }
    }

    return 0;
}

From source file:net.mintern.primitive.pair.IntPair.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 w w  w.j  a  v  a 2s  .  c  o m
@Override
public int compareTo(IntPair other) {
    int cmp = Integer.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Integer.compare(getRight(), other.getRight());
}

From source file:net.mintern.primitive.pair.IntBytePair.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 . j  ava  2  s .  c o  m
@Override
public int compareTo(IntBytePair other) {
    int cmp = Integer.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Byte.compare(getRight(), other.getRight());
}

From source file:net.mintern.primitive.pair.IntLongPair.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 w ww  . ja  va  2s .  c  o m*/
@Override
public int compareTo(IntLongPair other) {
    int cmp = Integer.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Long.compare(getRight(), other.getRight());
}

From source file:net.mintern.primitive.pair.IntCharPair.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  .j  a v a2  s .  c o  m
@Override
public int compareTo(IntCharPair other) {
    int cmp = Integer.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Character.compare(getRight(), other.getRight());
}

From source file:net.mintern.primitive.pair.IntFloatPair.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   www .  java 2  s .c o m
@Override
public int compareTo(IntFloatPair other) {
    int cmp = Integer.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Float.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
 *//* www  .j ava 2  s  .co m*/
@Override
public int compareTo(IntBooleanPair other) {
    int cmp = Integer.compare(getLeft(), other.getLeft());
    return cmp != 0 ? cmp : Boolean.compare(getRight(), other.getRight());
}

From source file:org.diorite.impl.command.CommandMapImpl.java

private Iterable<MainCommand> getSortedCommandList() {
    return this.commandMap.values().stream()
            .sorted((c1, c2) -> Integer.compare(c2.getPriority(), c1.getPriority()))
            .collect(Collectors.toList());
}

From source file:com.jnj.b2b.core.search.solrfacetsearch.provider.entity.GenericVariantProductModelComparator.java

/**
 * Considers variant1 greater then other if, for the same variant category level, the value of the
 * {@link VariantValueCategoryModel} belonging to variant1 has a bigger sequence then the
 * {@link VariantValueCategoryModel} belonging to variant2.
 *//*from  w  w w  . j av a2  s  .  co m*/
@Override
public int compare(final GenericVariantProductModel variant1, final GenericVariantProductModel variant2) {
    if ((variant1 != null) && (variant2 != null)) {
        // get sorted list of VariantValueCategories
        final List<VariantValueCategoryModel> variantValueCategories1 = getVariantValuesCategories(variant1);
        final List<VariantValueCategoryModel> variantValueCategories2 = getVariantValuesCategories(variant2);
        if (variantValueCategories1.size() == variantValueCategories2.size()) {
            int compare = 0;
            for (int i = 0; i < variantValueCategories1.size(); i++) {
                final VariantValueCategoryModel valueCategory1 = variantValueCategories1.get(i);
                final VariantValueCategoryModel valueCategory2 = variantValueCategories2.get(i);
                compare = Integer.compare(valueCategory1.getSequence(), valueCategory2.getSequence());
                if (compare != 0) {
                    break;
                }
            }
            return compare;
        } else {
            throw new IllegalArgumentException(
                    "Variants should have the same number of category levels to be compared!");
        }
    } else {
        throw new IllegalArgumentException("Cannot compare null variants!");
    }
}