List of usage examples for java.util Collection clear
void clear();
From source file:org.jactr.core.module.declarative.search.map.DefaultValueMap.java
public void clear(V value) { if (value == null) throw new NullPointerException("null values are not permitted as keys"); ReentrantReadWriteLock lock = getLock(); try {/*from w ww . ja va 2 s .c o m*/ lock.writeLock().lock(); Collection<I> indexables = getCoreMap().remove(value); if (indexables != null) { indexables.clear(); } } finally { lock.writeLock().unlock(); } }
From source file:MultiMap.java
/** * Clear the map./*from w w w . j ava2 s. c o m*/ */ public void clear() { // Clear the mappings Set pairs = super.entrySet(); Iterator pairsIterator = pairs.iterator(); while (pairsIterator.hasNext()) { Map.Entry keyValuePair = (Map.Entry) pairsIterator.next(); Collection coll = (Collection) keyValuePair.getValue(); coll.clear(); } super.clear(); }
From source file:org.carewebframework.vista.ui.notification.NotificationService.java
/** * Returns notifications for the current user. * // ww w.j a v a2 s. c om * @param patient If not null, only notifications associated with the current user are returned. * Otherwise, all notifications for the current user are returned. * @param result The list to receive the results. */ public void getNotifications(Patient patient, Collection<Notification> result) { List<String> lst = null; result.clear(); if (patient == null) { lst = broker.callRPCList("RGCWXQ ALRLIST", null); } else if (patient != null) { lst = broker.callRPCList("RGCWXQ ALRLIST", null, patient.getId().getIdPart()); } if (lst != null) { for (String item : lst) { result.add(new Notification(item)); } } }
From source file:com.cloudera.oryx.app.als.FeatureVectorsTest.java
@Test public void testRecent() { FeatureVectors fv = new FeatureVectors(); fv.setVector("foo", new float[] { 1.0f }); Collection<String> recentIDs = new HashSet<>(); fv.addAllRecentTo(recentIDs);// w ww . j a va 2 s .c o m assertEquals(Collections.singleton("foo"), recentIDs); fv.retainRecentAndIDs(Collections.singleton("foo")); recentIDs.clear(); fv.addAllRecentTo(recentIDs); assertEquals(0, recentIDs.size()); }
From source file:org.openhab.model.script.scoping.ScriptExtensionClassNameProvider.java
@Override protected Collection<String> computeLiteralClassNames() { // we completely define the content ourselves, but need the collection // instance from the super class as it is a private field Collection<String> literalClassNames = super.getLiteralClassNames(); if (literalClassNames == null) { literalClassNames = super.computeLiteralClassNames(); }/* w ww. j a v a 2s. c om*/ literalClassNames.clear(); // add all actions that are contributed as OSGi services Object[] services = ScriptActivator.actionServiceTracker.getServices(); if (services != null) { for (Object service : services) { ActionService actionService = (ActionService) service; literalClassNames.add(actionService.getActionClassName()); } } literalClassNames.add(CollectionLiterals.class.getName()); literalClassNames.add(InputOutput.class.getName()); literalClassNames.add(BusEvent.class.getCanonicalName()); literalClassNames.add(ScriptExecution.class.getCanonicalName()); literalClassNames.add(LogAction.class.getCanonicalName()); // jodatime static functions literalClassNames.add(DateTime.class.getCanonicalName()); literalClassNames.add(DateMidnight.class.getCanonicalName()); return literalClassNames; }
From source file:org.romaframework.core.schema.SchemaHelper.java
public static void insertElements(SchemaField iField, Object iContent, Object[] iSelection, boolean overrideContent) { if (iField == null) { log.warn("[SchemaHelper.insertElements] Field is null"); return;/*w w w . ja v a2s . c om*/ } if (iContent == null) { log.warn("[SchemaHelper.insertElements] target object is null. Cannot to value field " + iField); return; } boolean simpleSet = false; if (iSelection != null && iSelection.length > 0 && iSelection[0] != null) simpleSet = Roma.schema().getSchemaClass(iSelection[0]).equals(iField.getType().getSchemaClass()); // TODO: REVIEW BIND MODE WITH NESTED FIELDS EXPRESSION Object currentValue = SchemaHelper.getFieldValue(iField, iContent); if (currentValue == null && SchemaHelper.isMultiValueObject(iField) && !simpleSet) // CHECK IF IT'S A COLLECTION: IN THIS CASE THROW AN EXCEPTION SINCE // IT MUST BE INITIALIZED BEFORE TO USE IT if (isAssignableAs(iField.getType(), Collection.class)) throw new IllegalArgumentException( "The collection in field '" + iField.getEntity().getSchemaClass().getName() + "." + iField.getName() + "' is null: cannot add elements. Remember to initialize it."); else if (isAssignableAs(iField.getType(), Map.class)) throw new IllegalArgumentException( "The map in field '" + iField.getEntity().getSchemaClass().getName() + "." + iField.getName() + "' is null: cannot add elements. Remember to initialize it."); if (currentValue instanceof Collection<?> && !simpleSet) { // INSERT EACH ELEMENT OF SELECTION IN THE COLLECTION Collection<Object> coll = (Collection<Object>) currentValue; if (overrideContent) coll.clear(); if (iSelection != null) { for (Object o : iSelection) { coll.add(EntityHelper.getEntityObjectIfNeeded(o, iField.getEmbeddedType())); } } } else if (currentValue instanceof Map && !simpleSet) { // INSERT EACH ELEMENT OF SELECTION IN THE MAP (KEY = SELECTION // OBJ.toString() if (overrideContent) ((Map<String, Object>) currentValue).clear(); if (iSelection != null) { for (Object o : iSelection) { ((Map<String, Object>) currentValue).put(EntityHelper.getEntityObject(o).toString(), EntityHelper.getEntityObject(o)); } } } else if (((Class<?>) iField.getLanguageType()).isArray() && !simpleSet) { Object array = null; if (iField.getLanguageType().equals(Object[].class)) { // OBJECT[]: NO CONVERSION REQUIRED if (overrideContent) { array = iSelection; } else { Object[] oldValue = (Object[]) SchemaHelper.getFieldValue(iField, iContent); int oldLength = 0; if (oldValue != null) oldLength = oldValue.length; array = new Object[oldLength + iSelection.length]; if (oldValue != null) System.arraycopy(oldValue, 0, array, 0, oldLength); System.arraycopy(iSelection, 0, array, oldLength, iSelection.length); } } else if (iSelection != null) { // COPY THE ARRAY TO USE REAL CLASS ARRAY, IF ANY int i = 0; Object oldValue = SchemaHelper.getFieldValue(iField, iContent); if (overrideContent || oldValue == null) { array = Array.newInstance(((Class<?>) iField.getLanguageType()).getComponentType(), iSelection.length); } else { int oldSize = Array.getLength(oldValue); array = Array.newInstance(((Class<?>) iField.getLanguageType()).getComponentType(), iSelection.length + oldSize); for (; i < oldSize; ++i) { Array.set(array, i, Array.get(oldValue, i)); } } for (int sourcePos = 0; sourcePos < iSelection.length; ++sourcePos, ++i) { Array.set(array, i, iSelection[sourcePos]); } } SchemaHelper.setFieldValue(iField, iContent, array); } else { Object firstSelection = iSelection != null && iSelection.length > 0 ? iSelection[0] : null; SchemaHelper.setFieldValue(iField, iContent, EntityHelper.getEntityObjectIfNeeded(firstSelection, iField.getType())); } // REFRESH THE FIELD Roma.fieldChanged(iContent, iField.getName()); }
From source file:ubic.gemma.apps.MeshTermFetcherCli.java
@Override protected Exception doWork(String[] args) { processCommandLine("Load PubMed records", args); PubMedXMLFetcher fetcher = new PubMedXMLFetcher(); try {// w w w. j av a2 s . co m Collection<Integer> ids = readIdsFromFile(file); Collection<Integer> chunk = new ArrayList<Integer>(); for (Integer i : ids) { chunk.add(i); if (chunk.size() == CHUNK_SIZE) { processChunk(fetcher, chunk); chunk.clear(); } } if (!chunk.isEmpty()) { processChunk(fetcher, chunk); } } catch (IOException e) { return e; } return null; }
From source file:org.apache.streams.regex.AbstractRegexExtensionExtractor.java
@Override public List<StreamsDatum> process(StreamsDatum entry) { Activity activity;/*from www .j av a2 s . co m*/ if (entry.getDocument() instanceof Activity) { activity = (Activity) entry.getDocument(); } else if (entry.getDocument() instanceof ObjectNode) { activity = mapper.convertValue(entry.getDocument(), Activity.class); } else { return new ArrayList<>(); } if (StringUtils.isBlank(pattern)) { prepare(null); } Map<String, List<Integer>> matches = RegexUtils.extractMatches(pattern, activity.getContent()); Collection<T> entities = ensureTargetObject(activity); for (String key : matches.keySet()) { entities.add(prepareObject(key)); } Set<T> set = new HashSet<>(); set.addAll(entities); entities.clear(); entities.addAll(set); entry.setDocument(activity); return Collections.singletonList(entry); }
From source file:org.carewebframework.vista.ui.notification.NotificationService.java
/** * Returns a list of recipients associated with a scheduled notification. * /*from w w w . j av a 2s. c om*/ * @param notification A scheduled notification. * @param result Recipients associated with the notification. */ public void getScheduledNotificationRecipients(ScheduledNotification notification, Collection<Recipient> result) { List<String> lst = broker.callRPCList("RGCWXQ SCHRECIP", null, notification.getIen()); result.clear(); for (String data : lst) { result.add(new Recipient(data)); } }
From source file:ubic.gemma.core.apps.MeshTermFetcherCli.java
@Override protected Exception doWork(String[] args) { Exception e = super.processCommandLine(args); if (e != null) return e; PubMedXMLFetcher fetcher = new PubMedXMLFetcher(); try {/*w w w. j a v a 2s . c o m*/ Collection<Integer> ids = this.readIdsFromFile(file); Collection<Integer> chunk = new ArrayList<>(); for (Integer i : ids) { chunk.add(i); if (chunk.size() == MeshTermFetcherCli.CHUNK_SIZE) { this.processChunk(fetcher, chunk); chunk.clear(); } } if (!chunk.isEmpty()) { this.processChunk(fetcher, chunk); } } catch (IOException exception) { return exception; } return null; }