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:org.openmrs.module.privilegehelper.web.controller.PrivilegeAssignerController.java

@RequestMapping(value = "/assignPrivileges")
public String assignPrivileges(final @ModelAttribute(PRIVILEGES) SortedSet<PrivilegeLogEntry> privileges,
        final @ModelAttribute(MISSING_PRIVILEGES) SortedSet<PrivilegeLogEntry> missingPrivileges,
        final User user, @RequestParam final Integer loggedUserId, final ModelMap model) {
    User loggedUser = Context.getUserService().getUser(loggedUserId);
    if (loggedUser == null) {
        throw new IllegalArgumentException("User with id " + loggedUserId + " does not exist!");
    }/*from w  w  w  . ja  v a  2 s. c  o  m*/

    privileges.clear();
    missingPrivileges.clear();

    final List<PrivilegeLogEntry> loggedPrivileges = logger.getLoggedPrivileges(loggedUser);

    for (PrivilegeLogEntry privilege : loggedPrivileges) {
        if (StringUtils.isBlank(privilege.getPrivilege())) {
            continue;
        }

        final Privilege existingPrivilege = Context.getUserService().getPrivilege(privilege.getPrivilege());

        if (existingPrivilege != null) {
            privileges.add(new PrivilegeLogEntry(user.getUserId(), privilege.getPrivilege(),
                    privilege.isRequired(), !user.hasPrivilege(privilege.getPrivilege())));
        } else {
            missingPrivileges.add(new PrivilegeLogEntry(user.getUserId(), privilege.getPrivilege(),
                    privilege.isRequired(), !user.hasPrivilege(privilege.getPrivilege())));
        }
    }

    model.addAttribute("userId", user.getUserId());
    return "redirect:assignRoles.form";
}

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

/**
 * Returns the Attr[]s to be output for the given element.
 * <br>//from   ww  w. ja va  2 s .  com
 * IMPORTANT: This method expects to work on a modified DOM tree, i.e. a 
 * DOM which has been prepared using 
 * {@link org.apache.xml.security.utils.XMLUtils#circumventBug2650(
 * org.w3c.dom.Document)}.
 * 
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributes(Element element, NameSpaceSymbTable ns)
        throws CanonicalizationException {
    // result will contain the attrs which have to be output
    xmlattrStack.push(ns.getLevel());
    boolean isRealVisible = isVisibleDO(element, ns.getLevel()) == 1;
    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)) {
                //A non namespace definition node.
                if (XML_LANG_URI.equals(NUri)) {
                    if (NName.equals("id")) {
                        if (isRealVisible) {
                            // treat xml:id like any other attribute 
                            // (emit it, but don't inherit it)
                            result.add(attribute);
                        }
                    } else {
                        xmlattrStack.addXmlnsAttr(attribute);
                    }
                } else if (isRealVisible) {
                    //The node is visible add the attribute to the list of output attributes.
                    result.add(attribute);
                }
            } else if (!XML.equals(NName) || !XML_LANG_URI.equals(NValue)) {
                /* except omit namespace node with local name xml, which defines
                 * the xml prefix, if its string value is 
                 * http://www.w3.org/XML/1998/namespace.
                 */
                // add the prefix binding to the ns symb table.
                if (isVisible(attribute)) {
                    if (isRealVisible || !ns.removeMappingIfRender(NName)) {
                        // The xpath select this node output it if needed.
                        Node n = ns.addMappingAndRender(NName, NValue, attribute);
                        if (n != null) {
                            result.add((Attr) n);
                            if (C14nHelper.namespaceIsRelative(attribute)) {
                                Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
                                throw new CanonicalizationException("c14n.Canonicalizer.RelativeNamespace",
                                        exArgs);
                            }
                        }
                    }
                } else {
                    if (isRealVisible && !XMLNS.equals(NName)) {
                        ns.removeMapping(NName);
                    } else {
                        ns.addMapping(NName, NValue, attribute);
                    }
                }
            }
        }
    }

    if (isRealVisible) {
        //The element is visible, handle the xmlns definition        
        Attr xmlns = element.getAttributeNodeNS(XMLNS_URI, XMLNS);
        Node n = null;
        if (xmlns == null) {
            //No xmlns def just get the already defined.
            n = ns.getMapping(XMLNS);
        } else if (!isVisible(xmlns)) {
            //There is a definition but the xmlns is not selected by the xpath.
            //then xmlns=""
            n = ns.addMappingAndRender(XMLNS, "", nullNode);
        }
        //output the xmlns def if needed.
        if (n != null) {
            result.add((Attr) n);
        }
        //Float all xml:* attributes of the unselected parent elements to this one. 
        xmlattrStack.getXmlnsAttr(result);
        ns.getUnrenderedNodes(result);
    }

    return result.iterator();
}

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

void preLogRoll(Path newLog) throws IOException {

    synchronized (this.hlogsById) {
        String name = newLog.getName();
        for (ReplicationSourceInterface source : this.sources) {
            try {
                this.replicationQueues.addLog(source.getPeerClusterZnode(), name);
            } catch (ReplicationException e) {
                throw new IOException("Cannot add log to replication queue with id="
                        + source.getPeerClusterZnode() + ", filename=" + name, e);
            }//from ww  w .j a v a 2s  .c  o m
        }
        for (SortedSet<String> hlogs : this.hlogsById.values()) {
            if (this.sources.isEmpty()) {
                // If there's no slaves, don't need to keep the old hlogs since
                // we only consider the last one when a new slave comes in
                hlogs.clear();
            }
            hlogs.add(name);
        }
    }

    this.latestPath = newLog;
}

From source file:org.cloudata.core.commitlog.pipe.BufferPool.java

int clearExpiredEntries(int msec) {
    PoolEntry e = new PoolEntry((System.currentTimeMillis() + 10) - msec);
    int sizeOfDeallocated = 0;

    synchronized (bufferMap) {
        Iterator<TreeSet<PoolEntry>> iter = bufferMap.values().iterator();
        while (iter.hasNext()) {
            TreeSet<PoolEntry> entrySet = iter.next();
            SortedSet<PoolEntry> expiredSet = entrySet.headSet(e);

            if (expiredSet.isEmpty() == false) {
                LOG.debug(expiredSet.size() + " pool entries are removed");
                Iterator<PoolEntry> expiredIter = expiredSet.iterator();

                while (expiredIter.hasNext()) {
                    PoolEntry expiredEntry = expiredIter.next();
                    poolMonitor.deallocated(expiredEntry.buffer.capacity());
                    sizeOfDeallocated += expiredEntry.buffer.capacity();
                }//from   w w  w  .ja v  a2 s.  c o m

                expiredSet.clear();

                if (entrySet.isEmpty()) {
                    LOG.debug("entry set is removed");
                    iter.remove();
                }
            }
        }
    }

    return sizeOfDeallocated;
}

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

/**
 * {@inheritDoc}//  w w  w.  j  a v  a  2 s.co  m
 */
@Override
public void mergeLicenses(LicenseMap licenseMap, String... licenses) {
    if (licenses.length == 0) {
        return;
    }

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

From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Removes all elements in the {@link Set} for the given
 * {@link DeviceProtocolInfoSource}.//from w  w  w. j av a2s.com
 *
 * @param type The {@link DeviceProtocolInfoSource} type to clear.
 */
public void clear(DeviceProtocolInfoSource<?> type) {
    setsLock.writeLock().lock();
    try {
        SortedSet<ProtocolInfo> set = protocolInfoSets.get(type);
        if (set != null) {
            set.clear();
            updateImageProfiles();
        }
    } finally {
        setsLock.writeLock().unlock();
    }
}

From source file:org.orcid.persistence.adapter.impl.Jaxb2JpaAdapterImpl.java

private void setKeywords(ProfileEntity profileEntity, Keywords keywords) {
    SortedSet<ProfileKeywordEntity> profileKeywordEntities = null;
    if (profileEntity != null) {
        profileKeywordEntities = profileEntity.getKeywords();
        if (profileKeywordEntities != null) {
            profileKeywordEntities.clear();
        }// w w w. j a  va2s .  c o m
    }
    if (keywords != null && keywords.getKeyword() != null && !keywords.getKeyword().isEmpty()) {
        profileEntity.setKeywordsVisibility(keywords.getVisibility());
        List<Keyword> keywordList = keywords.getKeyword();
        if (keywordList != null && !keywordList.isEmpty()) {
            if (profileKeywordEntities == null) {
                profileKeywordEntities = new TreeSet<ProfileKeywordEntity>();
            }
            for (Keyword keyword : keywordList) {
                if (StringUtils.isNotBlank(keyword.getContent())) {
                    profileKeywordEntities.add(new ProfileKeywordEntity(profileEntity, keyword.getContent()));
                }
            }

        }
    }
    profileEntity.setKeywords(profileKeywordEntities);
}

From source file:com.github.FraggedNoob.GitLabTransfer.GitlabRelatedData.java

/**
 * Obtains the notes for a project issue.
 * @param i The Gitlab Issue to pull from
 * @param notes A SortedSet of notes by IID.  Empty means error or no
 * notes in the issue, see return value.
 * /*from w w w. j a  v  a  2 s .c  om*/
 * @return F indicates a problem, beware T may mean there are no notes.
 */
public boolean getIssueNotes(final GitlabIssue i, SortedSet<GitlabNote> notes) {

    if (!createApi()) {
        return false;
    }

    notes.clear();
    List<GitlabNote> noteList;

    try {
        noteList = api.getNotes(i);
    } catch (IOException e) {
        System.out.printf("Error getting notes from issue IID=%d.\n", i.getIid());
        e.printStackTrace();
        return false;
    }

    /*
     * Uniquely sort the list of issues by IID
     */
    try {
        notes.addAll(noteList);
    } catch (Exception e) {
        System.out.println("Error parsing notes - bad data.");
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:org.codehaus.mojo.license.api.DefaultThirdPartyTool.java

/**
 * {@inheritDoc}//  www .  ja v  a 2  s.c om
 */
public void mergeLicenses(LicenseMap licenseMap, String mainLicense, Set<String> licenses) {

    if (licenses.isEmpty()) {

        // nothing to merge, is this can really happen ?
        return;
    }

    SortedSet<MavenProject> mainSet = licenseMap.get(mainLicense);
    if (mainSet == null) {
        if (isVerbose()) {
            getLogger().warn("No license [" + mainLicense + "] found, will create it.");
        }
        mainSet = new TreeSet<MavenProject>(projectComparator);
        licenseMap.put(mainLicense, mainSet);
    }
    for (String license : licenses) {
        SortedSet<MavenProject> set = licenseMap.get(license);
        if (set == null) {
            if (isVerbose()) {
                getLogger().warn("No license [" + license + "] found, skip the merge to [" + mainLicense + "]");
            }
            continue;
        }
        if (isVerbose()) {
            getLogger().info("Merge license [" + license + "] to [" + mainLicense + "] (" + set.size()
                    + " dependencies).");
        }
        mainSet.addAll(set);
        set.clear();
        licenseMap.remove(license);
    }
}

From source file:org.commoncrawl.util.ArcFileWriter.java

/**
 * append a pre-generated arcfile entry directly into the arc file writer
 * //from  w  w  w  .  j av a  2  s.co m
 * @param arcFileData
 *          - the compressed arc file entry
 * @param dataBufferLength
 *          - the entry length
 * @throws IOException
 */
public void writeRawArcFileItem(String contentType, byte[] arcFileData, int dataBufferLength)
        throws IOException {
    // check to see if we need to start a new underlying file
    checkSize(0, dataBufferLength);
    // update stats
    getActiveFile()._totalContentBytesWritten += dataBufferLength;
    getActiveFile()._itemsWritten++;
    SortedSet<Integer> counts = _mimeTypeCounts.get(contentType);
    if (counts.size() == 0) {
        counts.add(1);
    } else {
        int count = counts.first() + 1;
        counts.clear();
        counts.add(count);
    }
    // record start position of this item
    _lastItemPos = getActiveFile().getFileSize();
    // write out data
    _out.write(arcFileData, 0, dataBufferLength);
    // record size of last item
    _lastItemCompressedSize = (getActiveFile().getFileSize() - _lastItemPos);
    // update stats
    getActiveFile()._compressedBytesWritten += _lastItemCompressedSize;
}