List of usage examples for java.lang Integer compareTo
public int compareTo(Integer anotherInteger)
From source file:org.b3log.solo.util.comparator.TagRefCntComparator.java
@Override public int compare(final JSONObject tag1, final JSONObject tag2) { try {/* w ww .j a va 2 s . c o m*/ final Integer refCnt1 = tag1.getInt(Tag.TAG_REFERENCE_COUNT); final Integer refCnt2 = tag2.getInt(Tag.TAG_REFERENCE_COUNT); return refCnt1.compareTo(refCnt2); } catch (final Exception e) { throw new IllegalStateException(e); } }
From source file:org.jdal.util.comparator.AlphaNumericComparator.java
/** * {@inheritDoc}//from w w w . java 2 s . c o m */ public int compare(String o1, String o2) { try { Pattern pattern = Pattern.compile("([0-9]+)"); Matcher matcher1 = pattern.matcher(o1); Matcher matcher2 = pattern.matcher(o2); if ((matcher1.find() && matcher2.find()) && o1.startsWith(o2.substring(0, matcher2.start()))) { // two strings have numbers, and same prefix. // use numeric comparation Integer n1 = Integer.valueOf(matcher1.group()); Integer n2 = Integer.valueOf(matcher2.group()); return n1.compareTo(n2); } // else return string comparation return o1.compareToIgnoreCase(o2); } catch (Exception e) { log.error(e); } return 0; // On Exception object are equals }
From source file:org.kuali.test.comparators.SqlHierarchyComparator.java
@Override public int compare(TableData o1, TableData o2) { int retval = 0; if (StringUtils.isBlank(o1.getForeignKeyName())) { retval = -1;//from w w w. jav a2 s . c o m } else if (StringUtils.isBlank(o2.getForeignKeyName())) { retval = 1; } else { DefaultMutableTreeNode tn1 = o1.getTreeNode(); DefaultMutableTreeNode tn2 = o2.getTreeNode(); if ((tn1 != null) && (tn2 != null)) { Integer i1 = Integer.valueOf(tn1.getLevel()); Integer i2 = Integer.valueOf(tn2.getLevel()); retval = i1.compareTo(i2); } if (retval == 0) { retval = o1.getName().compareTo(o2.getName()); } } return retval; }
From source file:com.sunchenbin.store.feilong.core.util.comparator.RegexGroupNumberComparator.java
public int compare(String s1, String s2) { String group1 = RegexUtil.group(regexPattern, s1, 1); String group2 = RegexUtil.group(regexPattern, s2, 1); Integer parseInt = Integer.parseInt(group1); Integer parseInt2 = Integer.parseInt(group2); return parseInt.compareTo(parseInt2); }
From source file:org.protempa.SimpleGapFunction.java
/** * Sets the the gap function's maximum gap value. A value of * <code>null</code> means any gap. * * @param maximumGap the maximum gap {@link Integer}. Must be non-negative. * If set to zero, the gap function always will return <code>false</code>. *///w w w.j a v a 2 s .c o m public void setMaximumGap(Integer maximumGap) { if (maximumGap != null && maximumGap.compareTo(ZERO) < 0) { throw new IllegalArgumentException("maximumGap must be null or >= 0"); } Integer old = this.maximumGap; this.maximumGap = maximumGap; initRelation(); this.changes.firePropertyChange("maximumGap", old, this.maximumGap); }
From source file:com.feilong.core.util.comparator.RegexGroupNumberComparator.java
@Override public int compare(String s1, String s2) { String group1 = RegexUtil.group(regexPattern, s1, 1); String group2 = RegexUtil.group(regexPattern, s2, 1); Integer parseInt = Integer.parseInt(group1); Integer parseInt2 = Integer.parseInt(group2); return parseInt.compareTo(parseInt2); }
From source file:ips1ap101.lib.base.util.StrUtils.java
public static boolean esObjetoEnRango(Object objeto, Object minimo, Object maximo) { boolean es = true; // EnumTipoDatoParametro tipo; if (objeto == null) { return false; } else if (objeto instanceof String) { // tipo = EnumTipoDatoParametro.ALFANUMERICO; String val1 = (String) objeto; String min1 = (String) minimo; String max1 = (String) maximo; if (min1 != null && val1.compareTo(min1) < 0) { es = false;//from ww w . j a v a 2 s . com } if (max1 != null && val1.compareTo(max1) > 0) { es = false; } } else if (objeto instanceof Integer) { // tipo = EnumTipoDatoParametro.ENTERO; Integer val4 = (Integer) objeto; Integer min4 = (Integer) minimo; Integer max4 = (Integer) maximo; if (min4 != null && val4.compareTo(min4) < 0) { es = false; } if (max4 != null && val4.compareTo(max4) > 0) { es = false; } } else if (objeto instanceof Long || objeto instanceof BigInteger) { // tipo = EnumTipoDatoParametro.ENTERO_GRANDE; Long val5 = objeto instanceof BigInteger ? ((BigInteger) objeto).longValue() : (Long) objeto; Long min5 = (Long) minimo; Long max5 = (Long) maximo; if (min5 != null && val5.compareTo(min5) < 0) { es = false; } if (max5 != null && val5.compareTo(max5) > 0) { es = false; } } else if (objeto instanceof BigDecimal) { // tipo = EnumTipoDatoParametro.NUMERICO; BigDecimal val2 = (BigDecimal) objeto; BigDecimal min2 = (BigDecimal) minimo; BigDecimal max2 = (BigDecimal) maximo; if (min2 != null && val2.compareTo(min2) < 0) { es = false; } if (max2 != null && val2.compareTo(max2) > 0) { es = false; } } else if (objeto instanceof Timestamp) { // tipo = EnumTipoDatoParametro.FECHA_HORA; Timestamp val3 = (Timestamp) objeto; Timestamp min3 = (Timestamp) minimo; Timestamp max3 = (Timestamp) maximo; if (min3 != null && val3.compareTo(min3) < 0) { es = false; } if (max3 != null && val3.compareTo(max3) > 0) { es = false; } } else { return false; } return es; }
From source file:org.powerassert.synthetic.ExpressionRenderer.java
private Iterable<RecordedValue> filterAndSortByAnchor(List<RecordedValue> recordedValues) { Map<Integer, RecordedValue> map = new TreeMap<>(new Comparator<Integer>() { @Override/* ww w. j a va2s.c om*/ public int compare(Integer n1, Integer n2) { return n2.compareTo(n1); } }); for (RecordedValue value : recordedValues) { if (!map.containsKey(value.getAnchor())) map.put(value.getAnchor(), value); } return map.values(); }
From source file:com.apress.prospringintegration.channels.prioritychannel.TicketMessagePriorityComparator.java
@Override public int compare(Message<Ticket> message1, Message<Ticket> message2) { Integer priority1 = message1.getPayload().getPriority().ordinal(); Integer priority2 = message2.getPayload().getPriority().ordinal(); priority1 = priority1 != null ? priority1 : 0; priority2 = priority2 != null ? priority2 : 0; return priority2.compareTo(priority1); }
From source file:org.protempa.SimpleGapFunction.java
/** * Initializes a gap function with a maximum gap and units. * /*from www . j av a 2 s. c o m*/ * @param maximumGap the maximum gap {@link Integer}. Must be non-negative. * If set to zero, the gap function always will return <code>false</code>. * @param maximumGapUnit a {@link Unit}. A value of <code>null</code> is * defined by the {@link Granularity} of the data. */ public SimpleGapFunction(Integer maximumGap, Unit maximumGapUnit) { if (maximumGap != null && maximumGap.compareTo(ZERO) < 0) { throw new IllegalArgumentException("maximumGap must be null or >= 0"); } this.maximumGapUnits = maximumGapUnit; this.maximumGap = maximumGap; initRelation(); this.changes = new PropertyChangeSupport(this); }