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:org.openeos.services.ui.form.abstractform.UIBeanSelectorProvider.java

@Override
@Transactional(readOnly = true)/*from w w w .  jav  a 2s . com*/
public SortedSet<T> getElements() {
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(beanClass);
    if (sqlRestriction != null && formInstance instanceof BFormInstance<?, ?>) {
        Object value = ((BFormInstance<?, ?>) formInstance).getValue();
        if (value instanceof UIBeanImpl) {
            value = ((UIBeanImpl) value).getBeanWrapped();
        }
        crit.add(buildSqlRestriction(sqlRestriction, value));
    }
    final List<T> listElements = crit.list();
    TreeSet<T> result = new TreeSet<T>(new Comparator<T>() {

        @Override
        public int compare(T o1, T o2) {
            return Integer.compare(listElements.indexOf(o1), listElements.indexOf(o2));
        }
    });
    result.addAll(listElements);
    return result;
}

From source file:com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl.PartyChartDataManagerImpl.java

/**
 * Gets the max size view riksdagen vote data ballot party summary daily.
 *
 * @return the max size view riksdagen vote data ballot party summary daily
 *//*  ww  w.  j a  va 2 s  .  c om*/
private List<ViewRiksdagenVoteDataBallotPartySummaryDaily> getMaxSizeViewRiksdagenVoteDataBallotPartySummaryDaily() {
    initPartyMap();

    final Optional<Entry<String, List<ViewRiksdagenVoteDataBallotPartySummaryDaily>>> first = partyMap
            .entrySet().stream().sorted((e1, e2) -> Integer.compare(e2.getValue().size(), e1.getValue().size())

            ).findFirst();

    if (first.isPresent()) {
        return first.get().getValue();
    } else {
        return new ArrayList<>();
    }
}

From source file:alias.id.WildcardID.java

@Override
public int compareTo(WildcardID otherWildcardID) {
    return Integer.compare(this.weight(), otherWildcardID.weight());
}

From source file:de.pixida.logtest.designer.automaton.Graph.java

void addObject(final BaseObject value) {
    Validate.notNull(value);//from  w w w.  j a v a  2 s  .  c o m
    Validate.isTrue(!this.objects.containsKey(value));
    final List<GraphShape> newShapes = value.getParts();
    Validate.notNull(newShapes);
    this.objects.put(value, newShapes);
    this.shapes.addAll(newShapes);
    Collections.sort(this.shapes, (shape1, shape2) -> Integer.compare(shape1.getZIndex(), shape2.getZIndex()));
    this.pane.getChildren().clear();
    this.pane.getChildren()
            .addAll(this.shapes.stream().map(shape -> shape.getNode()).collect(Collectors.toList()));
}

From source file:com.igormaznitsa.jute.Utils.java

public static List<TestContainer> sortDetectedClassMethodsForNameAndOrder(
        final List<TestContainer> testMethods) {
    Collections.sort(testMethods, new Comparator<TestContainer>() {
        @Override/*from   ww w  . j a  v  a2  s  .c  o m*/
        public int compare(final TestContainer o1, final TestContainer o2) {
            final int order1 = o1.getOrder() < 0 ? -1 : o1.getOrder();
            final int order2 = o2.getOrder() < 0 ? -1 : o2.getOrder();

            final String name1 = o1.getMethodName();
            final String name2 = o2.getMethodName();

            final int result;
            if (order1 == order2) {
                result = name1.compareTo(name2);
            } else {
                result = Integer.compare(order1, order2);
            }
            return result;
        }
    });
    return testMethods;
}

From source file:com.simiacryptus.mindseye.models.Hdf5Archive.java

private static void printTree(@Nonnull Hdf5Archive hdf5, CharSequence prefix, boolean printData,
        @Nonnull Logger log, @Nonnull String... path) {
    for (CharSequence datasetName : hdf5.getDataSets(path)) {
        @Nullable/*from   www. j a  v a2  s.  c  om*/
        Tensor tensor = hdf5.readDataSet(datasetName.toString(), path);
        log.info(String.format("%sDataset %s: %s", prefix, datasetName,
                Arrays.toString(tensor.getDimensions())));
        if (printData)
            log.info(String.format("%s%s", prefix, tensor.prettyPrint().replaceAll("\n", "\n" + prefix)));
        tensor.freeRef();
    }
    hdf5.getAttributes(path).forEach((k, v) -> {
        log.info((String.format("%sAttribute: %s => %s", prefix, k, v)));
    });
    for (String t : hdf5.getGroups(path).stream().map(CharSequence::toString).sorted(new Comparator<String>() {
        @Override
        public int compare(@Nonnull String o1, @Nonnull String o2) {
            @Nonnull
            String prefix = "layer_";
            @Nonnull
            Pattern digit = Pattern.compile("^\\d+$");
            if (digit.matcher(o1).matches() && digit.matcher(o2).matches())
                return Integer.compare(Integer.parseInt(o1), Integer.parseInt(o2));
            if (o1.startsWith(prefix) && o2.startsWith(prefix))
                return compare(o1.substring(prefix.length()), o2.substring(prefix.length()));
            else
                return o1.compareTo(o2);
        }
    }).collect(Collectors.toList())) {
        log.info(prefix + t);
        printTree(hdf5, prefix + "\t", printData, log, concat(path, t));
    }
}

From source file:TDS.Shared.Browser.BrowserValidation.java

public List<BrowserRule> FindRules(final BrowserInfo browserInfo) {
    //      return _rules.Where(r => MatchRule(browserInfo, r)).OrderByDescending(r => r.Priority);
    CollectionUtils.filter(_rules, new Predicate() {
        @Override/*w  ww  .  ja  va 2 s.  co  m*/
        public boolean evaluate(Object object) {
            // TODO Auto-generated method stub
            return MatchRule(browserInfo, (BrowserRule) object);
        }
    });
    if (_rules != null && !_rules.isEmpty()) {
        java.util.Collections.sort(_rules, new Comparator<BrowserRule>() {
            @Override
            public int compare(BrowserRule o1, BrowserRule o2) {
                return Integer.compare(o1.getPriority(), o2.getPriority());
            }

        });
        return _rules;
    } else {
        return null;
    }
}

From source file:com.jivesoftware.os.upena.shared.Instance.java

@Override
public int compareTo(Instance o) {
    int c = clusterKey.compareTo(o.clusterKey);
    if (c != 0) {
        return c;
    }/*from  ww w.  j  av a 2s . c  o  m*/
    c = hostKey.compareTo(o.hostKey);
    if (c != 0) {
        return c;
    }
    c = serviceKey.compareTo(o.serviceKey);
    if (c != 0) {
        return c;
    }
    c = releaseGroupKey.compareTo(o.releaseGroupKey);
    if (c != 0) {
        return c;
    }
    c = Integer.compare(instanceId, o.instanceId);
    if (c != 0) {
        return c;
    }
    return c;
}

From source file:org.darkware.wpman.data.WPUser.java

@Override
public int compareTo(final WPUser o) {
    return Integer.compare(this.id, o.id);
}

From source file:org.apache.ranger.plugin.geo.RangerGeolocationData.java

@Override
public int compareTo(final RangerGeolocationData other) {
    int ret = (other == null) ? 1 : 0;
    if (ret == 0) {
        ret = Long.compare(fromIPAddress, other.fromIPAddress);
        if (ret == 0) {
            ret = Long.compare(toIPAddress, other.toIPAddress);
            if (ret == 0) {
                ret = Integer.compare(locationData.length, other.locationData.length);
                for (int i = 0; ret == 0 && i < locationData.length; i++) {
                    ret = stringCompareTo(locationData[i], other.locationData[i]);
                }/*from w  ww  .  j  ava  2 s  .  c o m*/
            }
        }
    }
    return ret;
}