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:ubic.gemma.persistence.service.analysis.expression.diff.DifferentialExpressionAnalysisDaoImpl.java

@Override
public Collection<BioAssaySet> findExperimentsWithAnalyses(Gene gene) {

    StopWatch timer = new StopWatch();
    timer.start();/*w w w  . j a  v  a 2 s . c  om*/

    Collection<CompositeSequence> probes = CommonQueries.getCompositeSequences(gene,
            this.getSessionFactory().getCurrentSession());
    Collection<BioAssaySet> result = new HashSet<>();
    if (probes.size() == 0) {
        return result;
    }

    if (timer.getTime() > 1000) {
        AbstractDao.log.info("Find probes: " + timer.getTime() + " ms");
    }
    timer.reset();
    timer.start();

    /*
     * Note: this query misses ExpressionExperimentSubSets. The native query was implemented because HQL was always
     * constructing a constraint on SubSets. See bug 2173.
     */
    final String queryToUse = "select e.ID from ANALYSIS a inner join INVESTIGATION e ON a.EXPERIMENT_ANALYZED_FK = e.ID "
            + "inner join BIO_ASSAY ba ON ba.EXPRESSION_EXPERIMENT_FK=e.ID "
            + " inner join BIO_MATERIAL bm ON bm.ID=ba.SAMPLE_USED_FK inner join TAXON t ON bm.SOURCE_TAXON_FK=t.ID "
            + " inner join COMPOSITE_SEQUENCE cs ON ba.ARRAY_DESIGN_USED_FK =cs.ARRAY_DESIGN_FK where cs.ID in "
            + " (:probes) and t.ID = :taxon";

    Taxon taxon = gene.getTaxon();

    int batchSize = 1000;
    Collection<CompositeSequence> batch = new HashSet<>();
    for (CompositeSequence probe : probes) {
        batch.add(probe);

        if (batch.size() == batchSize) {
            this.fetchExperimentsTestingGeneNativeQuery(batch, result, queryToUse, taxon);
            batch.clear();
        }
    }

    if (!batch.isEmpty()) {
        this.fetchExperimentsTestingGeneNativeQuery(batch, result, queryToUse, taxon);
    }

    if (timer.getTime() > 1000) {
        AbstractDao.log.info("Find experiments: " + timer.getTime() + " ms");
    }

    return result;
}

From source file:org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.java

/**
 * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#setProperty(java.lang.Object,
 *      java.lang.String, java.lang.Object)
 *//*from   w  w w  . j  a v  a  2 s  .  c  om*/
@Override
public void setProperty(Object instance, String propertyName, Object value) throws ConversionException {
    if (propertiesIgnoredWhenUpdating.contains(propertyName)) {
        return;
    }
    try {
        DelegatingResourceHandler<? extends T> handler;

        try {
            handler = getResourceHandler((T) instance);
        } catch (Exception e) {
            // this try/catch isn't really needed because of java erasure behaviour at run time.
            // but I'm putting in here just in case
            handler = this;
        }

        // try to find a @PropertySetter-annotated method
        Method annotatedSetter = findSetterMethod(handler, propertyName);
        if (annotatedSetter != null) {
            Type expectedType = annotatedSetter.getGenericParameterTypes()[1];
            value = ConversionUtil.convert(value, expectedType);
            annotatedSetter.invoke(handler, instance, value);
            return;
        }

        // we need the generic type of this property, not just the class
        Method setter = PropertyUtils.getPropertyDescriptor(instance, propertyName).getWriteMethod();
        value = ConversionUtil.convert(value, setter.getGenericParameterTypes()[0]);

        if (value instanceof Collection) {
            //We need to handle collections in a way that Hibernate can track.
            Collection<?> newCollection = (Collection<?>) value;
            Object oldValue = PropertyUtils.getProperty(instance, propertyName);
            if (oldValue instanceof Collection) {
                Collection collection = (Collection) oldValue;
                collection.clear();
                collection.addAll(newCollection);
            } else {
                PropertyUtils.setProperty(instance, propertyName, value);
            }
        } else {
            PropertyUtils.setProperty(instance, propertyName, value);
        }
    } catch (Exception ex) {
        throw new ConversionException(propertyName + " on " + instance.getClass(), ex);
    }
}

From source file:org.malaguna.cmdit.service.reflection.HibernateProxyUtils.java

@SuppressWarnings("unchecked")
private Collection<?> deepLoadCollection(Collection collection, Collection guideObj) {
    Collection result = null;/*w  w w.  j a  v  a2s.co  m*/

    if (guideObj != null && !guideObj.isEmpty() && collection != null && !collection.isEmpty()) {

        try {
            if (collection instanceof PersistentSet) {
                result = new HashSet();
            } else if (collection instanceof PersistentList) {
                result = new ArrayList();
            } else {
                result = collection.getClass().newInstance();
            }

            //Recuperar primera instancia del guideObj y usarlo como siguiente guideObj
            Object collGuideObj = guideObj.iterator().next();
            for (Object aux : collection) {
                result.add(deepLoad(aux, collGuideObj));
            }

            collection.clear();
            collection.addAll(result);

        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    return collection;
}

From source file:org.grails.datastore.mapping.core.AbstractSession.java

private void executePendings(Collection<Runnable> pendings) {
    try {/*  w w  w  .j av a 2 s . co m*/
        for (Runnable pending : pendings) {
            pending.run();
        }
    } catch (RuntimeException e) {
        exceptionOccurred = true;
        throw e;
    }
    pendings.clear();
}

From source file:cn.vlabs.duckling.vwb.service.login.UMT2LoginAction.java

private void addUserToSiteByCheckFlag(Collection<Principal> currentPrincipals, String userName,
        String displayName) {//from  w ww  . ja  va 2s. c o m
    if (currentPrincipals != null) {
        boolean existInSite = false;
        for (Principal p : currentPrincipals) {
            if (p instanceof GroupPrincipal) {
                existInSite = true;
                break;
            }
        }
        if (!existInSite) {
            String checkValue = getVwbcontext().getProperty(Attributes.CHECK_SITE_FOR_USER);
            IUserService userS = VWBContainerImpl.findContainer().getUserService();
            if (checkValue != null && Attributes.CHECK_SITE_FOR_USER_ADD.equals(checkValue)) {
                userS.addUserToGroup(getVwbcontext().getVO(), "root", userName);
                currentPrincipals.clear();
                currentPrincipals.addAll(userS.getUserPrincipal(userName, getVwbcontext().getVO()));

            } else if (Attributes.CHECK_SITE_FOR_USER_APPLY.equals(checkValue)) {
                userS.applyUserToVo(getVwbcontext().getVO(), userName, displayName, null);
                currentPrincipals.clear();
                currentPrincipals.addAll(userS.getUserPrincipal(userName, getVwbcontext().getVO()));
            }
        }

    }

}

From source file:de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionServiceIntegrationTest.java

/**
 * Test method for/*w w w  .j av a 2 s .  com*/
 * {@link de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionService#setDeniedPrincipals(MediaModel, Collection)}
 * .
 */
@Test
public void testSetDeniedPrincipals() {
    Collection<PrincipalModel> deniedPrincipals = mediaPermissionService.getDeniedPrincipals(testMediaItem);
    Assert.assertTrue(CollectionUtils.isEmpty(deniedPrincipals));

    //create new user and assign proper permission
    final UserModel testUser = modelService.create(UserModel.class);
    testUser.setUid("testGroup");
    testUser.setName("Testgroup");
    modelService.save(testUser);

    final Collection<PrincipalModel> principalsToBeSet = new HashSet<PrincipalModel>();
    principalsToBeSet.add(userService.getCurrentUser());
    principalsToBeSet.add(testUser);

    //update the denied principals list. Expected result - 2 denied principals
    mediaPermissionService.setDeniedPrincipals(testMediaItem, principalsToBeSet);

    deniedPrincipals = mediaPermissionService.getDeniedPrincipals(testMediaItem);
    Assert.assertTrue(deniedPrincipals.size() == 2);
    Assert.assertTrue(deniedPrincipals.contains(userService.getCurrentUser()));
    Assert.assertTrue(deniedPrincipals.contains(testUser));

    principalsToBeSet.clear();
    //update the denied principals list. Expected result - empty list (no denied principals)
    mediaPermissionService.setDeniedPrincipals(testMediaItem, principalsToBeSet);

    deniedPrincipals = mediaPermissionService.getDeniedPrincipals(testMediaItem);
    Assert.assertTrue(CollectionUtils.isEmpty(deniedPrincipals));

}

From source file:de.uniba.wiai.kinf.pw.projects.lillytab.reasoner.tbox.RBox.java

private void addSubSuper() {
    final Collection<Map.Entry<R, R>> addList = new HashSet<>();

    for (Map.Entry<R, R> invEntry : MultiMapEntryIterable.decorate(_subRoles.entrySet())) {
        if (!_superRoles.containsValue(invEntry.getValue(), invEntry.getKey())) {
            addList.add(invEntry);/* www  .j a v a 2s. com*/
        }
    }
    for (Map.Entry<R, R> addItem : addList) {
        _superRoles.put(addItem.getKey(), addItem.getValue());
    }

    addList.clear();
    for (Map.Entry<R, R> invEntry : MultiMapEntryIterable.decorate(_superRoles.entrySet())) {
        if (!_subRoles.containsValue(invEntry.getValue(), invEntry.getKey())) {
            addList.add(invEntry);
        }
    }
    for (Map.Entry<R, R> addItem : addList) {
        _subRoles.put(addItem.getKey(), addItem.getValue());
    }
}

From source file:org.kuali.coeus.common.budget.impl.rate.BudgetRatesServiceImpl.java

protected void filterRates(Budget budget, Collection allAbstractInstituteRates,
        Collection filteredAbstractInstituteRates) {
    filteredAbstractInstituteRates.clear();
    Date personSalaryEffectiveDate = getBudgetPersonSalaryEffectiveDate(budget);
    filterInstituteRates(budget, allAbstractInstituteRates, filteredAbstractInstituteRates,
            personSalaryEffectiveDate);/*from w ww.j  a v  a 2 s.com*/
}

From source file:com.btoddb.fastpersitentqueue.InMemorySegmentMgr.java

private void loadPagedSegments() throws IOException {
    // read files and sort by their UUID name so they are in proper chronological order
    Collection<File> files = FileUtils.listFiles(pagingDirectory, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);//w ww .j a va  2  s  .  c om
    TreeSet<File> sortedFiles = new TreeSet<File>(new Comparator<File>() {
        @Override
        public int compare(File o1, File o2) {
            return new UUID(o1.getName()).compareTo(new UUID(o2.getName()));
        }
    });
    sortedFiles.addAll(files);

    // cleanup memory
    files.clear();

    assert 0 == numberOfActiveSegments.get();
    assert segments.isEmpty();

    segments.clear();

    for (File f : sortedFiles) {
        MemorySegment segment;
        // only load the segment's data if room in memory, otherwise just load its header
        if (numberOfActiveSegments.get() < maxNumberOfActiveSegments - 1) {
            segment = segmentSerializer.loadFromDisk(f.getName());
            segment.setStatus(MemorySegment.Status.READY);
            segment.setPushingFinished(true);

            assert segment.getNumberOfOnlineEntries() > 0;
            assert !segment.getQueue().isEmpty();

            numberOfActiveSegments.incrementAndGet();
        } else {
            segment = segmentSerializer.loadHeaderOnly(f.getName());
            segment.setStatus(MemorySegment.Status.OFFLINE);
            segment.setPushingFinished(true);

        }

        assert segment.isPushingFinished();
        assert segment.getNumberOfEntries() > 0;
        assert segment.getEntryListOffsetOnDisk() > 0;

        segments.add(segment);
        numberOfEntries.addAndGet(segment.getNumberOfEntries());
    }

    //        for (MemorySegment seg : segments) {
    //            if (seg.getStatus() == MemorySegment.Status.READY) {
    //                segmentSerializer.removePagingFile(seg);
    //            }
    //        }
}

From source file:de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionServiceIntegrationTest.java

/**
 * Test method for//from   w ww  . j  av  a2s .  c om
 * {@link de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionService#setPermittedPrincipals(MediaModel, Collection)}
 * .
 */
@Test
public void testSetPermittedPrincipals() {
    Collection<PrincipalModel> permittedPrincipals = mediaPermissionService
            .getPermittedPrincipals(testMediaItem);
    Assert.assertTrue(permittedPrincipals.size() == 1);
    Assert.assertTrue(permittedPrincipals.contains(userService.getCurrentUser()));

    //create new user and assign proper permission
    final UserModel testUser = modelService.create(UserModel.class);
    testUser.setUid("testGroup");
    testUser.setName("Testgroup");
    modelService.save(testUser);

    final Collection<PrincipalModel> principalsToBeSet = new HashSet<PrincipalModel>();
    principalsToBeSet.add(userService.getCurrentUser());
    principalsToBeSet.add(testUser);

    //update the permitted principals list. Expected result - 2 assigned principals
    mediaPermissionService.setPermittedPrincipals(testMediaItem, principalsToBeSet);

    permittedPrincipals = mediaPermissionService.getPermittedPrincipals(testMediaItem);
    Assert.assertTrue(permittedPrincipals.size() == 2);
    Assert.assertTrue(permittedPrincipals.contains(userService.getCurrentUser()));
    Assert.assertTrue(permittedPrincipals.contains(testUser));

    principalsToBeSet.clear();
    //update the permitted principals list. Expected result - empty list (no assigned principals)
    mediaPermissionService.setPermittedPrincipals(testMediaItem, principalsToBeSet);

    permittedPrincipals = mediaPermissionService.getPermittedPrincipals(testMediaItem);
    Assert.assertTrue(CollectionUtils.isEmpty(permittedPrincipals));
}