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:StringUtils.java

/**
 * Parse String to ANY collection you specify and trim each item.
 * /*  w w  w  .  j ava 2s . c o  m*/
 * @param strParse -
 *          String to parse
 * @param strDel -
 *          String deliminer
 * @param container -
 *          if specified then it will be filled with items (it WILL NOT be
 *          emptied first). If this is null, the default collection will be
 *          allocated. This allows you here to pass list or set so this method
 *          is more flexible.
 * @param bTrim -
 *          should it be trimmed or not
 * @param iConvertCase -
 *          how to convert the case of the string - one of the CASE_XXX
 *          costants
 * @return Collection - parsed collection, if container was specified, the
 *         same object will be returned. If it was not specified default
 *         object will be returned. If strParse was not null, then this will
 *         be not null.
 */
public static Collection parseStringToCollection(String strParse, String strDel, boolean bTrim,
        int iConvertCase, Collection container) {
    Collection colReturn;

    if (strParse == null || strParse.length() < 1) {
        if (container != null) {
            colReturn = container;
        } else {
            colReturn = null;
        }
    } else {
        // TODO: Performance: StringTokenizer is considered to be slow
        // because it creates lots of objects internally, consider replacing
        // this with String.indexOf(delimiter)
        StringTokenizer strTokParse = new StringTokenizer(strParse, strDel);
        String strTemp;

        if (container == null) {
            // This has to be List since parseStringToList requires it
            colReturn = new ArrayList();
        } else {
            container.clear();
            colReturn = container;
        }

        if (strParse.startsWith(strDel)) {
            // If the string starts with the delimiter, tokenizer would skip it
            // but we have to have empty element in front
            colReturn.add("");
        }

        while (strTokParse.hasMoreTokens()) {
            strTemp = (String) strTokParse.nextToken();
            if (bTrim) {
                strTemp = strTemp.trim();
            }
            switch (iConvertCase) {
            case (CASE_ORIGINAL): {
                // do nothing
                break;
            }
            case (CASE_TOUPPER): {
                strTemp = strTemp.toUpperCase();
                break;
            }
            case (CASE_TOLOWER): {
                strTemp = strTemp.toLowerCase();
                break;
            }
            default: {
                assert false : "Incorrect case specification.";
            }
            }
            colReturn.add(strTemp);
        }
    }
    return colReturn;
}

From source file:ubic.gemma.persistence.service.genome.sequenceAnalysis.AnnotationAssociationDaoImpl.java

@Override
public Collection<AnnotationAssociation> load(Collection<Long> ids) {
    if (ids.size() == 0) {
        return new HashSet<>();
    }//from w w w . java 2 s.co m
    int BATCH_SIZE = 2000;

    //language=HQL
    final String queryString = "select a from AnnotationAssociation a where a.id in (:ids)";
    Collection<Long> batch = new HashSet<>();
    Collection<AnnotationAssociation> results = new HashSet<>();

    for (Long id : ids) {
        batch.add(id);
        if (batch.size() == BATCH_SIZE) {
            //noinspection unchecked
            results.addAll(this.getSessionFactory().getCurrentSession().createQuery(queryString)
                    .setParameterList("ids", batch).list());
            batch.clear();
        }
    }
    if (batch.size() > 0) {
        //noinspection unchecked
        results.addAll(this.getSessionFactory().getCurrentSession().createQuery(queryString)
                .setParameterList("ids", batch).list());
    }

    return results;
}

From source file:org.jactr.core.module.declarative.search.local.DefaultSearchSystem.java

public void clear() {
    try {/*from  w w  w  . j  av a  2s  .c  o m*/
        _lock.writeLock().lock();
        for (Collection<ITypeValueMap<?, IChunk>> collection : _slotMap.values()) {
            if (collection != null) {
                for (ITypeValueMap<?, IChunk> tvm : collection)
                    tvm.clear();
                collection.clear();
            }
        }
        _slotMap.clear();
    } finally {
        _lock.writeLock().unlock();
    }
}

From source file:de.ingrid.usermanagement.jetspeed.IngridPermissionManager.java

/**
 * @see org.apache.jetspeed.security.PermissionManager#removePermissions(java.security.Principal)
 *///from ww  w . ja  va  2  s. com
public void removePermissions(Principal principal) throws SecurityException {
    String fullPath = SecurityHelper.getPreferencesFullPath(principal);
    ArgUtil.notNull(new Object[] { fullPath }, new String[] { "fullPath" },
            "removePermission(java.security.Principal)");

    // Remove permissions on principal.
    InternalPrincipal internalPrincipal = getInternalPrincipal(fullPath);
    if (null != internalPrincipal) {
        Collection internalPermissions = internalPrincipal.getPermissions();
        if (null != internalPermissions) {
            internalPermissions.clear();
        }
        try {
            internalPrincipal.setModifiedDate(new Timestamp(System.currentTimeMillis()));
            internalPrincipal.setPermissions(internalPermissions);

            broker.beginTransaction();
            broker.store(internalPrincipal);
            broker.commitTransaction();
        } catch (Exception e) {
            KeyedMessage msg = SecurityException.UNEXPECTED.create("PermissionManager.removePermissions",
                    "store", e.getMessage());
            log.error(msg, e);
            broker.abortTransaction();
            throw new SecurityException(msg, e);
        }
    }
}

From source file:org.wso2.carbon.bpel.analytics.publisher.Axis2ConfigurationContextObserverImpl.java

public void terminatingConfigurationContext(ConfigurationContext configurationContext) {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    log.info("Removing data publishers for this tenant " + tenantId + ".");

    TenantProcessStore tenantsProcessStore = bpelServer.getMultiTenantProcessStore()
            .getTenantsProcessStore(tenantId);
    if (tenantsProcessStore != null) {
        Map dataPublisherMap = tenantsProcessStore.getDataPublisherMap();
        if (dataPublisherMap != null) {
            Collection<DataPublisher> dataPublisherCollection = dataPublisherMap.values();
            Iterator<DataPublisher> iterator = dataPublisherCollection.iterator();
            while (iterator.hasNext()) {
                DataPublisher dataPublisher = iterator.next();
                try {
                    dataPublisher.shutdown();
                } catch (DataEndpointException e) {
                    String errMsg = "Error while shutting down tenant Data Publisher";
                    log.error(errMsg, e);
                }/*from   w w  w . j  a  va  2s .  co  m*/
            }
            dataPublisherCollection.clear();
        }
    }
}

From source file:org.openanzo.datasource.nodecentric.internal.NodeCentricDatasourceFactory.java

@Override
public void stop(boolean bundleStopping) {
    aclTracker.close();//from   www.j av  a 2 s. c o  m
    for (NodeCentricDatasource ds : datasources.values()) {
        try {
            ds.close(bundleStopping);
            Collection<ServiceRegistration> regs = serviceRegistrations.remove(ds);
            if (regs != null) {
                for (ServiceRegistration reg : regs) {
                    if (!bundleStopping) {
                        reg.unregister();
                    }
                }
                regs.clear();
            }
        } catch (AnzoException ae) {
            log.error(LogUtils.LIFECYCLE_MARKER, "Error closing nodecentric datasource", ae);
        }
    }
    datasources.clear();
    if (bundleStopping && jmxRegistration != null) {
        jmxRegistration.unregister();
        jmxRegistration = null;
    }
}

From source file:mitm.djigzo.web.pages.ca.CARequestsPreview.java

private void sendRequestsInBatches() throws WebServiceCheckedException, IOException {
    Collection<RequestParameters> batch = new ArrayList<RequestParameters>(maxBatchSize);

    for (RequestParameters request : certificateRequests) {
        batch.add(request);//from www.  ja va  2  s .  co  m

        if (batch.size() >= maxBatchSize) {
            sendRequests(batch);

            batch.clear();
        }
    }

    /*
     * Check if there are still some requests left to send (happens when the number
     * of requests is not a multiple of maxBatchSize)
     */
    if (batch.size() > 0) {
        sendRequests(batch);
    }
}

From source file:org.jactr.core.concurrent.ExecutorServices.java

/**
 * shutdown and wait for the shutdown of all the executors that are currently
 * installed. if millisecondsToWait is 0, it will wait indefinitely
 *//*w  ww .j  a  v a  2  s. c o m*/
static public void shutdown(long millisecondsToWait) {
    synchronized (_executors) {
        _isShuttingDown = true;
    }

    Collection<String> executorNames = new ArrayList<String>();
    getExecutorNames(executorNames);

    /*
     * issue shutdown
     */
    for (String name : executorNames) {
        ExecutorService executor = getExecutor(name);
        if (executor != null && !executor.isShutdown())
            executor.shutdown();
    }

    /*
     * and wait
     */
    long interval = 500;
    long abortAt = System.currentTimeMillis() + millisecondsToWait;
    if (millisecondsToWait == 0)
        abortAt = Long.MAX_VALUE;
    while (abortAt > System.currentTimeMillis() && executorNames.size() != 0) {
        for (String name : executorNames) {
            ExecutorService executor = getExecutor(name);
            if (executor != null)
                try {
                    if (executor.awaitTermination(interval, TimeUnit.MILLISECONDS))
                        removeExecutor(name);
                    else if (LOGGER.isDebugEnabled())
                        LOGGER.debug(name + " did not terminate after " + interval + "ms");
                } catch (Exception e) {
                    if (LOGGER.isWarnEnabled())
                        LOGGER.warn("Failed to terminate " + name, e);
                    removeExecutor(name);
                }
        }

        /*
         * get the current names again..
         */
        executorNames.clear();
        getExecutorNames(executorNames);
    }

    if (executorNames.size() != 0) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn("Forcing unresponsive executors to terminate " + executorNames + " after "
                    + millisecondsToWait + "ms");
        for (String name : executorNames) {
            ExecutorService executor = getExecutor(name);
            if (executor != null)
                executor.shutdownNow();
        }
    }

    synchronized (_executors) {
        _executors.clear();
        _isShuttingDown = false;
    }

}

From source file:org.openengsb.connector.userprojects.ldap.internal.UserProjectsLdapServiceImplTest.java

private void assertCorrectlyStored(Assignment assignment)
        throws NoSuchNodeException, MissingParentException, LdapInvalidAttributeValueException {
    Entry entry = ldapDao.lookup(DnFactory.assignmentProject(assignment));
    assertThat(entry.get(SchemaConstants.STRING_ATTRIBUTE).getString(), is(assignment.getProject()));

    entry = ldapDao.lookup(DnFactory.assignmentUser(assignment));
    assertThat(entry.get(SchemaConstants.STRING_ATTRIBUTE).getString(), is(assignment.getUser()));

    List<Entry> entryList = ldapDao.getDirectChildren(DnFactory.assignmentPermissions(assignment));
    Collection<String> actualCollection = Lists.newArrayList();
    for (Entry entry2 : entryList) {
        actualCollection.add(entry2.getDn().getRdn().getValue().getString());
    }/*  w w  w.  j av a  2 s.  c om*/
    assertTrue(CollectionUtils.isEqualCollection(actualCollection, assignment.getPermissions()));

    entryList = ldapDao.getDirectChildren(DnFactory.assignmentRoles(assignment));
    actualCollection.clear();
    for (Entry entry2 : entryList) {
        actualCollection.add(entry2.getDn().getRdn().getValue().getString());
    }
    assertTrue(CollectionUtils.isEqualCollection(actualCollection, assignment.getRoles()));
}