List of usage examples for java.util Iterator remove
default void remove()
From source file:de.dhke.projects.cutil.collections.aspect.AspectMapKeySet.java
private boolean batchRemove(final Collection<?> c, final boolean retain) { for (K key : _keySet) { if (c.contains(key) != retain) { Map.Entry<K, V> entry = new DefaultMapEntry<>(key, _aspectMap.get(key)); _aspectMap.notifyBeforeElementRemoved(_aspectMap, entry); }//from w ww . jav a 2 s. c o m } boolean wasRemoved = false; Iterator<K> iter = _aspectMap.getDecoratee().keySet().iterator(); while (iter.hasNext()) { K key = iter.next(); if (c.contains(key) != retain) { Map.Entry<K, V> entry = new DefaultMapEntry<>(key, _aspectMap.get(key)); iter.remove(); wasRemoved = true; _aspectMap.notifyAfterElementRemoved(_aspectMap, entry); } } return wasRemoved; }
From source file:com.dat255.ht13.grupp23.model.MapModel.java
/** * Remove the MessagePoint with the matching id. * //from w w w. j a va 2s .c om * @param id * the id of the MessagePoint to be removed. */ public void RemoveMessagePointById(int id) { Iterator<MessagePoint> it = messagePoints.iterator(); while (it.hasNext()) { MessagePoint msgp = it.next(); if (msgp.getId() == id) { it.remove(); break; } } }
From source file:com.evolveum.midpoint.model.intest.manual.CsvBackingStore.java
protected void deleteInCsv(String username) throws IOException { List<String> lines = Files.readAllLines(Paths.get(CSV_TARGET_FILE.getPath())); Iterator<String> iterator = lines.iterator(); while (iterator.hasNext()) { String line = iterator.next(); String[] cols = line.split(","); if (cols[0].matches("\"" + username + "\"")) { iterator.remove(); }// ww w . j a v a2 s .c o m } Files.write(Paths.get(CSV_TARGET_FILE.getPath()), lines, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); }
From source file:com.flexive.ejb.beans.search.SearchEngineBean.java
/** * {@inheritDoc}//from ww w . j a v a 2s . c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public Collection<String> loadNames(ResultLocation location) throws FxApplicationException { final List<String> names = Lists.newArrayList(configuration.getKeys(getConfigurationParameter(location))); // remove default query from list final Iterator<String> iter = names.iterator(); while (iter.hasNext()) { if (iter.next().equals(DEFAULT_QUERY_NAME)) { iter.remove(); } } return names; }
From source file:net.solarnetwork.web.support.AbstractView.java
/** * This method performs the same functions as * {@link AbstractView#render(Map, HttpServletRequest, HttpServletResponse)} * except that it uses a LinkedHashMap to preserve model order rather than a * HashMap.//from w w w. j a v a 2 s . co m */ @Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Rendering view with name '" + getBeanName() + "' with model " + model + " and static attributes " + getStaticAttributes()); } // Consolidate static and dynamic model attributes. Map<String, Object> mergedModel = new LinkedHashMap<String, Object>( getStaticAttributes().size() + (model != null ? model.size() : 0)); mergedModel.putAll(getStaticAttributes()); if (model != null) { mergedModel.putAll(model); } // Expose RequestContext? if (getRequestContextAttribute() != null) { mergedModel.put(getRequestContextAttribute(), createRequestContext(request, response, mergedModel)); } // remove objects that should be ignored if (modelObjectIgnoreTypes != null && modelObjectIgnoreTypes.size() > 0) { Iterator<Object> objects = mergedModel.values().iterator(); while (objects.hasNext()) { Object o = objects.next(); if (o == null) { objects.remove(); continue; } for (Class<?> clazz : modelObjectIgnoreTypes) { if (clazz.isAssignableFrom(o.getClass())) { if (logger.isTraceEnabled()) { logger.trace("Ignoring model type [" + o.getClass() + ']'); } objects.remove(); break; } } } } // remove objects that serialize to null if (propertySerializerRegistrar != null) { for (Iterator<Map.Entry<String, Object>> itr = mergedModel.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, Object> me = itr.next(); Object o = (me.getValue() == null ? null : propertySerializerRegistrar.serializeProperty(me.getKey(), me.getValue().getClass(), me.getValue(), me.getValue())); if (o == null) { if (logger.isDebugEnabled()) { logger.debug("Removing model entry [" + me.getKey() + "] because PropertySerializerRegistrar serialized to null"); } itr.remove(); } } } prepareResponse(request, response); renderMergedOutputModel(mergedModel, request, response); }
From source file:at.tugraz.ist.akm.webservice.requestprocessor.interceptor.HttpClientBackLog.java
private int sweepMap() { int freed = 0; Iterator<Map.Entry<Integer, Long>> iter = mClientBacklog.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Integer, Long> entry = iter.next(); if (entry.getValue() < System.currentTimeMillis()) { iter.remove(); freed++;// w w w .j a v a 2 s .co m } } return freed; }
From source file:com.largecode.interview.rustem.domain.LunchMenu.java
public void removeAllThatNotInList(List<Long> dishIdsFromClient) { Iterator<Dish> iterator = getTheDishes().iterator(); while (iterator.hasNext()) { Dish dish = iterator.next();//from ww w . j av a2 s.c o m if (dish.getIdDish() == null) { continue; } if (!dishIdsFromClient.contains(dish.getIdDish())) { iterator.remove(); } } }
From source file:au.org.ala.delta.model.image.ImageOverlay.java
public void deleteLocation(OverlayLocation selectedOverlayLocation) { Iterator<OverlayLocation> i = this.location.iterator(); while (i.hasNext()) { if (i.next().ID == selectedOverlayLocation.ID) { i.remove(); break; }//from ww w . ja v a2 s . c o m } }
From source file:com.digitalpebble.storm.crawler.ConfigurableTopology.java
private String[] parse(String args[]) { List<String> newArgs = new ArrayList<>(); Collections.addAll(newArgs, args); Iterator<String> iter = newArgs.iterator(); while (iter.hasNext()) { String param = iter.next(); if (param.equals("-conf")) { if (!iter.hasNext()) { throw new RuntimeException("Conf file not specified"); }/* w ww . j av a 2 s .c om*/ iter.remove(); String resource = iter.next(); try { ConfUtils.loadConf(resource, conf); } catch (FileNotFoundException e) { throw new RuntimeException("File not found : " + resource); } iter.remove(); } else if (param.equals("-local")) { isLocal = true; iter.remove(); } else if (param.equals("-ttl")) { if (!iter.hasNext()) { throw new RuntimeException("ttl value not specified"); } iter.remove(); String ttlValue = iter.next(); try { ttl = Integer.parseInt(ttlValue); } catch (NumberFormatException nfe) { throw new RuntimeException("ttl value incorrect"); } iter.remove(); } } return newArgs.toArray(new String[newArgs.size()]); }
From source file:com.zimbra.common.calendar.ZoneInfo2iCalendar.java
/** * @param zoneLines - Only the zoneLines related to a time zone that might be relevant from the reference date. *//* w w w . j av a 2s. c o m*/ private static String getTimeZoneForZoneLines(String tzid, Set<String> aliases, List<ZoneLine> zoneLines, Params params, Set<String> zoneIDs, Map<String, VTimeZone> oldTimeZones) { if ((zoneLines == null) || (zoneLines.isEmpty())) { return ""; } boolean isPrimary = sPrimaryTZIDs.contains(tzid); Integer matchScore = sMatchScores.get(tzid); if (matchScore == null) { if (isPrimary) { matchScore = Integer.valueOf(TZIDMapper.DEFAULT_MATCH_SCORE_PRIMARY); } else { matchScore = Integer.valueOf(TZIDMapper.DEFAULT_MATCH_SCORE_NON_PRIMARY); } } Iterator<String> aliasesIter = aliases.iterator(); while (aliasesIter.hasNext()) { String curr = aliasesIter.next(); if (zoneIDs.contains(curr)) { aliasesIter.remove(); } } ZoneLine zline = zoneLines.get(0); VTimeZone oldVtz = oldTimeZones.get(zline.getName()); Property oldLastModProp = null; if (null != oldVtz) { oldLastModProp = oldVtz.getProperties().getProperty(Property.LAST_MODIFIED); } LastModified newLastModified = getLastModified(params.lastModified); LastModified trialLastModified; if (null != oldLastModProp && oldLastModProp instanceof LastModified) { trialLastModified = (LastModified) oldLastModProp; } else { trialLastModified = newLastModified; } VTimeZone vtz = toVTimeZoneComp(params.referenceDate, zoneLines, trialLastModified, aliases, isPrimary, matchScore); String asText = vtz.toString(); if ((null != oldVtz) && (trialLastModified != newLastModified)) { String oldText = oldVtz.toString(); if (!asText.equals(oldText)) { /* Work around non-round tripped entries where the original source has: * X-ZIMBRA-TZ-ALIAS:(GMT+12.00) Anadyr\, Petropavlovsk-Kamchatsky (RTZ 11) * but in this we have: * X-ZIMBRA-TZ-ALIAS:(GMT+12.00) Anadyr\\\, Petropavlovsk-Kamchatsky (RTZ 11) * suspect that is a bug in libical which may be fixed in a later revision */ String oldText2 = oldText.replace("\\\\\\,", "\\,"); if (!asText.equals(oldText2)) { LastModified lastModProp = (LastModified) vtz.getProperties() .getProperty(Property.LAST_MODIFIED); try { lastModProp.setValue(newLastModified.getValue()); asText = vtz.toString(); } catch (ParseException e) { System.err.println("Problem assigning LAST-MODIFIED - " + e.getMessage()); } } } } return asText; }