List of usage examples for java.util Collection clear
void clear();
From source file:com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl.java
@Override public void clear() { backgroundWorker.checkUIAccess();//w w w . ja v a 2 s. c o m checkState(); Collection<T> collection = getCollection(); if (collection != null) { Collection<T> collectionItems = new ArrayList<>(collection); doNotModify = true; try { // Clear collection collection.clear(); // Notify listeners for (T item : collectionItems) { if (metaProperty.getRange().getCardinality() == Range.Cardinality.ONE_TO_MANY) { MetaProperty inverseProperty = metaProperty.getInverse(); if (inverseProperty == null) { throw new UnsupportedOperationException("No inverse property for " + metaProperty); } item.setValue(inverseProperty.getName(), null); } // detach listener only after setting value to the link property detachListener(item); } setItem(null); fireCollectionChanged(Operation.CLEAR, Collections.emptyList()); } finally { doNotModify = false; } } }
From source file:com.haulmont.cuba.gui.data.impl.CollectionPropertyDatasourceImpl.java
@SuppressWarnings("unchecked") protected void addToCollectionFirst(T item) { Collection<T> collection = getCollection(); if (collection instanceof List) { ((List) collection).add(0, item); } else if (collection instanceof LinkedHashSet) { LinkedHashSet tmpSet = (LinkedHashSet) ((LinkedHashSet) collection).clone(); collection.clear(); ((LinkedHashSet) collection).add(item); ((LinkedHashSet) collection).addAll(tmpSet); } else {//from w w w.j a va2 s .c om collection.add(item); } }
From source file:com.graphhopper.jsprit.core.algorithm.ruin.RuinClusters.java
private void ruin(Collection<VehicleRoute> vehicleRoutes, int nOfJobs2BeRemoved, List<Job> unassignedJobs) { if (vrp.getJobs().values().size() == 0) return;// w ww .j av a2 s. c o m Map<Job, VehicleRoute> mappedRoutes = map(vehicleRoutes); int toRemove = nOfJobs2BeRemoved; Collection<Job> lastRemoved = new ArrayList<Job>(); Set<VehicleRoute> ruined = new HashSet<VehicleRoute>(); Set<Job> removed = new HashSet<Job>(); Set<VehicleRoute> cycleCandidates = new HashSet<VehicleRoute>(); while (toRemove > 0) { Job target; VehicleRoute targetRoute = null; if (lastRemoved.isEmpty()) { target = RandomUtils.nextJob(vrp.getJobs().values(), random); targetRoute = mappedRoutes.get(target); } else { target = RandomUtils.nextJob(lastRemoved, random); Iterator<Job> neighborIterator = jobNeighborhoods.getNearestNeighborsIterator(nOfJobs2BeRemoved, target); while (neighborIterator.hasNext()) { Job j = neighborIterator.next(); if (!removed.contains(j) && !ruined.contains(mappedRoutes.get(j))) { targetRoute = mappedRoutes.get(j); break; } } lastRemoved.clear(); } if (targetRoute == null) break; if (cycleCandidates.contains(targetRoute)) break; if (ruined.contains(targetRoute)) { cycleCandidates.add(targetRoute); break; } DBSCANClusterer dbscan = new DBSCANClusterer(vrp.getTransportCosts()); dbscan.setRandom(random); dbscan.setMinPts(minPts); dbscan.setEpsFactor(epsFactor); List<Job> cluster = dbscan.getRandomCluster(targetRoute); for (Job j : cluster) { if (toRemove == 0) break; if (removeJob(j, vehicleRoutes)) { lastRemoved.add(j); unassignedJobs.add(j); } toRemove--; } ruined.add(targetRoute); } }
From source file:de.hybris.platform.test.MediaTest.java
@Test public void testDeniedPrincipals() throws JaloBusinessException { final UserRight userRight = AccessManager.getInstance().getOrCreateUserRightByCode("read"); final Media m = MediaManager.getInstance().createMedia("media123"); final Collection<Principal> existingDeniedPrincipals = m.getDeniedPrincipals(); assertThat(existingDeniedPrincipals).isEmpty(); final Collection<Principal> principalsToBeDenied = new HashSet<Principal>(); final User testUser1 = UserManager.getInstance().createUser("testUser1"); final User testUser2 = UserManager.getInstance().createUser("testUser2"); principalsToBeDenied.add(testUser1); principalsToBeDenied.add(testUser2); m.setDeniedPrincipals(principalsToBeDenied); assertCollection(principalsToBeDenied, m.getDeniedPrincipals()); //check the negative permissions assertTrue(m.getPermissions(testUser1, true).contains(userRight.getPK())); assertTrue(m.getPermissions(testUser2, true).contains(userRight.getPK())); principalsToBeDenied.clear(); final User testUser3 = UserManager.getInstance().createUser("testUser3"); principalsToBeDenied.add(testUser3); m.setDeniedPrincipals(principalsToBeDenied); assertCollection(principalsToBeDenied, m.getDeniedPrincipals()); assertTrue(m.getPermissions(testUser3, true).contains(userRight.getPK())); }
From source file:org.commonreality.sensors.base.BaseSensor.java
/** * commit all the changes..// w w w. j a v a2s. c o m */ private void process(IIdentifier agentId) { IIdentifier sId = getIdentifier(); Collection<IObjectDelta> deltas = new ArrayList<IObjectDelta>(); Collection<IIdentifier> identifiers = new ArrayList<IIdentifier>(); synchronized (_toBeAdded) { Collection<ISimulationObject> add = _toBeAdded.get(agentId); if (add.size() > 0) { for (ISimulationObject object : add) { identifiers.add(object.getIdentifier()); deltas.add(new FullObjectDelta(object)); } /* * we send the data immediately.. but queue up the notification */ _delayedCommands.add(new ObjectDataRequest(sId, agentId, deltas)); _delayedCommands .add(new ObjectCommandRequest(sId, agentId, IObjectCommand.Type.ADDED, identifiers)); } add.clear(); } identifiers.clear(); deltas.clear(); synchronized (_toBeChanged) { Collection<IObjectDelta> change = _toBeChanged.get(agentId); if (change.size() != 0) { /* * and the modify */ for (IObjectDelta delta : change) { deltas.add(delta); identifiers.add(delta.getIdentifier()); } _delayedCommands.add(new ObjectDataRequest(sId, agentId, deltas)); _delayedCommands .add(new ObjectCommandRequest(sId, agentId, IObjectCommand.Type.UPDATED, identifiers)); } change.clear(); } deltas.clear(); identifiers.clear(); synchronized (_toBeRemoved) { Collection<IIdentifier> remove = _toBeRemoved.get(agentId); if (remove.size() != 0) _delayedCommands.add(new ObjectCommandRequest(sId, agentId, IObjectCommand.Type.REMOVED, remove)); remove.clear(); } }
From source file:edu.ksu.cis.indus.staticanalyses.callgraphs.CallGraphXMLizerCLI.java
/** * Executed OFA-based call graph analysis. * //from w w w . ja v a 2 s. co m * @param dumpJimple <code>true</code> indicate that jimple should be dumped; <code>false</code>, otherwise. * @param <T> dummy type parameter. */ private <T extends ITokens<T, Value>> void executeOFA(final boolean dumpJimple, final String OFAType) { final String _tagName = "CallGraphXMLizer:FA"; final IValueAnalyzer<Value> _aa; if (OFAType.equals("ofa-oi")) _aa = OFAnalyzer.getFSOIAnalyzer(_tagName, TokenUtil.<T, Value, Type>getTokenManager(new SootValueTypeManager()), getStmtGraphFactory()); else if (OFAType.equals("ofa-oirt")) _aa = OFAnalyzer.getFSOIRTAnalyzer(_tagName, TokenUtil.<T, Value, Type>getTokenManager(new SootValueTypeManager()), getStmtGraphFactory()); else if (OFAType.equals("ofa-os")) _aa = OFAnalyzer.getFSOSAnalyzer(_tagName, TokenUtil.<T, Value, Type>getTokenManager(new SootValueTypeManager()), getStmtGraphFactory()); else { throw new IllegalArgumentException( "callgraph-type has to be one of the following: ofa-oi, ofa-oirt, ofa-os," + " fsoirt."); } final ValueAnalyzerBasedProcessingController _pc = new ValueAnalyzerBasedProcessingController(); final Collection<IProcessor> _processors = new ArrayList<IProcessor>(); final CallGraphInfo _cgi = new CallGraphInfo(new PairManager(false, true)); final OFABasedCallInfoCollector _ofaci = new OFABasedCallInfoCollector(); final Collection<SootMethod> _rm = new ArrayList<SootMethod>(); final MetricsProcessor _countingProcessor = new MetricsProcessor(); final OneAllStmtSequenceRetriever _ssr = new OneAllStmtSequenceRetriever(); _ssr.setStmtGraphFactory(getStmtGraphFactory()); _pc.setStmtSequencesRetriever(_ssr); _pc.setAnalyzer(_aa); _pc.setEnvironment(getEnvironment()); _pc.setProcessingFilter(new TagBasedProcessingFilter(_tagName)); final List<Object> _roots = new ArrayList<Object>(); if (cumulative) { _roots.add(getRootMethods()); } else { _roots.addAll(getRootMethods()); } Collections.sort(_roots, ToStringBasedComparator.getComparator()); writeInfo("Root methods are: " + _roots.size() + "\n" + _roots); for (final Iterator<Object> _k = _roots.iterator(); _k.hasNext();) { _rm.clear(); final Object _root = _k.next(); final String _fileBaseName = "OFA-Based_" + OFAXMLizerCLI.getBaseNameOfFileAndRootMethods(_root, _rm); writeInfo("RootMethod: " + _root); writeInfo("BEGIN: FA"); final long _start = System.currentTimeMillis(); _aa.reset(); getBbm().reset(); _aa.analyze(getEnvironment(), _rm); final long _stop = System.currentTimeMillis(); addTimeLog("FA", _stop - _start); writeInfo("END: FA"); _ofaci.reset(); _processors.clear(); _processors.add(_ofaci); _processors.add(_countingProcessor); _pc.reset(); _pc.driveProcessors(_processors); _processors.clear(); _cgi.reset(); _cgi.createCallGraphInfo(_ofaci.getCallInfo()); final ByteArrayOutputStream _stream = new ByteArrayOutputStream(); new PrintWriter(_stream) .write("STATISTICS: " + MapUtils.verbosePrint(new TreeMap(_countingProcessor.getStatistics()))); writeInfo(_stream.toString()); dumpInfo(dumpJimple, _cgi, _fileBaseName, _aa.getEnvironment()); } }
From source file:org.codehaus.groovy.grails.web.binding.GrailsDataBinder.java
@SuppressWarnings("unchecked") private void bindCollectionAssociation(MutablePropertyValues mpvs, PropertyValue pv) { Object v = pv.getValue();/*from ww w . j av a 2s .com*/ final boolean isArray = v != null && v.getClass().isArray(); if (!isArray && !(v instanceof String)) return; Collection collection = (Collection) bean.getPropertyValue(pv.getName()); collection.clear(); final Class associatedType = getReferencedTypeForCollection(pv.getName(), getTarget()); final PropertyEditor propertyEditor = findCustomEditor(collection.getClass(), pv.getName()); if (propertyEditor == null) { if (isDomainAssociation(associatedType)) { if (isArray) { Object[] identifiers = (Object[]) v; for (Object id : identifiers) { if (id != null) { associateObjectForId(pv, id, associatedType); } } mpvs.removePropertyValue(pv); } else if (v instanceof String) { associateObjectForId(pv, v, associatedType); mpvs.removePropertyValue(pv); } } else if (GrailsDomainConfigurationUtil.isBasicType(associatedType)) { Object[] values = null; if (isArray) { values = (Object[]) v; } else if (v instanceof String) { values = new String[] { (String) v }; } if (values != null) { List list = collection instanceof List ? (List) collection : null; for (int i = 0; i < values.length; i++) { Object value = values[i]; try { Object newValue = getTypeConverter().convertIfNecessary(value, associatedType); if (list != null) { if (i > list.size() - 1) { list.add(i, newValue); } else { list.set(i, newValue); } } else { collection.add(newValue); } } catch (TypeMismatchException e) { // ignore } } mpvs.removePropertyValue(pv); } } } }
From source file:org.metaborg.spoofax.eclipse.editor.SpoofaxInformationControl.java
private void setColorPrefixSuffix(Display display, ICompletion input) { SourceRegion prefixRegion = calculateRegionPrefix(input); SourceRegion suffixRegion = calculateRegionSuffix(input); if (prefixRegion == null && suffixRegion == null) return;/*from w w w . j a v a 2 s. co m*/ Collection<IRegionStyle<IStrategoTerm>> stylesPrefixSuffix = Lists.newLinkedList(); Style style = new Style(new java.awt.Color(196, 196, 196), null, false, false, false, false); if (prefixRegion != null) { RegionStyle<IStrategoTerm> prefixRegionStyle = new RegionStyle<IStrategoTerm>(prefixRegion, style, null); stylesPrefixSuffix.add(prefixRegionStyle); final TextPresentation textPresentation = StyleUtils.createTextPresentation(stylesPrefixSuffix, display); fViewer.changeTextPresentation(textPresentation, true); stylesPrefixSuffix.clear(); } if (suffixRegion != null) { RegionStyle<IStrategoTerm> suffixRegionStyle = new RegionStyle<IStrategoTerm>(suffixRegion, style, null); stylesPrefixSuffix.add(suffixRegionStyle); final TextPresentation textPresentation = StyleUtils.createTextPresentation(stylesPrefixSuffix, display); fViewer.changeTextPresentation(textPresentation, true); } }
From source file:com.wasteofplastic.beaconz.BeaconListeners.java
/** * Applies triangle effects to a player/* www. j a v a 2 s . co m*/ * @param player * @param to * @param team */ private void applyEffects(Player player, List<TriangleField> to, Team team) { if (to.isEmpty() || team == null) { return; } // Apply bad stuff // Enemy team Team triangleOwner = to.get(0).getOwner(); Collection<PotionEffect> effects = new ArrayList<PotionEffect>(); if (triangleOwner != null && !triangleOwner.equals(team)) { for (int i = 0; i <= to.size(); i++) { if (Settings.enemyFieldEffects.containsKey(i)) { effects.addAll(Settings.enemyFieldEffects.get(i)); } } player.addPotionEffects(effects); } effects.clear(); // Friendly triangle if (triangleOwner != null && triangleOwner.equals(team)) { for (int i = 0; i <= to.size(); i++) { if (Settings.friendlyFieldEffects.containsKey(i)) { effects.addAll(Settings.friendlyFieldEffects.get(i)); } } player.addPotionEffects(effects); } }
From source file:com.espertech.esper.filter.FilterServiceBase.java
private void retryableMatchEvent(EventBean theEvent, Collection<FilterHandle> matches) { // Install lock backoff exception handler that retries the evaluation. try {//from ww w . j a va 2 s. c o m eventTypeIndex.matchEvent(theEvent, matches); } catch (FilterLockBackoffException ex) { // retry on lock back-off // lock-backoff may occur when stateful evaluations take place such as boolean expressions that are subqueries // statements that contain subqueries in pattern filter expression can themselves modify filters, leading to a theoretically possible deadlock long delayNs = 10; while (true) { try { // yield try { Thread.sleep(0); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } // delay LockSupport.parkNanos(delayNs); if (delayNs < 1000000000) { delayNs = delayNs * 2; } // evaluate matches.clear(); eventTypeIndex.matchEvent(theEvent, matches); break; } catch (FilterLockBackoffException ex2) { // retried } } } }