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.LowLevelAbstractionDefinition.java

public final void setMaximumDuration(Integer maxDuration) {
    if (maxDuration != null && maxDuration.compareTo(0) < 0) {
        this.maximumDuration = 0;
    } else {/*from ww  w  .  j  a  v  a2  s  .  c  om*/
        this.maximumDuration = maxDuration;
    }
}

From source file:org.openmrs.module.haitimobileclinic.service.db.HibernateHaitiMobileClinicDAO.java

public List<DuplicatePatient> getDuplicatePatients(Patient patient) {
    List<DuplicatePatient> duplicatePatients = null;
    if (patient != null && patient.getId() != null && (patient.getBirthdate() != null)) {
        Calendar birthdate = Calendar.getInstance();
        birthdate.setTime(patient.getBirthdate());
        Integer birthYear = new Integer(birthdate.get(Calendar.YEAR));
        Integer intervalYear = HaitiMobileClinicGlobalProperties.GLOBAL_PROPERTY_BIRTH_YEAR_INTERVAL();
        Integer minYear = new Integer(birthYear.intValue() - intervalYear.intValue());
        if (minYear.intValue() < 0) {
            minYear = 0;/*from   w  w  w .  jav  a 2s. co m*/
        }
        PatientIdentifierType zlIdentifierType = HaitiMobileClinicGlobalProperties
                .GLOBAL_PROPERTY_PRIMARY_IDENTIFIER_TYPE();
        PatientIdentifierType dossierType = HaitiMobileClinicGlobalProperties.GLOBAL_PROPERTY_NUMERO_DOSSIER();
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT s.person_id as PatientId, ");
        sql.append("n.given_name as FirstName, n.family_name as LastName, ");
        sql.append("s.gender as Gender, s.birthdate as Birthdate, ");
        sql.append("a.address1 as Address1, ");
        sql.append("a.city_village as Commune, s.date_created as PersonDateCreated, ");
        if (zlIdentifierType != null) {
            sql.append("id1.identifier as ZLEMRID, ");
        }
        if (dossierType != null) {
            sql.append("id3.identifier as NimewoDosye, ");
        }
        sql.append("Min(e.date_created) as FirstEncounterDate ");
        sql.append("FROM person as s JOIN person_name as n ON (s.person_id=n.person_id) ");
        sql.append("LEFT JOIN person_address as a ON (s.person_id = a.person_id) ");
        if (zlIdentifierType != null) {
            sql.append(
                    "LEFT JOIN patient_identifier as id1 ON (s.person_id = id1.patient_id and id1.identifier_type=")
                    .append(zlIdentifierType.getId().intValue()).append(") ");
        }
        if (dossierType != null) {
            sql.append(
                    "LEFT JOIN patient_identifier as id3 ON (s.person_id = id3.patient_id and id3.identifier_type=")
                    .append(dossierType.getId().intValue()).append(") ");
        }
        sql.append("LEFT outer JOIN encounter as e ON (s.person_id = e.patient_id) ");
        sql.append("WHERE s.voided=0 and n.voided=0 and n.given_name=\"").append(patient.getGivenName())
                .append("\" ");
        sql.append("AND n.family_name=\"").append(patient.getFamilyName()).append("\" ");
        sql.append("AND YEAR(s.birthdate) BETWEEN ").append(minYear.toString()).append(" AND ")
                .append(birthYear.intValue() + intervalYear.intValue()).append(" ");
        if (patient.getPersonAddress() != null) {
            String cityVillage = patient.getPersonAddress().getCityVillage();
            if (StringUtils.isNotBlank(cityVillage)) {
                sql.append("AND ((a.city_village is null) OR TRIM(a.city_village)='' OR (a.city_village=\"")
                        .append(cityVillage).append("\")) ");
            }
        }
        sql.append("GROUP BY PatientId ");
        sql.append("ORDER BY PatientId, PersonDateCreated, FirstEncounterDate");

        List<List<Object>> queryResults = Context.getAdministrationService().executeSQL(sql.toString(), true);
        if (queryResults != null && queryResults.size() > 0) {
            duplicatePatients = new ArrayList<DuplicatePatient>();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat bdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = null;
            Object fieldValue = null;
            for (List<Object> row : queryResults) {
                Integer patientId = Integer.parseInt(row.get(0).toString());
                if (patientId.compareTo(patient.getId()) == 0) {
                    continue;
                }

                DuplicatePatient duplicatePatient = new DuplicatePatient();
                duplicatePatient.setPatientId(patientId);
                duplicatePatient.setFirstName(row.get(1).toString());
                duplicatePatient.setLastName(row.get(2).toString());
                duplicatePatient.setGender(row.get(3).toString());
                try {
                    date = bdf.parse(row.get(4).toString());
                    if (date != null) {
                        duplicatePatient.setBirthdate(date);
                    }
                } catch (ParseException e) {
                    log.error("failed to parse date", e);
                }
                fieldValue = row.get(5);
                if (fieldValue != null) {
                    duplicatePatient.setAddress1(fieldValue.toString());
                }
                fieldValue = row.get(6);
                if (fieldValue != null) {
                    duplicatePatient.setCityVillage(fieldValue.toString());
                }
                fieldValue = row.get(7);
                if (fieldValue != null) {
                    try {
                        date = sdf.parse(fieldValue.toString());
                        if (date != null) {
                            duplicatePatient.setPersonDateCreated(date);
                        }
                    } catch (ParseException e) {
                        log.error("failed to parse date", e);
                    }
                }
                fieldValue = row.get(8);
                if (fieldValue != null) {
                    duplicatePatient.setZlEmrId(fieldValue.toString());
                }
                // mobile clinics doesnt have this
                //               fieldValue = row.get(9); 
                //               if(fieldValue!=null){
                //                  duplicatePatient.setDossierNumber(fieldValue.toString());
                //               }
                fieldValue = row.get(9);
                if (fieldValue != null) {
                    try {
                        date = sdf.parse(fieldValue.toString());
                        if (date != null) {
                            duplicatePatient.setFirstEncounterDate(date);
                        }
                    } catch (ParseException e) {
                        log.error("failed to parse date", e);
                    }
                }

                duplicatePatients.add(duplicatePatient);
            }
        }

    }
    return duplicatePatients;
}

From source file:org.kuali.coeus.propdev.impl.person.ProposalDevelopmentPersonnelController.java

private void deleteProposalPersonBios(DevelopmentProposal proposal, ProposalPerson deleteLine) {
    List<ProposalPersonBiography> tmpBios = new ArrayList<>();
    String personIdOfDeletedLine = deleteLine.getPersonId();
    for (ProposalPersonBiography biography : proposal.getPropPersonBios()) {
        if (personIdOfDeletedLine == null) {
            Integer rolodexId = deleteLine.getRolodexId();
            if (biography.getRolodexId() == null || rolodexId.compareTo(biography.getRolodexId()) != 0) {
                tmpBios.add(biography);//from w  w w  . j a v a 2  s  .  co m
            }
        } else {
            if (!biography.getPersonId().equals(personIdOfDeletedLine))
                tmpBios.add(biography);
        }
    }
    proposal.setPropPersonBios(tmpBios);
}

From source file:ar.edu.famaf.nlp.alusivo.GraphAlgorithm.java

private Pair<DirectedPseudograph<Resource, Edge>, Double> findGraph(URI referent,
        DirectedPseudograph<Resource, Edge> fullGraph, DirectedPseudograph<Resource, Edge> bestGraph,
        double bestGraphCost, DirectedPseudograph<Resource, Edge> candidate, long startTime,
        final Map<String, Integer> mappedOrder) throws ReferringExpressionException {
    double candidateCost = cost(candidate);
    if (bestGraph != null && bestGraphCost <= candidateCost)
        return Pair.of(bestGraph, bestGraphCost);

    List<Resource> distractors = new ArrayList<Resource>(fullGraph.vertexSet().size());
    for (Resource v : fullGraph.vertexSet()) {
        if (System.currentTimeMillis() - startTime > maxTime)
            throw new ReferringExpressionException("Time-out");
        if (v != referent && matchGraphs(referent, candidate, v, fullGraph, startTime))
            distractors.add(v);/* w  w  w. ja  v  a 2 s.  c om*/
    }

    if (distractors.isEmpty())
        return Pair.of(candidate, candidateCost);

    Collection<Edge> neighbors = neighbors(candidate, fullGraph);
    if (mappedOrder != null) {
        List<Edge> toSort = new ArrayList<Edge>(neighbors);

        Collections.sort(toSort, new Comparator<Edge>() {
            public int compare(Edge e1, Edge e2) {
                Integer m1 = mappedOrder.get(e1.getURI().getLocalName());
                Integer m2 = mappedOrder.get(e2.getURI().getLocalName());
                if (m1 != null && m2 != null)
                    return m1.compareTo(m2);
                if (m1 != null)
                    return -1;
                if (m2 != null)
                    return 1;
                return e1.getURI().toString().compareTo(e2.getURI().toString());
            }
        });
        neighbors = toSort;
    }
    for (Edge e : neighbors) {
        if (System.currentTimeMillis() - startTime > maxTime)
            throw new ReferringExpressionException("Time-out");

        @SuppressWarnings("unchecked")
        DirectedPseudograph<Resource, Edge> newCandidate = (DirectedPseudograph<Resource, Edge>) candidate
                .clone();
        Resource source = fullGraph.getEdgeSource(e);
        Resource target = fullGraph.getEdgeTarget(e);
        if (!newCandidate.vertexSet().contains(source))
            // odd, this shouldn't always be the case?
            newCandidate.addVertex(source);
        if (!newCandidate.vertexSet().contains(target))
            newCandidate.addVertex(target);
        newCandidate.addEdge(fullGraph.getEdgeSource(e), fullGraph.getEdgeTarget(e), e);
        Pair<DirectedPseudograph<Resource, Edge>, Double> p = findGraph(referent, fullGraph, bestGraph,
                bestGraphCost, newCandidate, startTime, mappedOrder);
        if (bestGraph == null || p.getRight() <= bestGraphCost) {
            bestGraph = p.getLeft();
            bestGraphCost = p.getRight();
        }
    }

    return Pair.of(bestGraph, bestGraphCost);
}

From source file:com.inmobi.conduit.purge.DataPurgerService.java

private void addMergedStreams() {
    Map<String, DestinationStream> destinationStreamMapStreamMap = cluster.getDestinationStreams();
    Set<Map.Entry<String, DestinationStream>> entrySet = destinationStreamMapStreamMap.entrySet();
    Iterator it = entrySet.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        String streamName = (String) entry.getKey();
        DestinationStream consumeStream = (DestinationStream) entry.getValue();
        Integer mergedStreamRetentionInHours = consumeStream.getRetentionInHours();

        LOG.debug("Merged Stream :: streamName [" + streamName + "] mergedStreamRetentionInHours ["
                + mergedStreamRetentionInHours + "]");
        if (streamRetention.get(streamName) == null) {
            streamRetention.put(streamName, mergedStreamRetentionInHours);
            LOG.debug("Adding Merged Stream [" + streamName + "] retentionInHours ["
                    + mergedStreamRetentionInHours + "]");
        } else {/*from  w  w w.  j a va  2s .  com*/
            // Partial & Merged stream are produced at this cluster
            // choose max retention period
            Integer partialStreamRetentionInHours = streamRetention.get(streamName);
            if (partialStreamRetentionInHours.compareTo(mergedStreamRetentionInHours) > 0) {
                streamRetention.put(streamName, partialStreamRetentionInHours);
                LOG.debug("Overriding Stream [" + streamName + "] retentionInHours ["
                        + partialStreamRetentionInHours + "]");

            } else {
                streamRetention.put(streamName, mergedStreamRetentionInHours);
                LOG.debug("Overriding Stream [" + streamName + "] retentionInHours ["
                        + mergedStreamRetentionInHours + "]");

            }

        }
    }
}

From source file:org.intermine.bio.dataconversion.TropsChipseqHistoneModConverter.java

/**
 * /*from  w w  w. j av a2 s  . c  o m*/
 * @param start
 * @param end
 * @return
 * @throws NumberFormatException
 */

private String getLength(String start, String end) throws NumberFormatException {

    Integer a = new Integer(start);
    Integer b = new Integer(end);

    // if the coordinates are on the crick strand, they need to be reversed
    // or they
    // result in a negative number
    if (a.compareTo(b) > 0) {
        a = new Integer(end);
        b = new Integer(start);
    }

    Integer length = new Integer(b.intValue() - a.intValue());
    return length.toString();
}

From source file:org.onexus.website.api.pages.browser.BrowserPageStatus.java

@Override
public void decodeParameters(PageParameters parameters, String keyPrefix) {

    StringValue currentTabId = parameters.get(keyPrefix + "tab");
    if (!currentTabId.isEmpty()) {
        this.currentTabId = currentTabId.toString();

        // Check that is a valid tabId
        if (getConfig().getTab(this.currentTabId) == null) {

            // Look for the more similar tab id
            List<TabConfig> tabs = new ArrayList<TabConfig>(getConfig().getTabs());
            Collections.sort(tabs, new Comparator<TabConfig>() {
                @Override/*www  . ja  va2s.  com*/
                public int compare(TabConfig o1, TabConfig o2) {
                    Integer v1 = StringUtils.getLevenshteinDistance(BrowserPageStatus.this.currentTabId,
                            o1.getId());
                    Integer v2 = StringUtils.getLevenshteinDistance(BrowserPageStatus.this.currentTabId,
                            o2.getId());

                    return v1.compareTo(v2);
                }
            });
            this.currentTabId = tabs.get(0).getId();
        }
    }

    StringValue currentView = parameters.get(keyPrefix + "view");
    if (!currentView.isEmpty()) {
        this.currentView = currentView.toString();

        // Check that is a valid currentView
        if (getConfig().getTab(this.currentTabId).getView(this.currentView) == null) {

            // Look for the more similar view id
            List<ViewConfig> views = new ArrayList<ViewConfig>(
                    getConfig().getTab(this.currentTabId).getViews());

            if (views.size() > 1) {
                Collections.sort(views, new Comparator<ViewConfig>() {
                    @Override
                    public int compare(ViewConfig o1, ViewConfig o2) {
                        Integer v1 = StringUtils.getLevenshteinDistance(BrowserPageStatus.this.currentView,
                                o1.getTitle());
                        Integer v2 = StringUtils.getLevenshteinDistance(BrowserPageStatus.this.currentView,
                                o2.getTitle());

                        return v1.compareTo(v2);
                    }
                });
            }

            this.currentView = views.get(0).getTitle();

        }
    }

    selections = new ArrayList<IEntitySelection>();
    List<StringValue> values = parameters.getValues(keyPrefix + "f");
    if (!values.isEmpty()) {
        for (StringValue value : values) {
            SingleEntitySelection fe = new SingleEntitySelection();
            fe.loadUrlPrameter(value.toString());
            addEntitySelection(fe);
        }
    }

    values = parameters.getValues(keyPrefix + "fc");
    if (!values.isEmpty()) {
        for (StringValue value : values) {
            MultipleEntitySelection fe = new MultipleEntitySelection();
            fe.loadUrlPrameter(value.toString());
            addEntitySelection(fe);
        }
    }

    super.decodeParameters(parameters, keyPrefix); //To change body of overridden methods use File | Settings | File Templates.
}

From source file:org.openmrs.module.patientregistration.service.db.HibernatePatientRegistrationDAO.java

public List<DuplicatePatient> getDuplicatePatients(Patient patient) {
    List<DuplicatePatient> duplicatePatients = null;
    if (patient != null && patient.getId() != null && (patient.getBirthdate() != null)) {
        Calendar birthdate = Calendar.getInstance();
        birthdate.setTime(patient.getBirthdate());
        Integer birthYear = new Integer(birthdate.get(Calendar.YEAR));
        Integer intervalYear = PatientRegistrationGlobalProperties.GLOBAL_PROPERTY_BIRTH_YEAR_INTERVAL();
        Integer minYear = new Integer(birthYear.intValue() - intervalYear.intValue());
        if (minYear.intValue() < 0) {
            minYear = 0;/*from ww w .  ja v a 2  s.  c  o  m*/
        }
        PatientIdentifierType zlIdentifierType = PatientRegistrationGlobalProperties
                .GLOBAL_PROPERTY_PRIMARY_IDENTIFIER_TYPE();
        PatientIdentifierType dossierType = PatientRegistrationGlobalProperties
                .GLOBAL_PROPERTY_NUMERO_DOSSIER();
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT s.person_id as PatientId, ");
        sql.append("n.given_name as FirstName, n.family_name as LastName, ");
        sql.append("s.gender as Gender, s.birthdate as Birthdate, ");
        sql.append("a.address1 as Address1, ");
        sql.append("a.city_village as Commune, s.date_created as PersonDateCreated, ");
        if (zlIdentifierType != null) {
            sql.append("id1.identifier as ZLEMRID, ");
        }
        if (dossierType != null) {
            sql.append("id3.identifier as NimewoDosye, ");
        }
        sql.append("Min(e.date_created) as FirstEncounterDate ");
        sql.append("FROM person as s JOIN person_name as n ON (s.person_id=n.person_id) ");
        sql.append("LEFT JOIN person_address as a ON (s.person_id = a.person_id) ");
        if (zlIdentifierType != null) {
            sql.append(
                    "LEFT JOIN patient_identifier as id1 ON (s.person_id = id1.patient_id and id1.identifier_type=")
                    .append(zlIdentifierType.getId().intValue()).append(") ");
        }
        if (dossierType != null) {
            sql.append(
                    "LEFT JOIN patient_identifier as id3 ON (s.person_id = id3.patient_id and id3.identifier_type=")
                    .append(dossierType.getId().intValue()).append(") ");
        }
        sql.append("LEFT outer JOIN encounter as e ON (s.person_id = e.patient_id) ");
        sql.append("WHERE s.voided=0 and n.voided=0 and n.given_name=\"").append(patient.getGivenName())
                .append("\" ");
        sql.append("AND n.family_name=\"").append(patient.getFamilyName()).append("\" ");
        sql.append("AND YEAR(s.birthdate) BETWEEN ").append(minYear.toString()).append(" AND ")
                .append(birthYear.intValue() + intervalYear.intValue()).append(" ");
        if (patient.getPersonAddress() != null) {
            String cityVillage = patient.getPersonAddress().getCityVillage();
            if (StringUtils.isNotBlank(cityVillage)) {
                sql.append("AND ((a.city_village is null) OR TRIM(a.city_village)='' OR (a.city_village=\"")
                        .append(cityVillage).append("\")) ");
            }
        }
        sql.append("GROUP BY PatientId ");
        sql.append("ORDER BY PatientId, PersonDateCreated, FirstEncounterDate");

        List<List<Object>> queryResults = Context.getAdministrationService().executeSQL(sql.toString(), true);
        if (queryResults != null && queryResults.size() > 0) {
            duplicatePatients = new ArrayList<DuplicatePatient>();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat bdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = null;
            Object fieldValue = null;
            for (List<Object> row : queryResults) {
                Integer patientId = Integer.parseInt(row.get(0).toString());
                if (patientId.compareTo(patient.getId()) == 0) {
                    continue;
                }

                DuplicatePatient duplicatePatient = new DuplicatePatient();
                duplicatePatient.setPatientId(patientId);
                duplicatePatient.setFirstName(row.get(1).toString());
                duplicatePatient.setLastName(row.get(2).toString());
                duplicatePatient.setGender(row.get(3).toString());
                try {
                    date = bdf.parse(row.get(4).toString());
                    if (date != null) {
                        duplicatePatient.setBirthdate(date);
                    }
                } catch (ParseException e) {
                    log.error("failed to parse date", e);
                }
                fieldValue = row.get(5);
                if (fieldValue != null) {
                    duplicatePatient.setAddress1(fieldValue.toString());
                }
                fieldValue = row.get(6);
                if (fieldValue != null) {
                    duplicatePatient.setCityVillage(fieldValue.toString());
                }
                fieldValue = row.get(7);
                if (fieldValue != null) {
                    try {
                        date = sdf.parse(fieldValue.toString());
                        if (date != null) {
                            duplicatePatient.setPersonDateCreated(date);
                        }
                    } catch (ParseException e) {
                        log.error("failed to parse date", e);
                    }
                }
                fieldValue = row.get(8);
                if (fieldValue != null) {
                    duplicatePatient.setZlEmrId(fieldValue.toString());
                }
                fieldValue = row.get(9);
                if (fieldValue != null) {
                    duplicatePatient.setDossierNumber(fieldValue.toString());
                }
                fieldValue = row.get(10);
                if (fieldValue != null) {
                    try {
                        date = sdf.parse(fieldValue.toString());
                        if (date != null) {
                            duplicatePatient.setFirstEncounterDate(date);
                        }
                    } catch (ParseException e) {
                        log.error("failed to parse date", e);
                    }
                }

                duplicatePatients.add(duplicatePatient);
            }
        }

    }
    return duplicatePatients;
}

From source file:org.web4thejob.orm.PropertyMetadataImpl.java

@Override
public int compareTo(PropertyMetadata other) {
    final Integer i1 = getIndex();
    final Integer i2 = other.getIndex();

    final int res = i1.compareTo(i2);
    if (res != 0) {
        return res;
    } else {//  www . j  a va2s  . c o m
        return Integer.valueOf(hashCode()).compareTo(other.hashCode());
    }
}

From source file:edu.ku.brc.specify.toycode.mexconabio.CollectionStats.java

/**
 * /*www  .  j a v  a 2  s.c  om*/
 */
public void createCharts() {
    loadInstCodesAndtotals();

    //for (CollStatInfo csi : institutions)
    //{
    //    csi.setInstName(getProviderNameFromInstCode(csi.getProviderId()));
    //}

    List<CollStatSQLDefs> statTypes = getStatSQL();
    HashMap<StatType, CollStatSQLDefs> statTypeHash = new HashMap<StatType, CollStatSQLDefs>();
    for (CollStatSQLDefs cs : statTypes) {
        statTypeHash.put(cs.getType(), cs);
    }

    CollStatInfo totals = new CollStatInfo(" Totals");
    for (CollStatInfo csi : institutions) {
        for (CollStatSQLDefs csqd : statTypes) {
            StatType type = csqd.getType();
            int totVal = totals.getValue(type) + csi.getValue(type);
            totals.setValue(type, totVal);
        }
    }

    try {
        FileUtils.deleteDirectory(new File("reports/charts/"));
    } catch (IOException e) {
        e.printStackTrace();
    }

    Collections.sort(institutions, new Comparator<CollStatInfo>() {
        @Override
        public int compare(CollStatInfo o1, CollStatInfo o2) {
            return o1.getInstName().compareToIgnoreCase(o2.getInstName());
            //Integer cnt1 = o1.getTotalNumRecords();
            //Integer cnt2 = o2.getTotalNumRecords();
            //return cnt2.compareTo(cnt1);
        }
    });

    institutions.insertElementAt(totals, 0);
    CollStatInfo clsi = totals;

    //tblWriter.logHdr(titles);

    int i = 0;
    for (CollStatInfo csi : institutions) {
        if (StringUtils.isEmpty(csi.getInstName())) {
            csi.setInstName(getProviderNameFromInstCode(csi.getProviderId()));
        }

        String title = csi.getTitle() + " - " + csi.getTotalNumRecords();

        if (i == 0) {
            startLogging("reports", "charts", clsi.hashCode() + ".html", title, false);
            tblWriter.startTable();
            tblInstHash.put(tblWriter, csi);

        } else {
            tblWriter.endTable();
            startNewDocument(csi.hashCode() + ".html", title, false);
            tblInstHash.put(tblWriter, csi);
            tblWriter.startTable();
        }

        if (generateChart(csi, statTypeHash)) {
            int total = csi.getValue(StatType.eTotalNumRecords);

            tblWriter.setHasLines();
            tblWriter.print("<TR><TD>");
            tblWriter.print(String.format("<img src=\"%s\">", csi.getChartFileName()));
            tblWriter.println("<BR><BR><BR><BR></TD><TD>");
            tblWriter.startTable();
            tblWriter.logHdr("Stat", "Percent");

            int rowCnt = 0;
            int cnt = 0;
            double totalPercent = 0.0;
            for (StatType type : StatType.values()) {
                if (type == StatType.eTotalNumRecords)
                    continue;

                CollStatSQLDefs csqd = statTypeHash.get(type);

                double dVal = (double) csi.getValue(type);
                double val = (((dVal / (double) total) * 100.0));

                if (type.ordinal() < StatType.eHasYearOnly.ordinal()) {
                    tblWriter.print(String.format("<TR class=\"%s\">", (rowCnt % 2 == 0 ? "od" : "ev")));
                    totalPercent += val;
                    cnt++;
                } else {
                    tblWriter.print(String.format("<TR>", csqd.getName()));
                }
                tblWriter.println(String.format("<TD>%s</TD><TD style=\"text-align:right\">%6.2f</TD></TR>",
                        csqd.getName(), val));
                rowCnt++;
            }
            totalPercent = Math.max(totalPercent, 0.0);
            double avePercent = (totalPercent / (double) cnt);
            tblWriter.println(String
                    .format("<TR><TD>Average</TD><TD style=\"text-align:right\">%6.2f</TD></TR>", avePercent));
            csi.setAveragePercent(avePercent);

            tblWriter.endTable();
            tblWriter.println("</TD></TR>");
        }

        i++;

        /*if (i % 25 == 0)
        {
        tblWriter.endTable();
        startNewDocument("institutions"+i+".html", "Institutions " + i, false);
        tblWriter.setHasLines();
        }*/

        //if (i == 100) break;
    }
    tblWriter.endTable();

    Vector<CollStatInfo> sortedByAvesList = new Vector<CollStatInfo>(institutions);
    Collections.sort(sortedByAvesList, new Comparator<CollStatInfo>() {
        @Override
        public int compare(CollStatInfo o1, CollStatInfo o2) {
            Double i1 = o1.getAveragePercent();
            Double i2 = o2.getAveragePercent();
            int rv = i2.compareTo(i1);
            if (rv == 0) {
                Integer cnt1 = o1.getTotalNumRecords();
                Integer cnt2 = o2.getTotalNumRecords();
                return cnt2.compareTo(cnt1);
            }
            return rv;
        }
    });

    Integer rank = 0;
    String average = "";
    startNewDocument("SortedByAverages.html", " Sorted By Averages", false);
    sortByTblWriter = tblWriter;
    tblWriter.startTable();
    tblWriter.logHdr("Rank", "Institution", "Num of Records", "Percentage");
    for (CollStatInfo csi : sortedByAvesList) {
        String aveStr = String.format("%8.2f", csi.getAveragePercent());
        Integer cnt = csi.getTotalNumRecords();
        if (!aveStr.equals(average)) {
            rank++;
            average = aveStr;
        }

        String fileName = StringUtils.replace(csi.getChartFileName(), "png", "html");
        String link = String.format("<a href=\"%s\">%s</>", fileName, csi.getTitle());
        tblWriter.log(rank.toString(), link, cnt.toString(), aveStr);
    }
    tblWriter.endTable();

    //tblWriter.println("</BODY></HTML>");
    endLogging(true);

    //saveInstitutions();
}