Example usage for java.util Collection clear

List of usage examples for java.util Collection clear

Introduction

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

Prototype

void clear();

Source Link

Document

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

Usage

From source file:org.jactr.core.runtime.controller.debug.DebugController.java

/**
 * @see org.jactr.core.runtime.controller.debug.IDebugController#clearBreakpoints(org.jactr.core.model.IModel,
 *      org.jactr.core.runtime.controller.debug.BreakpointType)
 *//*from ww w.j  a  va2 s .  c om*/
public void clearBreakpoints(IModel model, BreakpointType type) {
    try {
        _lock.lock();
        Collection<IModel> forModels = _breakpoints.keySet();
        if (model != null)
            forModels = Collections.singleton(model);

        for (IModel m : forModels) {
            Map<BreakpointType, Collection<Object>> maps = _breakpoints.get(model);
            Collection<BreakpointType> types = Arrays.asList(BreakpointType.values());
            if (type != null)
                types = Collections.singleton(type);

            if (maps != null) {
                for (BreakpointType t : types) {
                    if (LOGGER.isDebugEnabled())
                        LOGGER.debug("Clearing break points of " + t + " for " + m);
                    Collection<Object> points = maps.get(t);
                    if (points != null)
                        points.clear();
                }
                maps.clear();
            }

        }
        _breakpoints.clear();
    } finally {
        _lock.unlock();
    }
}

From source file:org.ejbca.ui.web.pub.retrieve.CertificateFinderBean.java

/**
 * Uses the store session to look up all certificates for a subject.
 * The parameter <code>result</code> is updated so that it contains
 * the certificates as CertificateView objects.
 * @param subject The DN of the subject/*from ww  w .java2 s .  c o  m*/
 * @param result a Collection (not null) that will be filled by CertificateView objects
 */
public void lookupCertificatesBySubject(String subject, Collection<CertificateView> result) {
    if (log.isTraceEnabled()) {
        log.trace(">lookupCertificatesBySubject(" + subject + ", " + result + ")");
    }
    if (result == null) {
        return; // There's nothing we can do here.
    }
    result.clear();
    if (subject == null || mInitialized == false) {
        return; // We can't lookup any certificates, so return with an empty result.
    }
    Collection<Certificate> certificates = mStoreSession.findCertificatesBySubject(subject);
    if (certificates != null) {
        Iterator<Certificate> i = certificates.iterator();
        while (i.hasNext()) {
            Certificate cert = i.next();
            // TODO: CertificateView is located in web.admin package, but this is web.pub package...
            CertificateView view = new CertificateView(cert, null, null);
            result.add(view);
        }
    }
}

From source file:org.kitodo.production.forms.dataeditor.FieldedMetadataTableRow.java

/**
 * This method is triggered when the user clicks the insert meta-data
 * button.//from  w  w w. j ava 2 s  . c  om
 */
void pasteClick() {
    try {
        Collection<Metadata> clipboard = panel.getClipboard();
        preserve();
        metadata.addAll(clipboard);
        clipboard.clear();
        createMetadataTable();
    } catch (NoSuchMetadataFieldException | InvalidMetadataValueException e) {
        Helper.setErrorMessage(e.getLocalizedMessage());
    }
}

From source file:org.openanzo.rdf.utils.MultiTreeMap.java

/**
 * Clear the map./*from  w  w  w.  j ava2  s  .c o  m*/
 * <p/>
 * This clears each collection in the map, and so may be slow.
 */
public void clear() {
    // For gc, clear each list in the map
    Set<Map.Entry<K, Collection<V>>> pairs = internalMap.entrySet();
    Iterator<Map.Entry<K, Collection<V>>> pairsIterator = pairs.iterator();
    while (pairsIterator.hasNext()) {
        Map.Entry<K, Collection<V>> keyValuePair = pairsIterator.next();
        Collection<V> coll = keyValuePair.getValue();
        coll.clear();
    }
    internalMap.clear();
}

From source file:org.sjmvc.binding.AbstractBinder.java

/**
 * Set the values in a collection property.
 * //from  w ww  . j av a2 s  .  c o  m
 * @param field The field to set.
 * @param currentObject The object being processed.
 * @param name The name of the collection property.
 * @param values The values to set.
 * @throws Exception If the values cannot be set in the collection property.
 */
protected void setCollectionValues(Field field, Object currentObject, String name, String values[])
        throws Exception {
    LOGGER.trace("Setting [{}] to {} collection", StringUtils.join(values, ", "), name);

    // Get the type of the elements in the collection
    Class<?> elementsType = ReflectionUtils.getFieldCollectionType(name, currentObject.getClass());

    // Get the collection and clear it
    @SuppressWarnings("unchecked")
    Collection<Object> col = (Collection<Object>) ReflectionUtils.getProperty(currentObject, name);

    if (col == null) {
        LOGGER.trace("Collection property {} is null. Creating it", name);

        col = new ArrayList<Object>();
    }

    // Add the values to the collection
    col.clear();

    for (String currentValue : values) {
        col.add(ReflectionUtils.fromString(elementsType, currentValue));
    }

    // Save the collection in the object
    ReflectionUtils.setValue(currentObject, name, col);
}

From source file:org.bedework.dumprestore.restore.Restore.java

private void createNewSystem() throws Throwable {
    // Create the public user.

    BwPrincipal pu = BwPrincipal.makeUserPrincipal();

    pu.setAccount(RestoreGlobals.getBasicSyspars().getPublicUser());
    globals.setPrincipalHref(pu);//from   w ww  .  j av a 2s.  c  o m

    globals.rintf.restorePrincipal(pu);

    // Create the root user.

    BwPrincipal rootUser = BwPrincipal.makeUserPrincipal();

    rootUser.setAccount(rootId);
    globals.setPrincipalHref(rootUser);

    globals.rintf.restorePrincipal(rootUser);

    // Create the an authuser entry for the root user.

    BwAuthUser au = new BwAuthUser();
    au.setUserHref(rootUser.getPrincipalRef());
    au.setUsertype(UserAuth.allAuth);
    au.setPrefs(BwAuthUserPrefs.makeAuthUserPrefs());

    globals.rintf.restoreAuthUser(au);

    // Create a group for all public admin groups

    BwAdminGroup g = new BwAdminGroup();

    String publicAdminGroupsAccount = "publicAdminGroups"; // XXX Put into config
    g.setAccount(publicAdminGroupsAccount);
    g.setGroupOwnerHref(pu.getPrincipalRef());
    g.setOwnerHref(pu.getPrincipalRef());

    if (!globals.onlyUsersMap.check(g.getGroupOwnerHref())) {
        g.setGroupOwnerHref(globals.getPublicUser().getPrincipalRef());
    }

    globals.rintf.restoreAdminGroup(g);

    // Create the public root.

    Collection<Privilege> privs = new ArrayList<Privilege>();
    privs.add(Privileges.makePriv(PrivilegeDefs.privRead));

    Collection<Ace> aces = new ArrayList<Ace>();

    aces.add(Ace.makeAce(AceWho.other, privs, null));

    privs.clear();
    privs.add(Privileges.makePriv(PrivilegeDefs.privRead));
    privs.add(Privileges.makePriv(PrivilegeDefs.privWriteContent));

    AceWho who = AceWho.getAceWho(publicAdminGroupsAccount, WhoDefs.whoTypeGroup, false);
    aces.add(Ace.makeAce(who, privs, null));

    makeCal(null, pu, BwCalendar.calTypeFolder, RestoreGlobals.getBasicSyspars().getPublicCalendarRoot(),
            new String(new Acl(aces).encode()));

    // Create the user root.

    privs.clear();
    privs.add(Privileges.makePriv(PrivilegeDefs.privAll));

    aces.clear();
    aces.add(Ace.makeAce(AceWho.owner, privs, null));

    BwCalendar userRoot = makeCal(null, pu, BwCalendar.calTypeFolder,
            RestoreGlobals.getBasicSyspars().getUserCalendarRoot(), new String(new Acl(aces).encode()));

    makeUserHome(userRoot, pu);
    makeUserHome(userRoot, rootUser);
}

From source file:ddf.catalog.validation.impl.ValidationParser.java

private void commitStaged(Collection<Callable<Boolean>> stagedAdds) throws Exception {
    for (Callable<Boolean> staged : stagedAdds) {
        try {// w ww  . ja v a  2  s .c  o  m
            staged.call();
        } catch (RuntimeException e) {
            LOGGER.warn("Error adding staged item {}", staged, e);
        }
    }
    stagedAdds.clear();
}

From source file:com.icesoft.faces.async.common.PushServerAdaptingServlet.java

public PushServerAdaptingServlet(final HttpSession httpSession, final String iceFacesId,
        final Collection synchronouslyUpdatedViews, final ViewQueue allUpdatedViews,
        final Configuration configuration, final CoreMessageService coreMessageService)
        throws MessageServiceException {
    blockingRequestHandlerContext = configuration.getAttribute("blockingRequestHandlerContext", "push-server");
    allUpdatedViews.onPut(new Runnable() {
        public void run() {
            allUpdatedViews.removeAll(synchronouslyUpdatedViews);
            synchronouslyUpdatedViews.clear();
            Set _viewIdentifierSet = new HashSet(allUpdatedViews);
            if (!_viewIdentifierSet.isEmpty()) {
                Long _sequenceNumber;
                synchronized (lock) {
                    _sequenceNumber = (Long) httpSession.getAttribute(SEQUENCE_NUMBER_KEY);
                    if (_sequenceNumber != null) {
                        _sequenceNumber = new Long(_sequenceNumber.longValue() + 1);
                    } else {
                        _sequenceNumber = new Long(1);
                    }//from  www.  ja v  a2s . c  om
                    httpSession.setAttribute(SEQUENCE_NUMBER_KEY, _sequenceNumber);
                }
                String[] _viewIdentifiers = (String[]) _viewIdentifierSet
                        .toArray(new String[_viewIdentifierSet.size()]);
                StringWriter _stringWriter = new StringWriter();
                for (int i = 0; i < _viewIdentifiers.length; i++) {
                    if (i != 0) {
                        _stringWriter.write(',');
                    }
                    _stringWriter.write(_viewIdentifiers[i]);
                }
                Properties _messageProperties = new Properties();
                _messageProperties.setStringProperty(Message.DESTINATION_SERVLET_CONTEXT_PATH,
                        blockingRequestHandlerContext);
                coreMessageService.publish(iceFacesId + ";" + // ICEfaces ID
                _sequenceNumber + ";" + // Sequence Number
                _stringWriter.toString(), // Message Body
                        _messageProperties, UPDATED_VIEWS_MESSAGE_TYPE, MessageServiceClient.PUSH_TOPIC_NAME);
            }
        }
    });
}

From source file:co.turnus.analysis.bottlenecks.AlgorithmicBottlenecks.java

protected double[] measure(Table<String, String, Double> ratiosTable) {
    // check if the trace should be initialised
    initTrace();//from w ww .  j av a 2s .c o m

    Trace trace = project.getTrace();
    double[] cp = { 0, 0 };
    iterationId++;

    Collection<Step> predecessors = Sets.newHashSet();
    for (long stepId = 0; stepId < trace.getLength(); stepId++) {
        Step step = trace.getStep(stepId);
        double[] cl = getWeight(step, ratiosTable);

        predecessors.clear();
        for (Dependency in : step.getIncomings()) {
            predecessors.add(in.getSource());
        }

        double[] pcp = { 0, 0 };
        for (Step pred : predecessors) {
            double[] tmpPcp = pred.getAttribute(PARTIAL_CP + iterationId);
            if (tmpPcp[MEAN] > pcp[MEAN]) {
                pcp[MEAN] = tmpPcp[MEAN];
                pcp[VARIANCE] = tmpPcp[VARIANCE];
            }
        }

        pcp[MEAN] += cl[MEAN];
        pcp[VARIANCE] += cl[VARIANCE];
        step.setAttribute(PARTIAL_CP + iterationId, pcp);

        // update the global one
        if (pcp[MEAN] > cp[MEAN]) {
            cp = pcp;
        }
    }

    return cp;
}

From source file:org.onehippo.forge.solr.indexer.task.SolrIndexer.java

/**
 * Index documents//w  w  w. ja  va  2 s. c om
 * @param documents Documents
 * @param totalDocuments Total documents (will be updated)
 * @throws IOException -
 * @throws SolrServerException -
 */
private void index(Collection<SolrInputDocument> documents, MutableInt totalDocuments)
        throws IOException, SolrServerException {
    if (!documents.isEmpty()) {
        log.info("Indexing {} documents", documents.size());
        server.add(documents);
        totalDocuments.add(documents.size());
        documents.clear();
    }
}