Example usage for java.util SortedSet clear

List of usage examples for java.util SortedSet clear

Introduction

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

Prototype

void clear();

Source Link

Document

Removes all of the elements from this set (optional operation).

Usage

From source file:com.enitalk.controllers.youtube.CalendarTest.java

public static void main(String[] args) throws IOException {

    InputStream is = new ClassPathResource("events.json").getInputStream();
    ObjectMapper jackson = new ObjectMapper();
    JsonNode tree = jackson.readTree(is);
    IOUtils.closeQuietly(is);// ww  w. j  av  a 2 s .com

    DateTimeFormatter fmtDateTime = ISODateTimeFormat.dateTimeNoMillis();
    DateTimeFormatter fmt = ISODateTimeFormat.date();

    TreeMultimap<DateTime, DateTime> set = CalendarTest.getPeriodSet(10, 18);

    Iterator<JsonNode> nodes = tree.elements();
    while (nodes.hasNext()) {
        JsonNode ev = nodes.next();
        boolean isFullDay = ev.path("start").has("date");

        DateTime stDate = isFullDay ? fmt.parseDateTime(ev.path("start").path("date").asText())
                : fmtDateTime.parseDateTime(ev.path("start").path("dateTime").asText());

        DateTime enDate = isFullDay ? fmt.parseDateTime(ev.path("end").path("date").asText())
                : fmtDateTime.parseDateTime(ev.path("end").path("dateTime").asText());

        System.out.println("St " + stDate + " en " + enDate);

        int days = Days.daysBetween(stDate, enDate).getDays();
        System.out.println("Days between " + days);
        if (isFullDay) {
            switch (days) {
            case 1:
                set.removeAll(stDate);
                break;
            default:
                while (days-- > 0) {
                    set.removeAll(stDate.plusDays(days));
                }
            }
        } else {
            DateTime copySt = stDate.minuteOfHour().setCopy(0).secondOfMinute().setCopy(0);
            DateTime copyEn = enDate.plusHours(1).minuteOfHour().setCopy(0).secondOfMinute().setCopy(0);

            //                System.out.println("Dates truncated " + copySt + " " + copyEn);
            //                System.out.println("Ll set " + set);

            //                System.out.println("Getting set for key " + stDate.millisOfDay().setCopy(0));
            SortedSet<DateTime> ss = set.get(stDate.millisOfDay().setCopy(0));
            SortedSet<DateTime> subset = ss.subSet(copySt, copyEn);
            subset.clear();
            set.remove(enDate.millisOfDay().setCopy(0), copyEn);
        }

    }

}

From source file:net.sourceforge.fenixedu.presentationTier.docs.academicAdministrativeOffice.ApprovementInfoForEquivalenceProcess.java

public static String getApprovementsInfo(final Registration registration) {

    final StringBuilder res = new StringBuilder();

    final SortedSet<ICurriculumEntry> entries = new TreeSet<ICurriculumEntry>(
            ICurriculumEntry.COMPARATOR_BY_EXECUTION_PERIOD_AND_NAME_AND_ID);

    final Map<Unit, String> ids = new HashMap<Unit, String>();
    if (registration.isBolonha()) {
        reportCycles(res, entries, ids, registration);
    } else {//from   ww  w  .  java2  s  .c om
        final ICurriculum curriculum = registration.getCurriculum();
        filterEntries(entries, curriculum);
        reportEntries(res, entries, ids, registration);
    }

    entries.clear();
    entries.addAll(getExtraCurricularEntriesToReport(registration));
    if (!entries.isEmpty()) {
        reportRemainingEntries(res, entries, ids,
                registration.getLastStudentCurricularPlan().getExtraCurriculumGroup(), registration);
    }

    entries.clear();
    entries.addAll(getPropaedeuticEntriesToReport(registration));
    if (!entries.isEmpty()) {
        reportRemainingEntries(res, entries, ids,
                registration.getLastStudentCurricularPlan().getPropaedeuticCurriculumGroup(), registration);
    }

    res.append(getRemainingCreditsInfo(registration.getCurriculum()));

    res.append(LINE_BREAK);

    if (!ids.isEmpty()) {
        res.append(LINE_BREAK).append(getAcademicUnitInfo(ids));
    }

    return res.toString();
}

From source file:org.shredzone.cilla.ws.assembler.PictureAssembler.java

@Override
public void merge(PictureDto dto, Picture entity) throws CillaServiceException {
    super.merge(dto, entity);
    entity.setCreateDate(dto.getCreateDate());

    entity.setCreateTimeZone(dto.getCreateTimeZone());
    entity.setCreateTimeDefinition(dto.getCreateTimeDefinition());
    entity.getThread().setCommentable(dto.isCommentable());

    if (dto.getCaption() != null && dto.getCaptionFormat() != null) {
        entity.setCaption(new FormattedText(dto.getCaption(), dto.getCaptionFormat()));
    } else {//w  w  w  .  j a  v a  2s.com
        entity.setCaption(null);
    }

    if (dto.getLongitude() != null && dto.getLatitude() != null) {
        Geolocation gl = new Geolocation();
        gl.setLongitude(dto.getLongitude());
        gl.setLatitude(dto.getLatitude());
        gl.setAltitude(dto.getAltitude());
        entity.setLocation(gl);
    } else {
        entity.setLocation(null);
    }

    SortedSet<Tag> tagSet = entity.getTags();
    tagSet.clear();
    dto.getTags().stream().map(tagDao::fetchOrCreate).forEach(tag -> tagSet.add(tag));
}

From source file:com.benfante.minimark.blo.QuestionBo.java

/**
 * Update the set of tags of a question.
 *
 * @param question The question to update
 *///w  w w . ja  va  2s  .c o m
private void updateTagSet(Question question) {
    String[] tags = question.getTagList().split(",");
    SortedSet<TagQuestionLink> currentTags = question.getTags();
    SortedSet<TagQuestionLink> oldTags = new TreeSet<TagQuestionLink>(currentTags);
    currentTags.clear();
    for (String stag : tags) {
        if (StringUtils.isNotBlank(stag)) {
            stag = stag.trim().toLowerCase();
            TagQuestionLink tagLink = searchInSet(stag, oldTags);
            if (tagLink == null) {
                // new tag for this post
                Tag tag = tagDao.findByName(stag);
                if (tag == null) {
                    // totally new tag
                    tag = new Tag(stag);
                    tagDao.store(tag);
                }
                tagLink = new TagQuestionLink(tag, question);
            }
            currentTags.add(tagLink);
        }
    }
}

From source file:org.apache.ctakes.ytex.libsvm.LibSVMGramMatrixExporterImpl.java

private double[][] loadGramMatrix(String name, String experiment, double param1, String param2,
        String splitName, String label, int run, int fold, InstanceData instanceData,
        SortedSet<Long> instanceIds, Map<Long, Integer> mapInstanceIdToIndex) {
    double[][] gramMatrix;
    instanceIds.clear();
    mapInstanceIdToIndex.clear();/*  w w  w  .j av a  2 s .co  m*/
    instanceIds.addAll(instanceData.getAllInstanceIds(label, run, fold));
    int index = 0;
    for (long instanceId : instanceIds) {
        mapInstanceIdToIndex.put(instanceId, index++);
    }
    gramMatrix = this.kernelUtil.loadGramMatrix(instanceIds, name, splitName, experiment, label, run, fold,
            param1, param2);
    return gramMatrix;
}

From source file:gov.nih.nci.caarray.application.fileaccess.FileAccessServiceBean.java

private void removeFile(CaArrayFile caArrayFile) {
    // A hibernate bug is preventing us from simply calling caArrayFile.getProject().getFiles().remove(caArrayFile)
    // https://hibernate.onjira.com/browse/HHH-3799
    // The workaround is to clear the collection and re-add everything we don't want to delete.
    // This is in reference to issue ARRAY-2349.
    SortedSet<CaArrayFile> files = caArrayFile.getProject().getFiles();
    SortedSet<CaArrayFile> filesToKeep = new TreeSet<CaArrayFile>();
    Long fileId = caArrayFile.getId();
    for (CaArrayFile file : files) {
        if (!file.getId().equals(fileId)) {
            filesToKeep.add(file);/*from  ww  w .  j  a  v a  2s. co m*/
        }
    }
    files.clear();
    files.addAll(filesToKeep);
    this.fileDao.remove(caArrayFile);
}

From source file:org.codehaus.mojo.license.LicenseMap.java

public void mergeLicenses(String... licenses) {
    if (licenses.length == 0) {
        return;// ww  w . j  av a2 s .  co m
    }

    String mainLicense = licenses[0].trim();
    SortedSet<MavenProject> mainSet = get(mainLicense);
    if (mainSet == null) {
        getLog().warn("No license [" + mainLicense + "] found, will create it.");
        mainSet = new TreeSet<MavenProject>(ArtifactHelper.getProjectComparator());
        put(mainLicense, mainSet);
    }
    int size = licenses.length;
    for (int i = 1; i < size; i++) {
        String license = licenses[i].trim();
        SortedSet<MavenProject> set = get(license);
        if (set == null) {
            getLog().warn("No license [" + license + "] found, skip this merge.");
            continue;
        }
        getLog().info("Merge license [" + license + "] (" + set.size() + " depedencies).");
        mainSet.addAll(set);
        set.clear();
        remove(license);
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.docs.academicAdministrativeOffice.ApprovementInfoForEquivalenceProcess.java

static private void reportCycles(final StringBuilder result, final SortedSet<ICurriculumEntry> entries,
        final Map<Unit, String> academicUnitIdentifiers, final Registration registration) {
    final Collection<CycleCurriculumGroup> cycles = new TreeSet<CycleCurriculumGroup>(
            CycleCurriculumGroup.COMPARATOR_BY_CYCLE_TYPE_AND_ID);
    cycles.addAll(registration.getLastStudentCurricularPlan().getInternalCycleCurriculumGrops());

    CycleCurriculumGroup lastReported = null;
    for (final CycleCurriculumGroup cycle : cycles) {
        if (!cycle.isConclusionProcessed() || isDEARegistration(registration)) {
            // final ApprovementCertificateRequest request =
            // ((ApprovementCertificateRequest) getDocumentRequest());
            final Curriculum curriculum = cycle.getCurriculum();
            filterEntries(entries, curriculum);

            if (!entries.isEmpty()) {
                if (lastReported == null) {
                    lastReported = cycle;
                } else {
                    result.append(LINE_BREAK);
                }/*  w w  w. ja  v  a  2 s  .  co m*/

                result.append(getMLSTextContent(cycle.getName())).append(":").append(LINE_BREAK);
                reportEntries(result, entries, academicUnitIdentifiers, registration);
            }

            entries.clear();
        }
    }
}

From source file:org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager.java

/**
 * Cleans a log file and all older files from ZK. Called when we are sure that a
 * log file is closed and has no more entries.
 * @param key Path to the log//from  w  w w . j a  v a2  s  . c  o  m
 * @param id id of the peer cluster
 * @param queueRecovered Whether this is a recovered queue
 */
public void cleanOldLogs(String key, String id, boolean queueRecovered) {
    synchronized (this.hlogsById) {
        SortedSet<String> hlogs = this.hlogsById.get(id);
        if (queueRecovered || hlogs.first().equals(key)) {
            return;
        }
        SortedSet<String> hlogSet = hlogs.headSet(key);
        for (String hlog : hlogSet) {
            this.replicationQueues.removeLog(id, hlog);
        }
        hlogSet.clear();
    }
}

From source file:org.apache.xml.security.c14n.implementations.Canonicalizer11.java

/**
 * Returns the Attr[]s to be output for the given element.
 * <br>//  w w  w  .j av  a  2 s  .co  m
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- 
 * subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
        throws CanonicalizationException {
    if (!element.hasAttributes() && !firstCall) {
        return null;
    }
    // result will contain the attrs which have to be output
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            String NUri = attribute.getNamespaceURI();
            String NName = attribute.getLocalName();
            String NValue = attribute.getValue();

            if (!XMLNS_URI.equals(NUri)) {
                // It's not a namespace attr node. Add to the result and continue.
                result.add(attribute);
            } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
                // The default mapping for xml must not be output.
                Node n = ns.addMappingAndRender(NName, NValue, attribute);

                if (n != null) {
                    // Render the ns definition
                    result.add((Attr) n);
                    if (C14nHelper.namespaceIsRelative(attribute)) {
                        Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
                        throw new CanonicalizationException("c14n.Canonicalizer.RelativeNamespace", exArgs);
                    }
                }
            }
        }
    }

    if (firstCall) {
        // It is the first node of the subtree
        // Obtain all the namespaces defined in the parents, and added to the output.
        ns.getUnrenderedNodes(result);
        // output the attributes in the xml namespace.
        xmlattrStack.getXmlnsAttr(result);
        firstCall = false;
    }

    return result.iterator();
}