Example usage for java.util TreeSet last

List of usage examples for java.util TreeSet last

Introduction

In this page you can find the example usage for java.util TreeSet last.

Prototype

public E last() 

Source Link

Usage

From source file:org.ensembl.healthcheck.testcase.EnsTestCase.java

/**
 * Get the equivalent database from the secondary database server.
 * "equivalent" means: same database type and species. If more than one
 * database on the secondary server has the same type and species, then the
 * one with the highest version number is used.
 * /*  w  w  w. j av  a2 s. co m*/
 * @param dbre
 *            The database to find the equivalent for.
 * @return The database on the secondary server with the same type and
 *         species, and the highest version number, or null if none is
 *         found.
 */
public DatabaseRegistryEntry getEquivalentFromSecondaryServer(DatabaseRegistryEntry dbre) {

    DatabaseRegistry secondaryDatabaseRegistry = DBUtils.getSecondaryDatabaseRegistry();

    // find any databases matching type and species
    TreeSet<DatabaseRegistryEntry> matchingDBs = new TreeSet<DatabaseRegistryEntry>(); // get
    // sorting
    // for
    // free

    for (DatabaseRegistryEntry secDBRE : secondaryDatabaseRegistry.getAll()) {
        if (DBUtils.getSecondaryDatabase() != null) {
            if (secDBRE.getName().equals(DBUtils.getSecondaryDatabase())) {
                return secDBRE;
            }
        }
        if (dbre.getSpecies() == Species.UNKNOWN) {
            // EG where we don't know the species, use type and alias
            // matching instead
            if (dbre.getType().equals(secDBRE.getType()) && dbre.getAlias().equals(secDBRE.getAlias())) {
                matchingDBs.add(secDBRE);
                logger.finest("added " + secDBRE.getName() + " to list of databases to check for equivalent to "
                        + dbre.getName());
            }
        } else {
            // nulls will set type automatically
            if (dbre.getType().equals(secDBRE.getType()) && dbre.getSpecies().equals(secDBRE.getSpecies())) {
                matchingDBs.add(secDBRE);
                logger.finest("added " + secDBRE.getName() + " to list of databases to check for equivalent to "
                        + dbre.getName());
            }
        }
    }

    if (matchingDBs.size() == 0) {
        logger.finest("Could not find equivalent database to " + dbre.getName() + " on secondary server");
    }

    // take the highest one that doesn't have the same version number as our
    // current one, if available
    DatabaseRegistryEntry result = null;

    if (matchingDBs.size() > 0) {

        result = (DatabaseRegistryEntry) matchingDBs.last();

    }

    return result;

}

From source file:org.hyperic.hq.measurement.server.session.AvailabilityManagerImpl.java

private AvailabilityDataRLE getLastAvail(DataPoint state,
        Map<Integer, TreeSet<AvailabilityDataRLE>> currAvails) {
    Integer mId = state.getMeasurementId();
    TreeSet<AvailabilityDataRLE> rles = currAvails.get(mId);
    if (rles.size() == 0) {
        return null;
    }//from  ww w.j  a  v  a 2  s. c  o m
    return rles.last();
}

From source file:org.jamocha.dn.ConflictSet.java

public synchronized RuleAndToken getCurrentlySelectedRuleAndToken() {
    final TreeSet<RuleAndToken> conflictingRulesAndTokensForMaxSalience = getConflictingRulesAndTokensForMaxSalience();
    if (null == conflictingRulesAndTokensForMaxSalience || conflictingRulesAndTokensForMaxSalience.isEmpty()) {
        return null;
    }/*  ww  w. j a v a2 s .c o m*/
    return conflictingRulesAndTokensForMaxSalience.last();
}

From source file:org.oscarehr.match.vacancy.VacancyTemplateData.java

public int matches(String value) {
    if (this.weight == 0) {
        this.weight = 1;
    }//from  w  w  w .  j  a v  a2 s.com
    if (GENDER.equalsIgnoreCase(param)) {
        if (value != null) {
            for (String gender : transaGender) {
                if (value.toLowerCase().contains(gender)) {
                    return 100;
                }
            }
        }
    }
    if (this.range) {
        if (ranges.isEmpty()) {
            return 100;
        }
        if (!StringUtils.isNumeric(value)) {
            for (Range range : ranges) {
                for (String rangeString : range.rangeString) {
                    if (value.contains(rangeString) || rangeString.contains(value)) {
                        return 100;
                    }
                }
            }
        }
        Integer val = null;
        try {
            val = Integer.valueOf(value);
        } catch (Exception e) {
            logger.error("Error", e);
        }
        if (val != null) {
            for (Range rangeVal : ranges) {
                if (rangeVal.isInRange(val)) {
                    return 100;
                }
            }
        } else {
            return 0;
        }
    }
    String valueToMatch = value;
    if (valueToMatch == null) {
        return 0;
    }
    if (values.isEmpty()) {
        return 100;
    }
    TreeSet<Integer> weights = new TreeSet<Integer>();
    for (String val : values) {
        if (val == null) {
            if (values.size() == 1) {
                return 100;
            }
            weights.add(MAX_WEIGHT);
        } else {
            int distance = StringUtils.getLevenshteinDistance(val.toLowerCase(), valueToMatch.toLowerCase());
            int calculatedWeight = 100 / (distance == 0 ? 1 : distance);
            weights.add(calculatedWeight);
        }
    }
    return weights.last();
}

From source file:org.processmining.analysis.performance.PerformanceAnalysisGUI.java

/**
 * Initializes the waiting time levels. If no manual peformance settings are
 * filled in by the user, standard settings are calculated and used.
 * Standard settings: approximately 33% low, 33% high, 33% medium level note
 * that a set is used instead of a list however, so if a time occurs
 * multiple times (this can happen easily with a waiting time of 0.0s for
 * instance) of such places only one is used, so the 33-33-33 estimation can
 * be quite wrong, though this is not considered to be a problem.
 *//*  w w  w. j  a  va  2  s . co  m*/
public void initializeWaitingTimeLevels() {
    if (!manualSettings) {
        // no manual settings are present
        TreeSet waitingTimes = new TreeSet();
        ListIterator it = extendedPetriNet.getPlaces().listIterator();
        while (it.hasNext()) {
            // place the mean waiting time of each place in the tree set
            ExtendedPlace p = (ExtendedPlace) it.next();
            p.calculateMetrics(extendedLog.getLogTraceIDs(), advancedSettings[1], failedInstances);
            if (p.getMeanWaitingTime() >= 0) {
                // only add correct times
                double waitTime = p.getMeanWaitingTime() / timeDivider;
                waitingTimes.add(Double.valueOf(waitTime));
            }
        }
        int num = waitingTimes.size() / 3;
        // remove the first 'num' measurements and the last 'num'
        // measurements
        // from waitingTimes
        for (int i = 0; i < num; i++) {
            // there should be at least one waiting time measurement
            // remaining
            if (!(waitingTimes.size() < 2)) {
                waitingTimes.remove(waitingTimes.first());
                waitingTimes.remove(waitingTimes.last());
            }
        }

        // give new values to the bounds and the colors
        if (waitingTimes.size() != 0) {
            Double bnd = (Double) waitingTimes.first();
            bounds.set(0, bnd);
            bnd = (Double) waitingTimes.last();
            bounds.set(1, bnd);
        } else {
            // in case there are no valid waiting times
            waitingTimes.add(Double.valueOf(0));
            Double bnd = (Double) waitingTimes.first();
            bounds.set(0, bnd);
            bounds.set(1, bnd);
        }
        levelColors.set(0, Color.BLUE);
        levelColors.set(1, Color.YELLOW);
        levelColors.set(2, Color.MAGENTA);
    }
    extendedPetriNet.setAdvancedSettings(advancedSettings);
    extendedPetriNet.setBounds(bounds);
    extendedPetriNet.setLevelColors(levelColors);
    extendedPetriNet.setTimeDivider(timeDivider);
    extendedPetriNet.setFailedInstances(failedInstances);
}

From source file:org.prom5.analysis.performance.PerformanceAnalysisGUI.java

/**
 * Initializes the waiting time levels. If no manual peformance settings are
 * filled in by the user, standard settings are calculated and used.
 * Standard settings: approximately 33% low, 33% high, 33% medium level
 * note that a set is used instead of a list however, so if a time occurs
 * multiple times (this can happen easily with a waiting time of 0.0s for
 * instance) of such places only one is used, so the 33-33-33 estimation can
 * be quite wrong, though this is not considered to be a problem.
 *///from   w w w . j  ava  2 s  . co m
public void initializeWaitingTimeLevels() {
    if (!manualSettings) {
        //no manual settings are present
        TreeSet waitingTimes = new TreeSet();
        ListIterator it = extendedPetriNet.getPlaces().listIterator();
        while (it.hasNext()) {
            //place the mean waiting time of each place in the tree set
            ExtendedPlace p = (ExtendedPlace) it.next();
            p.calculateMetrics(extendedLog.getLogTraceIDs(), advancedSettings[1], failedInstances);
            if (p.getMeanWaitingTime() >= 0) {
                //only add correct times
                double waitTime = p.getMeanWaitingTime() / timeDivider;
                waitingTimes.add(Double.valueOf(waitTime));
            }
        }
        int num = waitingTimes.size() / 3;
        //remove the first 'num' measurements and the last 'num' measurements
        //from waitingTimes
        for (int i = 0; i < num; i++) {
            //there should be at least one waiting time measurement remaining
            if (!(waitingTimes.size() < 2)) {
                waitingTimes.remove(waitingTimes.first());
                waitingTimes.remove(waitingTimes.last());
            }
        }

        //give new values to the bounds and the colors
        if (waitingTimes.size() != 0) {
            Double bnd = (Double) waitingTimes.first();
            bounds.set(0, bnd);
            bnd = (Double) waitingTimes.last();
            bounds.set(1, bnd);
        } else {
            //in case there are no valid waiting times
            waitingTimes.add(Double.valueOf(0));
            Double bnd = (Double) waitingTimes.first();
            bounds.set(0, bnd);
            bounds.set(1, bnd);
        }
        levelColors.set(0, Color.BLUE);
        levelColors.set(1, Color.YELLOW);
        levelColors.set(2, Color.MAGENTA);
    }
    extendedPetriNet.setAdvancedSettings(advancedSettings);
    extendedPetriNet.setBounds(bounds);
    extendedPetriNet.setLevelColors(levelColors);
    extendedPetriNet.setTimeDivider(timeDivider);
    extendedPetriNet.setFailedInstances(failedInstances);
}

From source file:org.sonatype.mercury.mp3.delta.cli.DeltaManagerCli.java

private List<Artifact> getLocalVersions(final String containerId) {
    ArrayList<Artifact> res = new ArrayList<Artifact>(8);

    File cdDir = new File(_mavenHome, DeltaManager.CD_DIR);

    if (!cdDir.exists())
        return res;

    File[] files = cdDir.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            String name = pathname.getName();

            if (name.equals(MavenDeltaManager.DEFAULT_CONTAINER_ID + "." + DeltaManager.CD_EXT))
                return false;// current version

            //                                          if( name.matches( ".*-[0-9]{14}\\."+DeltaManager.CD_EXT ) )
            if (name.endsWith("." + DeltaManager.CD_EXT))
                return true;

            return false;
        }/*  ww w  .j a  v  a 2 s  .c o m*/
    });
    if (Util.isEmpty(files))
        return res;

    int count = files.length;

    TreeSet<String> sortedFiles = new TreeSet<String>();
    for (File f : files)
        sortedFiles.add(f.getName());

    while (count-- > 0) {
        String f = sortedFiles.last();

        DefaultArtifact da = new DefaultArtifact(new ArtifactMetadata("org.apache.maven:maven-cd:" + f));

        da.setFile(new File(cdDir, f));

        res.add(da);

        sortedFiles.remove(f);
    }

    return res;
}

From source file:org.unitime.timetable.action.PersonalizedExamReportAction.java

protected String getMeetingTime(ExamSectionInfo section) {
    String meetingTime = "";
    if (section.getOwner().getOwnerObject() instanceof Class_) {
        Formats.Format<Date> dpf = Formats.getDateFormat(Formats.Pattern.DATE_EVENT_SHORT);
        Class_ clazz = (Class_) section.getOwner().getOwnerObject();
        Assignment assignment = clazz.getCommittedAssignment();
        TreeSet meetings = (clazz.getEvent() == null ? null : new TreeSet(clazz.getEvent().getMeetings()));
        if (meetings != null && !meetings.isEmpty()) {
            Date first = ((Meeting) meetings.first()).getMeetingDate();
            Date last = ((Meeting) meetings.last()).getMeetingDate();
            meetingTime += dpf.format(first) + " - " + dpf.format(last);
        } else if (assignment != null && assignment.getDatePattern() != null) {
            DatePattern dp = assignment.getDatePattern();
            if (dp != null && !dp.isDefault()) {
                if (dp.getType().intValue() == DatePattern.sTypeAlternate)
                    meetingTime += dp.getName();
                else {
                    meetingTime += dpf.format(dp.getStartDate()) + " - " + dpf.format(dp.getEndDate());
                }//from www. j a va  2 s . c  o m
            }
        }
        if (meetings != null && !meetings.isEmpty()) {
            int dayCode = getDaysCode(meetings);
            String days = "";
            for (int i = 0; i < Constants.DAY_CODES.length; i++)
                if ((dayCode & Constants.DAY_CODES[i]) != 0)
                    days += CONSTANTS.shortDays()[i];
            meetingTime += " " + days;
            Meeting first = (Meeting) meetings.first();
            meetingTime += " " + first.startTime() + " - " + first.stopTime();
        } else if (assignment != null) {
            TimeLocation t = assignment.getTimeLocation();
            meetingTime += " " + t.getDayHeader() + " " + t.getStartTimeHeader(CONSTANTS.useAmPm()) + " - "
                    + t.getEndTimeHeader(CONSTANTS.useAmPm());
        }
    }
    return meetingTime;
}

From source file:org.unitime.timetable.action.PersonalizedExamReportAction.java

protected String getMeetingTime(Class_ clazz) {
    String meetingTime = "";
    Formats.Format<Date> dpf = Formats.getDateFormat(Formats.Pattern.DATE_EVENT_SHORT);
    Assignment assignment = clazz.getCommittedAssignment();
    TreeSet meetings = (clazz.getEvent() == null ? null : new TreeSet(clazz.getEvent().getMeetings()));
    DatePattern dp = (assignment == null ? null : assignment.getDatePattern());
    if (meetings != null && !meetings.isEmpty()) {
        int dayCode = getDaysCode(meetings);
        String days = "";
        for (int i = 0; i < Constants.DAY_CODES.length; i++)
            if ((dayCode & Constants.DAY_CODES[i]) != 0)
                days += CONSTANTS.shortDays()[i];
        meetingTime += days;//from   ww  w  .j  av a  2s .  co m
        Meeting first = (Meeting) meetings.first();
        meetingTime += " " + first.startTime() + " - " + first.stopTime();
    } else if (assignment != null) {
        TimeLocation t = assignment.getTimeLocation();
        meetingTime += t.getDayHeader() + " " + t.getStartTimeHeader(CONSTANTS.useAmPm()) + " - "
                + t.getEndTimeHeader(CONSTANTS.useAmPm());
    } else {
        meetingTime += "Arr Hrs";
    }
    if (meetings != null && !meetings.isEmpty()) {
        if (dp == null || !dp.isDefault()) {
            Date first = ((Meeting) meetings.first()).getMeetingDate();
            Date last = ((Meeting) meetings.last()).getMeetingDate();
            if (dp != null && dp.getType() == DatePattern.sTypeAlternate)
                meetingTime += " (" + dpf.format(first) + " - " + dpf.format(last) + " " + dp.getName() + ")";
            else
                meetingTime += " (" + dpf.format(first) + " - " + dpf.format(last) + ")";
        }
    } else if (dp != null && !dp.isDefault()) {
        if (dp.getType() == DatePattern.sTypeAlternate)
            meetingTime += " (" + dpf.format(dp.getStartDate()) + " - " + dpf.format(dp.getEndDate()) + " "
                    + dp.getName() + ")";
        else
            meetingTime += " (" + dpf.format(dp.getStartDate()) + " - " + dpf.format(dp.getEndDate()) + ")";
    }
    return meetingTime;
}

From source file:org.unitime.timetable.gwt.server.UploadServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Params params = null;/*www . j ava 2s  .  c  o  m*/
    String q = request.getParameter("q");
    if (q != null) {
        params = new QParams(q);
    } else {
        params = new HttpParams(request);
    }
    if (params.getParameter("event") != null) {
        Long eventId = Long.parseLong(params.getParameter("event"));
        String fileName = params.getParameter("name");
        Long noteId = (params.getParameter("note") == null ? null : Long.valueOf(params.getParameter("note")));
        if (q == null)
            getSessionContext().checkPermissionAnyAuthority(Long.valueOf(eventId), "Event", Right.EventDetail);
        Event event = EventDAO.getInstance().get(eventId);
        TreeSet<EventNote> notes = new TreeSet<EventNote>();
        if (event != null)
            for (EventNote note : event.getNotes()) {
                if (note.getAttachedName() == null || note.getAttachedName().isEmpty())
                    continue;
                if (fileName != null) {
                    if (fileName.equals(note.getAttachedName())
                            && (noteId == null || noteId.equals(note.getUniqueId())))
                        notes.add(note);
                } else if (noteId != null) {
                    if (noteId.equals(note.getUniqueId()))
                        notes.add(note);
                } else {
                    notes.add(note);
                }
            }
        if (!notes.isEmpty()) {
            EventNote note = notes.last();

            response.setContentType(note.getAttachedContentType());
            response.setHeader("Content-Disposition",
                    "attachment; filename=\"" + note.getAttachedName() + "\"");
            OutputStream out = response.getOutputStream();
            out.write(note.getAttachedFile());
            out.flush();
            out.close();

            return;
        }
    }

    throw new ServletException("Nothing to download.");
}