Example usage for java.util SortedSet last

List of usage examples for java.util SortedSet last

Introduction

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

Prototype

E last();

Source Link

Document

Returns the last (highest) element currently in this set.

Usage

From source file:ch.fork.AdHocRailway.manager.impl.TurnoutManagerImpl.java

@Override
public int getNextFreeTurnoutNumber() {
    LOGGER.debug("getNextFreeTurnoutNumber()");

    if (lastProgrammedNumber == 0) {
        final SortedSet<Turnout> turnoutsNumbers = new TreeSet<Turnout>(new Comparator<Turnout>() {

            @Override//from  w  w w  . j  a  v  a2 s .c  o m
            public int compare(final Turnout o1, final Turnout o2) {
                return Integer.valueOf(o1.getNumber()).compareTo(o2.getNumber());
            }
        });
        turnoutsNumbers.addAll(getAllTurnouts());
        if (turnoutsNumbers.isEmpty()) {
            lastProgrammedNumber = 0;
        } else {
            lastProgrammedNumber = turnoutsNumbers.last().getNumber();
        }
    }

    return lastProgrammedNumber + 1;
}

From source file:edu.harvard.med.screensaver.model.screenresults.ScreenResult.java

/**
 * The last {@link AdministrativeActivityType#SCREEN_RESULT_DATA_LOADING}
 * screen result data loading activity that full or incremental data was
 * loaded for this ScreenResult./*from ww w  . jav  a 2  s.com*/
 */
@Transient
public AdministrativeActivity getLastDataLoadingActivity() {
    SortedSet<AdministrativeActivity> screenResultDataLoadings = Sets
            .newTreeSet(Iterables.filter(getScreen().getUpdateActivities(),
                    AdministrativeActivityType.SCREEN_RESULT_DATA_LOADING.isValuePredicate()));
    if (screenResultDataLoadings.isEmpty()) {
        return null;
    }
    return screenResultDataLoadings.last();
}

From source file:com.tdclighthouse.prototype.maven.PrototypeSupperClassHandler.java

@SuppressWarnings("unchecked")
private ClassReference extendsExistingBeans(List<String> supertypes) {
    ClassReference result = null;/*from  w w  w . j ava2s .c  o m*/
    SortedSet<Class<? extends HippoBean>> supperClasses = new TreeSet<Class<? extends HippoBean>>(
            classExtensionComparator);
    for (String superType : supertypes) {
        if (Constants.NodeType.HIPPO_COMPOUND.equals(superType)) {
            Class<TdcDocument> tdcDocumentClass = TdcDocument.class;
            supperClasses.add(tdcDocumentClass);
        } else if (getBeansOnClassPath().containsKey(superType)) {
            HippoBeanClass hippoBeanClass = getBeansOnClassPath().get(superType);
            Class<?> clazz = getClass(hippoBeanClass);
            supperClasses.add((Class<? extends HippoBean>) clazz);
        }
    }
    if (!supperClasses.isEmpty()) {
        result = new ClassReference(supperClasses.last());
    }
    return result;
}

From source file:net.sourceforge.mavenhippo.gen.DefaultSupperClassHandler.java

@SuppressWarnings("unchecked")
private ClassReference extendsExistingBeans(List<String> supertypes) {
    ClassReference result = null;/*from  ww w. j  a v a2 s  . c  om*/
    SortedSet<Class<? extends HippoBean>> supperClasses = new TreeSet<Class<? extends HippoBean>>(
            classExtensionComparator);
    for (String superType : supertypes) {
        if (Constants.NodeType.HIPPO_COMPOUND.equals(superType)) {
            Class<HippoCompound> hippoCompoundClass = HippoCompound.class;
            supperClasses.add(hippoCompoundClass);
        } else if (getBeansOnClassPath().containsKey(superType)) {
            HippoBeanClass hippoBeanClass = getBeansOnClassPath().get(superType);
            Class<?> clazz = getClass(hippoBeanClass);
            supperClasses.add((Class<? extends HippoBean>) clazz);
        }
    }
    if (!supperClasses.isEmpty()) {
        result = new ClassReference(supperClasses.last());
    }
    return result;
}

From source file:org.apache.cxf.fediz.service.oidc.clients.ClientRegistrationService.java

protected RegisteredClients registerNewClient(Client newClient) {
    String userName = newClient.getResourceOwnerSubject().getLogin();
    Set<String> names = clientNames.get(userName);
    if (names == null) {
        names = new HashSet<String>();
        clientNames.put(userName, names);
    } else if (names.contains(newClient.getApplicationName())) {
        String newName = newClient.getApplicationName();
        SortedSet<Integer> numbers = new TreeSet<Integer>();
        for (String name : names) {
            if (name.startsWith(newName) && !name.equals(newName)) {
                try {
                    numbers.add(Integer.valueOf(name.substring(newName.length())));
                } catch (Exception ex) {
                    // can be characters, continue;
                }/*from  w  ww . j  a  v a  2  s .co m*/
            }
        }
        int nextNumber = numbers.isEmpty() ? 2 : numbers.last() + 1;
        newClient.setApplicationName(newName + nextNumber);
    }
    names.add(newClient.getApplicationName());

    clientProvider.setClient(newClient);
    Collection<Client> clientRegistrations = getClientRegistrations();
    clientRegistrations.add(newClient);
    return new RegisteredClients(clientRegistrations);
}

From source file:info.rmapproject.core.rmapservice.impl.openrdf.ORMapDiSCOMgr.java

/**
 * Get IRI of previous version of this DiSCO.
 *
 * @param discoID IRI of DiSCO/*from w  w  w .  j a va 2  s  .c  om*/
 * @param event2disco Map from events to all versions of DiSCOs
 * @param date2event  Map from date events associated with version of DiSCO
 * @param ts the triplestore instance
 * @return IRI of previous version of this DiSCO, or null if none found
 * @throws RMapException the RMap exception
 * @throws RMapObjectNotFoundException the RMap object not found exception
 * @throws RMapDefectiveArgumentException the RMap defective argument exception
 */
protected IRI getPreviousIRI(IRI discoID, Map<IRI, IRI> event2disco, Map<Date, IRI> date2event,
        SesameTriplestore ts)
        throws RMapException, RMapObjectNotFoundException, RMapDefectiveArgumentException {
    if (discoID == null) {
        throw new RMapDefectiveArgumentException("null DiSCO id");
    }
    if (event2disco == null) {
        throw new RMapDefectiveArgumentException("Null event2disco map");
    }
    Map<IRI, IRI> disco2event = Utils.invertMap(event2disco);

    if (date2event == null) {
        date2event = eventmgr.getDate2EventMap(event2disco.keySet(), ts);
    }

    Map<IRI, Date> event2date = Utils.invertMap(date2event);

    IRI discoEventId = disco2event.get(discoID);
    Date eventDate = event2date.get(discoEventId);

    SortedSet<Date> sortedDates = new TreeSet<Date>();
    sortedDates.addAll(date2event.keySet());
    SortedSet<Date> earlierDates = sortedDates.headSet(eventDate);
    IRI prevDiscoId = null;
    if (earlierDates.size() > 0) {
        Date previousDate = earlierDates.last();
        IRI prevEventId = date2event.get(previousDate);
        prevDiscoId = event2disco.get(prevEventId);
    }
    return prevDiscoId;
}

From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginView.java

/**
 * //from  w  w  w.j  ava 2 s .  co m
 * @param path int of the path to get the Time Options for
 * @param storedTimePref Long of anytime during the specific day that we want to return times for
 * @return populates the "times" TreeSet (time longs truncated at the "the seconds" position) 
 *          which populates Time Combo box, the truncTimeToFullTimeMap which maps the truncated times
 *          im times TreeSet to each times full Long value. The truncTimeToFullTimeMap chooses each time
 *          up to the second and maps it to the greatest equivalent time up to the milliseconds.
 *          
 */
protected void setTimeOptions(int path, Long storedTimePref) {
    try {
        timeSelectCombo.getItems().clear();
        overrideTimestamp = null;

        Date startDate = null, finishDate = null;
        if (storedTimePref != null) {
            StampBdb stampDb = Bdb.getStampDb();
            NidSet nidSet = new NidSet();
            nidSet.add(path);

            NidSetBI stamps = null;
            if (!storedTimePref.equals(getDefaultTime())) {
                startDate = getStartOfDay(new Date(storedTimePref));
                finishDate = getEndOfDay(new Date(storedTimePref));
                stamps = stampDb.getSpecifiedStamps(nidSet, startDate.getTime(), finishDate.getTime());
            } else {
                stamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE);
            }

            truncTimeToFullTimeMap.clear();
            times.clear();

            HashSet<Integer> stampSet = stamps.getAsSet();

            Date d = new Date(storedTimePref);
            if (dateIsLocalDate(d)) {
                // Get stamps of day
                Date todayStartDate = getStartOfDay(new Date());
                Date todayFinishDate = getEndOfDay(new Date());
                NidSetBI todayStamps = stampDb.getSpecifiedStamps(nidSet, todayStartDate.getTime(),
                        todayFinishDate.getTime());

                // If have stamps, no action, if not, show Latest and set stamps to latest stamp we have in stampset
                if (todayStamps.size() == 0) {
                    //                  timeSelectCombo.getItems().add(Long.MAX_VALUE);
                    NidSetBI allStamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE);
                    HashSet<Integer> allStampSet = allStamps.getAsSet();
                    SortedSet<Integer> s = new TreeSet<Integer>(allStampSet);
                    if (!s.isEmpty()) {
                        Integer stampToSet = s.last();
                        overrideTimestamp = stampDb.getPosition(stampToSet).getTime();
                        timeSelectCombo.getItems().add(Long.MAX_VALUE);
                        timeSelectCombo.setValue(Long.MAX_VALUE);
                    }
                }
            }

            this.pathDatesList.add(LocalDate.now());
            if (overrideTimestamp == null) {
                if (!stampSet.isEmpty()) {
                    enableTimeCombo(true);
                    for (Integer thisStamp : stampSet) {
                        Long fullTime = null;
                        Date stampDate;
                        LocalDate stampInstant = null;
                        try {
                            fullTime = stampDb.getPosition(thisStamp).getTime();
                            stampDate = new Date(fullTime);
                            stampInstant = stampDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        Calendar cal = Calendar.getInstance();
                        cal.setTime(new Date(fullTime));
                        cal.set(Calendar.MILLISECOND, 0); //Strip milliseconds
                        Long truncTime = cal.getTimeInMillis();

                        this.pathDatesList.add(stampInstant); //Build DatePicker
                        times.add(truncTime); //This can probably go, we don't populate hashmap like this at initialization
                        timeSelectCombo.getItems().add(truncTime);

                        if (truncTimeToFullTimeMap.containsKey(truncTime)) { //Build Truncated Time to Full Time HashMap
                            //If truncTimeToFullTimeMap has this key, is the value the newest time in milliseconds?
                            if (new Date(truncTimeToFullTimeMap.get(truncTime)).before(new Date(fullTime))) {
                                truncTimeToFullTimeMap.put(truncTime, fullTime);
                            }
                        } else {
                            truncTimeToFullTimeMap.put(truncTime, fullTime);
                        }
                    }
                } else {
                    //               disableTimeCombo(true);
                    //                  timeSelectCombo.getItems().add(Long.MAX_VALUE);
                    timeSelectCombo.setValue(Long.MAX_VALUE);
                    enableTimeCombo(true);
                    //               logger.error("Could not retreive any Stamps");
                }
            }
        }
    } catch (Exception e) {
        logger.error("Error setting the default Time Dropdown");
        e.printStackTrace();
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.coordinator.thesis.ManageThesisDA.java

private Thesis findPreviousThesis(final SortedSet<Enrolment> dissertationEnrolments) {
    if (dissertationEnrolments.isEmpty()) {
        return null;
    }//from  w w  w .  j  a  v a2s  .c om
    final Enrolment previous = dissertationEnrolments.last();
    if (previous != null) {
        if (!previous.getThesesSet().isEmpty()) {
            return previous.getThesis();
        } else {
            dissertationEnrolments.remove(previous);
            return findPreviousThesis(dissertationEnrolments);
        }
    }
    return null;
}

From source file:org.geoserver.taskmanager.external.impl.FileServiceImpl.java

@Override
public FileReference getVersioned(String filePath) {
    if (filePath.indexOf(FileService.PLACEHOLDER_VERSION) < 0) {
        return new FileReferenceImpl(this, filePath, filePath);
    }//w w w  .  j  ava 2s .  c o m

    Path parent = getAbsolutePath(filePath).getParent();
    String[] fileNames = parent.toFile()
            .list(new WildcardFileFilter(filePath.replace(FileService.PLACEHOLDER_VERSION, "*")));

    SortedSet<Integer> set = new TreeSet<Integer>();
    Pattern pattern = Pattern
            .compile(Pattern.quote(filePath).replace(FileService.PLACEHOLDER_VERSION, "\\E(.*)\\Q"));
    for (String fileName : fileNames) {
        Matcher matcher = pattern.matcher(fileName);
        if (matcher.matches()) {
            try {
                set.add(Integer.parseInt(matcher.group(1)));
            } catch (NumberFormatException e) {
                LOGGER.log(Level.WARNING, "could not parse version in versioned file " + fileName, e);
            }
        } else {
            LOGGER.log(Level.WARNING,
                    "this shouldn't happen: couldn't find version in versioned file " + fileName);
        }
    }
    int last = set.isEmpty() ? 0 : set.last();
    return new FileReferenceImpl(this, filePath.replace(FileService.PLACEHOLDER_VERSION, last + ""),
            filePath.replace(FileService.PLACEHOLDER_VERSION, (last + 1) + ""));
}

From source file:sadl.modellearner.rtiplus.SimplePDRTALearner.java

void complete(PDRTA a, StateColoring sc) {

    final boolean preExit = (bOp[2] instanceof OrOperator)
            && distrCheckType.equals(DistributionCheckType.DISABLED);
    if (mainModel == a && preExit) {
        logger.info("Pre-Exiting algorithm when number of tails falls below minData");
    }// ww  w .  j a v  a 2  s.  co  m

    int counter = 0;
    Transition t;
    while ((t = getMostVisitedTrans(a, sc)) != null
            && !(preExit && t.in.getTails().size() < PDRTA.getMinData())) {
        if (mainModel == a) {
            if (directory != null) {
                draw(a, true, directory, counter);
            }
            logger.debug("Automaton contains {} states and {} transitions", a.getStateCount(), a.getSize());
            logger.debug("Found most visited transition  {}  containing {} tails", t.toString(),
                    t.in.getTails().size());
        }
        counter++;

        if (!distrCheckType.equals(DistributionCheckType.DISABLED)) {
            if (mainModel == a) {
                logger.debug("Checking data distribution");
            }
            final List<Interval> idaIns = checkDistribution(t.source, t.symAlphIdx, distrCheckType, sc);
            if (idaIns.size() > 0) {
                if (mainModel == a) {
                    logger.debug("#{} DO: Split interval due to IDA into {} intervals", counter, idaIns.size());
                    // TODO Printing the intervals may be to expensive just for logging
                    final StringBuilder sb = new StringBuilder();
                    for (final Interval in : idaIns) {
                        sb.append("  ");
                        sb.append(in.toString());
                    }
                    logger.trace("Resulting intervals are:{}", sb.toString());
                }
                continue;
            } else {
                if (mainModel == a) {
                    logger.debug("No splits because of data distributuion were perfomed in:  {}",
                            t.in.toString());
                }
                if (bOp[2] instanceof OrOperator && t.in.getTails().size() < PDRTA.getMinData()) {
                    // Shortcut for skipping merges and splits when OR is selected
                    if (mainModel == a) {
                        logger.debug("#{} DO: Color state {} red", counter, t.target.getIndex());
                    }
                    sc.setRed(t.target);
                    continue;
                }
            }
        }

        if (mainModel == a) {
            logger.debug("Testing splits");
        }
        final SortedSet<Refinement> splits = getSplitRefs(t, sc);
        if (mainModel == a) {
            logger.debug("Found {} possible splits", splits.size());
        }
        if (splits.size() > 0) {
            final Refinement r = splits.last();
            if (mainModel == a) {
                logger.debug("#{} DO: {}", counter, r.toString());
            }
            r.refine();
        } else {
            if (mainModel == a) {
                logger.debug("Testing merges");
            }
            final SortedSet<Refinement> merges = getMergeRefs(t, sc);
            if (mainModel == a) {
                logger.debug("Found {} possible merges", merges.size());
            }
            if (merges.size() > 0) {
                final Refinement r = merges.last();
                if (mainModel == a) {
                    logger.debug("#{} DO: {}", counter, r.toString());
                }
                r.refine();
            } else {
                if (mainModel == a) {
                    logger.debug("#{} DO: Color state {} red", counter, t.target.getIndex());
                }
                sc.setRed(t.target);
            }
        }

        if (Settings.isDebug()) {
            a.checkConsistency();
        }
    }

    assert (a.getStateCount() == sc.getNumRedStates());

    a.checkConsistency();
    if (directory != null) {
        draw(a, true, directory, counter);
    }
}