Example usage for java.util TreeSet isEmpty

List of usage examples for java.util TreeSet isEmpty

Introduction

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

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this set contains no elements.

Usage

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

protected long getMeetingComparable(ExamSectionInfo section) {
    if (section.getOwner().getOwnerObject() instanceof Class_) {
        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()) {
            return ((Meeting) meetings.first()).getMeetingDate().getTime();
        } else if (assignment != null) {
            return assignment.getTimeLocation().getStartSlot();
        }//w  ww  .  j a v a  2s.co m
    }
    return -1;
}

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());
                }//ww  w.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 getMeetingRooms(boolean html, Class_ clazz) {
    String meetingRooms = "";
    Assignment assignment = clazz.getCommittedAssignment();
    TreeSet<Meeting> meetings = (clazz.getEvent() == null ? null : new TreeSet(clazz.getEvent().getMeetings()));
    TreeSet<Location> locations = new TreeSet<Location>();
    if (meetings != null && !meetings.isEmpty()) {
        for (Meeting meeting : meetings)
            if (meeting.getLocation() != null)
                locations.add(meeting.getLocation());
    } else if (assignment != null && assignment.getDatePattern() != null) {
        for (Iterator i = assignment.getRooms().iterator(); i.hasNext();) {
            locations.add((Location) i.next());
        }/*w  w  w . j av a 2 s .  c o m*/
    }
    for (Location location : locations) {
        if (meetingRooms.length() > 0)
            meetingRooms += ", ";
        meetingRooms += (html ? location.getLabelWithHint() : location.getLabel());
    }
    return meetingRooms;
}

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;/* ww w  .  ja  v  a2s . 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.apache.myfaces.trinidadbuild.plugin.tagdoc.TagdocReport.java

private void _writeComponentAttributes(Writer out, ComponentBean bean) throws IOException {
    // Sort the names
    TreeSet<String> attributes = new TreeSet<String>();
    Iterator<PropertyBean> attrs = bean.properties(true);
    attrs = new FilteredIterator(attrs, new NonHiddenFilter());

    while (attrs.hasNext()) {
        PropertyBean property = attrs.next();
        if (!property.isTagAttributeExcluded())
            attributes.add(property.getPropertyName());
    }//from  w ww  .  j a va  2 s .c  o m

    // Now get a list of PropertyBeans
    List<PropertyBean> list = new ArrayList<PropertyBean>();
    Iterator<String> iter = attributes.iterator();
    while (iter.hasNext()) {
        String attrName = iter.next();
        list.add(bean.findProperty(attrName, true));
    }

    TreeSet<String> groups = new TreeSet<String>(new GroupComparator());
    /* No current support for grouping
    // Make sure "null" is the representative for unknown groups
    Iterator iter = attributes.iterator();
    while (iter.hasNext())
    {
      String group = ((AttributeDoc) iter.next()).group;
      if (group != null)
        groups.add(group);
    }
    */

    _writeComponentAttributes(out, list.iterator(), bean.getComponentClass(),
            groups.isEmpty() ? null : "Ungrouped");

    Iterator<String> groupIter = groups.iterator();
    while (groupIter.hasNext()) {
        _writeComponentAttributes(out, list.iterator(), bean.getComponentClass(), groupIter.next());
    }
}

From source file:org.cloudata.core.tabletserver.DiskSSTable.java

public void splitMapFile(final Row.Key midRowKey, final Tablet[] createdTablets, final String columnName,
        List<TabletMapFile> columnMapFiles, String fileId) throws IOException {

    MapFileReader[] readers = new MapFileReader[columnMapFiles.size()];
    MapFileWriter[] writers = new MapFileWriter[2];
    TabletMapFile[] mapFiles = new TabletMapFile[2];
    long targetMapFileSize = 0;

    try {//from   ww  w . ja va2  s  . co  m
        for (int i = 0; i < 2; i++) {
            GPath tempMapFilePath = new GPath(
                    Tablet.getTabletSplitTempPath(conf, createdTablets[i].getTabletInfo()),
                    columnName + "/" + fileId + "/");
            mapFiles[i] = new TabletMapFile(conf, CloudataFileSystem.get(conf),
                    createdTablets[i].getTabletInfo(), columnName, fileId, tempMapFilePath, numOfVersion);
            createdTablets[i].getDiskSSTable().addTabletMapFile(columnName, mapFiles[i]);
            writers[i] = mapFiles[i].getMapFileWriter();
        }

        TreeSet<ColumnValueEntry> workPlace = new TreeSet<ColumnValueEntry>();

        ColumnValue columnValue = null;

        for (int i = 0; i < readers.length; i++) {
            TabletMapFile mapFile = columnMapFiles.get(i);
            targetMapFileSize += mapFile.getDataFileSize();

            readers[i] = mapFile.getMapFileReader(Row.Key.MIN_KEY, Row.Key.MAX_KEY);
            columnValue = readers[i].next();
            if (columnValue != null) {
                workPlace.add(new ColumnValueEntry(columnValue, i));
            } else {
                readers[i].close();
                readers[i] = null;
            }
        }

        while (true) {
            if (workPlace.isEmpty()) {
                break;
            }

            ColumnValueEntry winnerValue = workPlace.pollFirst();
            int winnerIndex = winnerValue.index;
            columnValue = winnerValue.columnValue;

            Row.Key rowKey = columnValue.getRowKey();

            int nw = 0;
            if (rowKey.compareTo(midRowKey) > 0) {
                nw = writers[1].write(columnValue);
            } else {
                nw = writers[0].write(columnValue);
            }

            if (readers[winnerIndex] != null) {
                columnValue = readers[winnerIndex].next();

                if (columnValue != null) {
                    workPlace.add(new ColumnValueEntry(columnValue, winnerIndex));
                } else {
                    readers[winnerIndex].close();
                    readers[winnerIndex] = null;
                }
            }
        } //end of while
    } finally {
        for (int i = 0; i < writers.length; i++) {
            try {
                if (writers[i] != null) {
                    writers[i].close();
                }
            } catch (IOException e) {
                LOG.warn("IOException in closing map file writer, exception : " + e);
                for (int j = 0; j < mapFiles.length; j++) {
                    mapFiles[j].delete();
                }
                throw e;
            }
        }

        LOG.debug(columnName + " file splited from orig: " + targetMapFileSize + " to file1: "
                + mapFiles[0].getDataFileSize() + " & file2: " + mapFiles[1].getDataFileSize());

        for (int i = 0; i < readers.length; i++) {
            try {
                if (readers[i] != null) {
                    readers[i].close();
                }
            } catch (IOException e) {
                throw e;
            }
        }
    }
}

From source file:org.unitime.timetable.solver.exam.ExamSolver.java

public ExamSuggestionsInfo getSuggestions(long examId, ExamProposedChange change, String filter, int depth,
        int limit, long timeOut) {
    Lock lock = currentSolution().getLock().writeLock();
    lock.lock();// w w  w .ja  v a 2 s  . c o m
    try {
        Exam exam = getExam(examId);
        if (exam == null)
            return null;
        ExamSuggestions s = new ExamSuggestions(this);
        s.setDepth(depth);
        s.setFilter(filter);
        s.setLimit(limit);
        s.setTimeOut(timeOut);
        TreeSet<ExamProposedChange> suggestions = s.computeSuggestions(exam,
                (change == null ? null : change.getAssignments()));
        String message = null;
        if (s.wasTimeoutReached()) {
            message = "(" + (timeOut / 1000l) + "s timeout reached, " + s.getNrCombinationsConsidered()
                    + " possibilities up to " + depth + " changes were considered, ";
        } else {
            message = "(all " + s.getNrCombinationsConsidered() + " possibilities up to " + depth
                    + " changes were considered, ";
        }
        if (suggestions.isEmpty()) {
            message += "no suggestion found)";
        } else if (s.getNrSolutions() > suggestions.size()) {
            message += "top " + suggestions.size() + " of " + s.getNrSolutions() + " suggestions displayed)";
        } else {
            message += suggestions.size() + " suggestions displayed)";
        }
        return new ExamSuggestionsInfo(suggestions, message, s.wasTimeoutReached());
    } finally {
        lock.unlock();
    }
}

From source file:net.sourceforge.fenixedu.domain.student.Student.java

final public Enrolment getDissertationEnrolment(DegreeCurricularPlan degreeCurricularPlan) {
    TreeSet<Enrolment> enrolments = getDissertationEnrolments(degreeCurricularPlan);
    return enrolments.isEmpty() ? null : enrolments.last();
}

From source file:net.spfbl.core.Analise.java

private boolean process() {
    if (run) {//from  www  .  j  a  va 2s.  com
        String token = pollFirst();
        if (token == null) {
            return false;
        } else if (Subnet.isReservedIP(token)) {
            dropProcess(token);
            return false;
        } else if (Domain.isOfficialTLD(token)) {
            addResult(token, "RESERVED");
            return false;
        } else if (Generic.containsDynamic(token)) {
            addResult(token, "DYNAMIC");
            return false;
        } else if (!token.startsWith("@") && Domain.isDomain(token)) {
            add("@" + Domain.normalizeHostname(token, false));
            dropProcess(token);
            return false;
        } else if (Domain.isHostname(token)) {
            String hostname = Domain.normalizeHostname(token, true);
            TreeSet<String> ipLocalSet = Analise.getIPSet(hostname.substring(1));
            if (ipLocalSet == null) {
                if (!Generic.containsGeneric(hostname) && Block.tryAdd(hostname)) {
                    Server.logDebug("new BLOCK '" + hostname + "' added by 'NXDOMAIN'.");
                }
                addResult(hostname, "NXDOMAIN");
            } else if (ipLocalSet.isEmpty()) {
                addResult(hostname, "NONE");
            } else {
                for (String ip : ipLocalSet) {
                    add(ip);
                }
                addResult(hostname, "RESOLVED");
            }
            return false;
        } else {
            StringBuilder builder = new StringBuilder();
            Analise.process(token, builder, 20000);
            String result = builder.toString();
            if (addResult(token, result)) {
                //                    Server.logTrace(token + ' ' + result);
            }
            return true;
        }
    } else {
        return false;
    }
}