Example usage for java.lang Integer compareTo

List of usage examples for java.lang Integer compareTo

Introduction

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

Prototype

public int compareTo(Integer anotherInteger) 

Source Link

Document

Compares two Integer objects numerically.

Usage

From source file:org.protempa.backend.dsb.file.AbstractFileDataSourceBackend.java

@BackendProperty
@Override/* w  w  w  .j  a  v a2 s.  co  m*/
public void setSkipLines(Integer skipLines) {
    if (skipLines == null || skipLines.compareTo(0) < 0) {
        this.skipLines = 0;
    } else {
        this.skipLines = skipLines;
    }
}

From source file:org.apache.tajo.validation.MaxValidator.java

@Override
protected <T> boolean validateInternal(T object) {
    boolean result = false;

    if (object != null) {
        if ((object instanceof Byte) || (object instanceof Short) || (object instanceof Integer)) {
            Integer objInteger = Integer.decode(object.toString());
            Integer maxInteger = Integer.decode(maxValue);
            result = objInteger.compareTo(maxInteger) <= 0;
        } else if (object instanceof Long) {
            Long objLong = Long.decode(object.toString());
            Long maxLong = Long.decode(maxValue);
            result = objLong.compareTo(maxLong) <= 0;
        } else if ((object instanceof Float) || (object instanceof Double)) {
            Double objDouble = Double.valueOf(object.toString());
            Double maxDouble = Double.valueOf(maxValue);
            result = objDouble.compareTo(maxDouble) <= 0;
        } else if (object instanceof BigInteger) {
            BigInteger objInteger = (BigInteger) object;
            BigInteger maxInteger = new BigInteger(maxValue);
            result = objInteger.compareTo(maxInteger) <= 0;
        } else if (object instanceof BigDecimal) {
            BigDecimal objDecimal = (BigDecimal) object;
            BigDecimal maxDecimal = new BigDecimal(maxValue);
            result = objDecimal.compareTo(maxDecimal) <= 0;
        }/*ww w  . jav a  2s  . c o m*/
    } else {
        result = true;
    }

    return result;
}

From source file:org.openmrs.module.laboratoryapp.util.ParameterModel.java

public int compareTo(ParameterModel otherParameterModel) {
    if (otherParameterModel.getContainerId() == null)
        return 1;
    if (this.getContainerId() == null)
        return -1;
    Integer thisContainerId = containerId;
    Integer otherContainerId = otherParameterModel.getContainerId();
    return thisContainerId.compareTo(otherContainerId);
}

From source file:org.apache.tajo.validation.MinValidator.java

@Override
protected <T> boolean validateInternal(T object) {
    boolean result = false;

    if (object != null) {
        if ((object instanceof Byte) || (object instanceof Short) || (object instanceof Integer)) {
            Integer objInteger = Integer.decode(object.toString());
            Integer minInteger = Integer.decode(minValue);
            result = objInteger.compareTo(minInteger) >= 0;
        } else if (object instanceof Long) {
            Long objLong = Long.decode(object.toString());
            Long minLong = Long.decode(minValue);
            result = objLong.compareTo(minLong) >= 0;
        } else if ((object instanceof Float) || (object instanceof Double)) {
            Double objDouble = Double.valueOf(object.toString());
            Double minDouble = Double.valueOf(minValue);
            result = objDouble.compareTo(minDouble) >= 0;
        } else if (object instanceof BigInteger) {
            BigInteger objInteger = (BigInteger) object;
            BigInteger minInteger = new BigInteger(minValue);
            result = objInteger.compareTo(minInteger) >= 0;
        } else if (object instanceof BigDecimal) {
            BigDecimal objDecimal = (BigDecimal) object;
            BigDecimal minDecimal = new BigDecimal(minValue);
            result = objDecimal.compareTo(minDecimal) >= 0;
        } else if (object instanceof String) {
            BigDecimal objDecimal = new BigDecimal((String) object);
            BigDecimal minDecimal = new BigDecimal(minValue);
            result = objDecimal.compareTo(minDecimal) >= 0;
        }/*ww w.j  ava  2 s.c o m*/
    } else {
        result = true;
    }

    return result;
}

From source file:TableSortDemo.java

public int compare(Object o1, Object o2) {
    if (!(o1 instanceof Integer) || !(o2 instanceof Integer))
        return 0;
    Integer s1 = (Integer) o1;
    Integer s2 = (Integer) o2;
    int result = 0;
    result = s1.compareTo(s2);
    if (!isSortAsc)
        result = -result;//from   ww w . java2s  .  c  om
    return result;
}

From source file:org.drugis.mtc.graph.AbsoluteOneCenterTest.java

private Comparator<Integer> intComparator() {
    final Comparator<Integer> comparator = new Comparator<Integer>() {
        public int compare(final Integer o1, final Integer o2) {
            return o1.compareTo(o2);
        }//from   ww w.ja  va 2  s  .  c  o  m
    };
    return comparator;
}

From source file:SortByHouseNo.java

@Override
public int compare(HouseNo o1, HouseNo o2) {
    Integer first = Integer.valueOf(o1.getHouseno());
    Integer second = Integer.valueOf(o2.getHouseno());

    Integer f1 = Integer.valueOf(o1.getBlockno());
    Integer f2 = Integer.valueOf(o2.getBlockno());

    if (first.compareTo(second) == 0) {
        return f1.compareTo(f2);
    }//from   w  ww  . j  ava  2 s  .c  o  m
    return first.compareTo(second);
}

From source file:org.apache.james.imap.processor.GetAnnotationProcessor.java

private Optional<Integer> getMaxSizeOfOversizedItems(List<MailboxAnnotation> mailboxAnnotations,
        final Integer maxsize) {
    Predicate<MailboxAnnotation> filterOverSizedAnnotation = new Predicate<MailboxAnnotation>() {
        @Override/*  w  ww.  j  a  v a 2s  . c om*/
        public boolean apply(MailboxAnnotation input) {
            return (input.size() > maxsize);
        }
    };

    Function<MailboxAnnotation, Integer> transformToSize = new Function<MailboxAnnotation, Integer>() {
        public Integer apply(MailboxAnnotation input) {
            return input.size();
        }
    };

    ImmutableSortedSet<Integer> overLimitSizes = FluentIterable.from(mailboxAnnotations)
            .filter(filterOverSizedAnnotation).transform(transformToSize)
            .toSortedSet(new Comparator<Integer>() {
                @Override
                public int compare(Integer annotationSize1, Integer annotationSize2) {
                    return annotationSize2.compareTo(annotationSize1);
                }
            });

    if (overLimitSizes.isEmpty()) {
        return Optional.absent();
    }
    return Optional.of(overLimitSizes.first());
}

From source file:org.kuali.student.r2.core.scheduling.dao.TimeSlotDao.java

public String getCurrentMaxTimeSlotCode() {
    Query query = em.createNamedQuery("TimeSlotEntity.GetTimeSlotNames");
    List timeSlotNames = query.getResultList();
    int size = timeSlotNames.size();

    if (size > 0) {
        Collections.sort(timeSlotNames, new Comparator() {
            @Override/*www . j av  a2 s . c o m*/
            public int compare(Object o1, Object o2) {

                Integer n1 = Integer.parseInt(o1.toString());
                Integer n2 = Integer.parseInt(o2.toString());
                return n1.compareTo(n2);
            }
        });

        return timeSlotNames.get(size - 1).toString();
    } else {
        return "0";
    }

}

From source file:biz.webgate.dominoext.poi.component.kernel.CSVProcessor.java

public ByteArrayOutputStream generateCSV(UICSV csvDef, FacesContext context) throws IOException, POIException {
    ByteArrayOutputStream csvBAOS = new ByteArrayOutputStream();
    OutputStreamWriter csvWriter = new OutputStreamWriter(csvBAOS);
    CSVPrinter csvPrinter = new CSVPrinter(csvWriter, CSVFormat.DEFAULT);

    List<CSVColumn> lstColumns = csvDef.getColumns();
    Collections.sort(lstColumns, new Comparator<CSVColumn>() {

        public int compare(CSVColumn o1, CSVColumn o2) {
            Integer p1 = Integer.valueOf(o1.getPosition());
            Integer p2 = Integer.valueOf(o2.getPosition());
            return p1.compareTo(p2);
        }//  w w  w  .j a v a 2s  .co  m

    });
    if (csvDef.isIncludeHeader()) {
        for (CSVColumn cl : lstColumns) {
            csvPrinter.print(cl.getTitle());
        }
        csvPrinter.println();
    }

    // DATASOURCE holen und verarbeiten.
    if (csvDef.getDataSource() != null) {
        EmbeddedDataSourceExportProcessor.getInstance().process(lstColumns, csvDef, csvPrinter, context);
    } else {
        XPagesDataSourceExportProcessor.getInstance().process(lstColumns, csvDef, csvPrinter, context);
    }

    csvPrinter.flush();
    return csvBAOS;
}