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:gov.nih.nci.ncicb.cadsr.bulkloader.util.excel.DBExcelUtility.java

public boolean compareExcelRow(ExcelRow erow, ArrayList cmp, String coltype[]) throws Exception {
    int numberOfColumns = coltype.length;
    short col = 0;
    boolean nodata = true;
    Object data[] = erow.getData();

    for (int i = 0; i < numberOfColumns; i++) {
        Object odata = (Object) cmp.get(i);

        if (data[i] == null && odata == null) {
            continue;
        }/*from   w w  w .  j  av a 2 s  .  c  om*/
        if ((data[i] == null && odata != null) || (data[i] != null && odata == null)) {
            return false;
        }

        if (coltype[i].equalsIgnoreCase(DataType.TYPE_STRING)) {
            String cdata = (String) cmp.get(i);

            if (!cdata.equalsIgnoreCase((String) data[i])) {
                return false;
            }
        } else if (coltype[i].equalsIgnoreCase(DataType.TYPE_INTEGER)) {
            Integer idata = (Integer) cmp.get(i);
            Integer cidata = (Integer) data[i];

            if (idata.compareTo(cidata) != 0) {
                return false;
            }
        } else if (coltype[i].equalsIgnoreCase(DataType.TYPE_DOUBLE)) {
            Double ddata = (Double) cmp.get(i);
            Double cddata = (Double) data[i];

            if (ddata.compareTo(cddata) != 0) {
                return false;
            }
        } else if (coltype[i].equalsIgnoreCase(DataType.TYPE_BOOLEAN)) {
            Boolean bdata = (Boolean) cmp.get(i);
            Boolean cbdata = (Boolean) data[i];

            if (bdata.booleanValue() != cbdata.booleanValue()) {
                return false;
            }
        } else if (coltype[i].equalsIgnoreCase(DataType.TYPE_DATE)) {
            Date dtval = (Date) cmp.get(i);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            //Date cdtval = sdf.parse(data[i]);
            Date cdtval = (Date) data[i];

            Calendar cal1 = Calendar.getInstance();
            Calendar cal2 = Calendar.getInstance();

            cal1.setTime(dtval);
            cal2.setTime(cdtval);
            if (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR)
                    || cal1.get(Calendar.MONTH) != cal2.get(Calendar.MONTH)
                    || cal1.get(Calendar.DATE) != cal2.get(Calendar.DATE)) {
                return false;
            }
        }
    }
    return true;
}

From source file:be.docarch.odt2braille.PEF.java

/**
 * Split a single PEF file into several files, one file per volume.
 *//*www . j  a v a2s . c om*/
private File[] splitPEF() {

    logger.entering("PEF", "splitPEF");

    File input = pefFile;
    File output = new File(input.getAbsolutePath() + "-split");
    output.mkdir();

    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
    {

        PEFFileSplitter splitter = new PEFFileSplitter();
        splitter.split(input, output);

    }
    Thread.currentThread().setContextClassLoader(cl);

    File[] pefs = output.listFiles();
    Arrays.sort(pefs, new Comparator<File>() {
        public int compare(File f1, File f2) {
            String n1 = f1.getName();
            String n2 = f2.getName();
            Integer i1 = Integer.parseInt(n1.substring(n1.lastIndexOf('-') + 1, n1.length() - 4));
            Integer i2 = Integer.parseInt(n2.substring(n2.lastIndexOf('-') + 1, n2.length() - 4));
            return i1.compareTo(i2);
        }
    });
    return pefs;
}

From source file:at.tugraz.sss.servs.kcprojwiki.impl.SSKCProjWikiImportCommons.java

private void parseUpdateResponse(final HttpResponse response, final String pageTitle) throws SSErr {

    InputStream in = null;/*from  ww w  . j ava 2s. com*/

    try {

        JSONObject json;
        JSONObject edit;
        String strResult;

        in = response.getEntity().getContent();
        json = new JSONObject(SSFileU.readStreamText(in));

        try {
            edit = (JSONObject) json.get(SSMediaWikiLangE.edit.toString());
        } catch (Exception error) {

            SSLogU.debug(error);

            JSONObject jsonResult = (JSONObject) json.get(SSMediaWikiLangE.result.toString());
            Integer code = Integer.valueOf((String) jsonResult.get(SSMediaWikiLangE.code.toString()));

            if (code.compareTo(200) != 0) {
                SSServErrReg.regErrThrow(SSErrE.mediaWikiParseUpdateResponseFailed);
                return;
            }

            return;
        }

        strResult = (String) edit.get(SSMediaWikiLangE.result.toString());

        if (!SSStrU.isEqual(strResult, SSMediaWikiLangE.Success.toString())) {
            SSServErrReg.regErrThrow(SSErrE.mediaWikiParseUpdateResponseFailed);
            return;
        }

    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ex) {
                SSLogU.err(ex);
            }
        }
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.LockboxLoadServiceImpl.java

protected boolean compareDetailsWithHeader(Lockbox lockbox) {
    boolean isHeaderMatchedDetails = true;
    KualiDecimal headerTransBatchTotal = lockbox.getHeaderTransactionBatchTotal();
    Integer headerTransBatchCount = lockbox.getHeaderTransactionBatchCount();
    KualiDecimal detailInvPaidTotal = new KualiDecimal(0);
    Integer totalDetailRecords = 0;
    for (LockboxDetail detail : lockbox.getLockboxDetails()) {
        detailInvPaidTotal = detailInvPaidTotal.add(detail.getInvoicePaidOrAppliedAmount());
        totalDetailRecords++;/*from w  ww  .j a  v a2s.c  o  m*/
    }

    if (headerTransBatchTotal.compareTo(detailInvPaidTotal) == 0
            && headerTransBatchCount.compareTo(totalDetailRecords) == 0) {

        String message = "Good Transfer for lockbox number " + lockbox.getLockboxNumber() + "."
                + " Transaction count : " + lockbox.getHeaderTransactionBatchCount()
                + " Transaction total amount : $ " + lockbox.getHeaderTransactionBatchTotal();
        lockbox.getFlatFileTransactionInformation().addInfoMessage(message);
        GlobalVariables.getMessageMap().putInfo(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_CUSTOM,
                message);

    }

    if (headerTransBatchTotal.compareTo(detailInvPaidTotal) != 0) {
        String message = "Bad Transmmission for lock box number " + lockbox.getLockboxNumber() + "."
                + " Detail does not match header control values " + " Header total : $ "
                + lockbox.getHeaderTransactionBatchTotal() + " Detail total : $ " + detailInvPaidTotal;
        lockbox.getFlatFileTransactionInformation().addErrorMessage(message);
        GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_CUSTOM,
                message);
        isHeaderMatchedDetails = false;
    }

    if (headerTransBatchCount.compareTo(totalDetailRecords) != 0) {
        String message = "Bad Transmmission for lock box number " + lockbox.getLockboxNumber() + "."
                + " Detail does not match header control values " + " Header Count : "
                + lockbox.getHeaderTransactionBatchCount() + " Detail total : " + totalDetailRecords;
        lockbox.getFlatFileTransactionInformation().addErrorMessage(message);
        GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.ERROR_CUSTOM,
                message);
        isHeaderMatchedDetails = false;
    }

    return isHeaderMatchedDetails;

}

From source file:com.kylinolap.metadata.model.cube.CubeDesc.java

private void sortDimensionsByID() {
    Collections.sort(dimensions, new Comparator<DimensionDesc>() {
        @Override//from w  w w.  j  ava 2s . com
        public int compare(DimensionDesc d1, DimensionDesc d2) {
            Integer id1 = d1.getId();
            Integer id2 = d2.getId();
            return id1.compareTo(id2);
        }
    });
}

From source file:com.kylinolap.metadata.model.cube.CubeDesc.java

private void sortMeasuresByID() {
    if (measures == null) {
        measures = Lists.newArrayList();
    }/*ww w.  j ava2 s . c o  m*/

    Collections.sort(measures, new Comparator<MeasureDesc>() {
        @Override
        public int compare(MeasureDesc m1, MeasureDesc m2) {
            Integer id1 = m1.getId();
            Integer id2 = m2.getId();
            return id1.compareTo(id2);
        }
    });
}

From source file:edu.harvard.med.screensaver.io.screenresults.ScreenResultParser.java

private void recordAssayPlatesDataLoaded(Well well, int replicateCount) {
    Integer maxReplicateCount = _plateNumbersLoadedWithMaxReplicates.get(well.getPlateNumber());
    if (maxReplicateCount == null || maxReplicateCount.compareTo(replicateCount) < 0) {
        _plateNumbersLoadedWithMaxReplicates.put(well.getPlateNumber(), replicateCount);
    }/*from   w  ww .j a  va 2s .  c  o m*/
}

From source file:org.projectforge.business.timesheet.TimesheetDao.java

private boolean contains(final List<Kost2DO> kost2List, final Integer kost2Id) {
    for (final Kost2DO entry : kost2List) {
        if (kost2Id.compareTo(entry.getId()) == 0) {
            return true;
        }//  w w w .  j a v  a 2s . c  o  m
    }
    return false;
}

From source file:ca.on.gov.jus.icon.common.util.LookupNestedMapHandler.java

/**
 * Iterates through the query result set and creates a correctly
 * indexed map of maps.  This is only intended to work with a result
 * set that contains three columns and the first column must
 * cast successfully to a <code>Integer</code> datatype.
 * /*from   w w w . j a v a2s  . com*/
 * @param   rs      The result set that is used to obtain the name/value data.
 * @return   Object   The <code>java.util.Map</code> collection containing the results. 
 * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet)
 */
public Object handle(ResultSet rs) throws SQLException {
    Map results = new HashMap();
    Map nestedMap = new HashMap();
    Integer currentId = null;

    // Get the number of columns in the result set.
    ResultSetMetaData rsmd = rs.getMetaData();
    int cols = rsmd.getColumnCount();

    // Populate the Map with the name value pairs
    // if the result set contains two columns of data.
    if (cols == MAP_RESULT_SET_COLUMNS) {
        while (rs.next()) {
            Object primaryId = rs.getObject(1);
            Object secondaryId = rs.getObject(2);
            Object secondaryValue = rs.getObject(3);

            // Initialize the current id on the first iteration.
            if (currentId == null) {
                currentId = (Integer) primaryId;
            }

            // Check if the primary id is not the same as the current id.         
            if (currentId.compareTo(primaryId) != 0) {
                // Put the current nested map into the result map
                // and create a new nested map.
                results.put(currentId, nestedMap);
                nestedMap = new HashMap();
                currentId = (Integer) primaryId;
            }

            // Put the key & value into the current nested map.
            // This occurs after checking if a new nested map is required.
            nestedMap.put(secondaryId, secondaryValue);
        }

        // Put the final nested map into the results map
        // once the iterations are complete.
        results.put(currentId, nestedMap);
    }

    return results;
}

From source file:com.kylinolap.metadata.model.cube.CubeDesc.java

private void sortHierarchiesByLevel(HierarchyDesc[] hierarchies) {
    if (hierarchies != null) {
        Arrays.sort(hierarchies, new Comparator<HierarchyDesc>() {
            @Override/* www. j ava 2 s. c  om*/
            public int compare(HierarchyDesc h1, HierarchyDesc h2) {
                Integer level1 = Integer.parseInt(h1.getLevel());
                Integer level2 = Integer.parseInt(h2.getLevel());
                return level1.compareTo(level2);
            }
        });
    }
}