List of usage examples for java.util Iterator remove
default void remove()
From source file:nl.npcf.eav.store.EntityAttributeValueStore.java
@Transactional(rollbackFor = EAVValidationException.class) public Entity setValue(String entityKey, Path path, String valueString, Principal createdBy) throws EAVValidationException { EAVAttribute attribute = (EAVAttribute) getEAVSchema().getAttribute(path, true); if (attribute.isAggregate()) { throw EAVValidationException.cannotBeSet(attribute); }//w ww .ja va2 s . c o m Query query = entityManager.createQuery("select entity from EAVEntity entity where entity.key = :key"); query.setParameter("key", entityKey); EAVEntity entity = (EAVEntity) query.getSingleResult(); entity.setSchema(getSchema()); Object value = attribute.stringToValue(valueString); //validate first Iterator<EAVValue> valueIterator = entity.getValues().iterator(); while (valueIterator.hasNext()) { // clear any existing value EAVValue existing = valueIterator.next(); if (existing.getPath().equals(path)) { valueIterator.remove(); entityManager.remove(existing); } } EAVValue eavValue = attribute.instantiate(entity, (EAVPath) path, value, createdBy); entity.getValues().add(eavValue); eavValue.getPath(); entity.validate(); entity.sortValues(); return entity; }
From source file:com.couchbase.client.dcp.state.SessionState.java
/** * Helper method to rollback the given partition to the given sequence number. * * This will set the seqno AND REMOVE ALL ENTRIES from the failover log that are higher * than the given sequence number!/* ww w . j a va 2 s . com*/ * * @param partition the partition to rollback * @param seqno the sequence number where to roll it back to. */ public void rollbackToPosition(short partition, long seqno) { PartitionState ps = partitionStates.get(partition); ps.setStartSeqno(seqno); ps.setSnapshotStartSeqno(seqno); ps.setSnapshotEndSeqno(seqno); Iterator<FailoverLogEntry> flog = ps.getFailoverLog().iterator(); while (flog.hasNext()) { FailoverLogEntry entry = flog.next(); // check if this entry is has a higher seqno than we need to roll back to if (entry.getSeqno() > seqno) { flog.remove(); } } partitionStates.set(partition, ps); }
From source file:mase.spec.SafeHybridExchanger.java
@Override protected void mergeProcess(EvolutionState state) { super.mergeProcess(state); // add foreign individuals to the populations outside the stability threshold for (MetaPopulation mp : metaPops) { if (mp.age >= stabilityTime) { HashSet<MetaPopulation> current = new HashSet<MetaPopulation>(); for (MetaPopulation mpf : metaPops) { if (mp != mpf && mpf.age >= stabilityTime) { current.add(mpf);//from w w w . j av a 2 s . c om } } Iterator<Foreign> iter = mp.foreigns.iterator(); while (iter.hasNext()) { Foreign next = iter.next(); if (current.contains(next.origin)) { current.remove(next.origin); } else { iter.remove(); } } for (MetaPopulation mpf : current) { mp.foreigns.add(new Foreign(mpf)); } } } }
From source file:com.ikanow.infinit.e.data_model.custom.InfiniteMongoInputSplit.java
@SuppressWarnings("deprecation") @Override/*from w ww . j av a 2 s .c o m*/ protected DBCursor getCursor() { //added the limit and skip if (_createCursor && (_cursor == null)) { DBObject query = null; BasicBSONObject queryObj = (BasicBSONObject) _querySpec.get("$query"); BasicBSONObject minObj = (BasicBSONObject) _querySpec.get("$min"); BasicBSONObject maxObj = (BasicBSONObject) _querySpec.get("$max"); if (null == queryObj) { if ((null != minObj) || (null != maxObj)) { // one of min/max specified query = new BasicDBObject(); } else { // no $query, $max or $min => this is the query query = _querySpec; } } else { query = new BasicDBObject(queryObj); } _cursor = InfiniteMongoConfigUtil.getCollection(_mongoURI).find(query, _fieldSpec).sort(_sortSpec) .limit(_limit).skip(_skip); if (null != minObj) { Iterator<Map.Entry<String, Object>> it = minObj.entrySet().iterator(); while (it.hasNext()) { // remove upper/lower limit objects because not sure about new mongo syntax Map.Entry<String, Object> keyVal = it.next(); if (keyVal.getValue() instanceof org.bson.types.MinKey) { it.remove(); } } if (!minObj.isEmpty()) { _cursor = _cursor.addSpecial("$min", new BasicDBObject(minObj)); } } if (null != maxObj) { Iterator<Map.Entry<String, Object>> it = maxObj.entrySet().iterator(); while (it.hasNext()) { // remove upper/lower limit objects because not sure about new mongo syntax Map.Entry<String, Object> keyVal = it.next(); if (keyVal.getValue() instanceof org.bson.types.MaxKey) { it.remove(); } } if (!maxObj.isEmpty()) { _cursor = _cursor.addSpecial("$max", new BasicDBObject(maxObj)); } } //DEBUG //log.info( "Created InfiniteMongoInputSplit cursor: min=" + minObj + ", max=" + maxObj + ", query=" + query ); if (_notimeout) _cursor.setOptions(Bytes.QUERYOPTION_NOTIMEOUT); _cursor.slaveOk(); } return _cursor; }
From source file:pe.gob.mef.gescon.web.ui.RangoMB.java
public void cleanAttributes() { this.setId(BigDecimal.ZERO); this.setDescripcion(StringUtils.EMPTY); this.setNombre(StringUtils.EMPTY); this.setActivo(BigDecimal.ONE); this.setSelectedRango(null); Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages(); if (iter.hasNext() == true) { iter.remove(); FacesContext.getCurrentInstance().renderResponse(); }/*from ww w.ja va2 s. co m*/ }
From source file:com.esri.geoevent.transport.httpPoll.HttpPollInboundTransport.java
@Override public void beforeConnect(TransportContext context) { DateFormat df = null;//from w w w. j a v a 2 s . c o m tsvalue = ""; if (!(context instanceof HttpTransportContext)) return; // Parse user defined initial ts try { df = new SimpleDateFormat(tsformat); } catch (Exception e) { df = null; } if (df != null) { if (ts == null) { try { Date userdefined = df.parse(tsinit); if (userdefined == null) { ts = new Date(0); tsvalue = df.format(ts); } else { tsvalue = df.format(userdefined); } } catch (ParseException e) { ts = new Date(0); tsvalue = df.format(ts); } } else { tsvalue = df.format(ts); } ts = new Date(); } HttpRequest request = ((HttpTransportContext) context).getHttpRequest(); if (request instanceof HttpPost) { ArrayList<NameValuePair> postParameters; postParameters = new ArrayList<NameValuePair>(); if (tsvalue.length() > 0) postParameters.add(new BasicNameValuePair(tsparam, tsvalue)); try { Map<String, String> paramMap = parseParameters(params); Iterator<Entry<String, String>> itr = paramMap.entrySet().iterator(); while (itr.hasNext()) { Entry<String, String> pairs = itr.next(); postParameters.add(new BasicNameValuePair((String) pairs.getKey(), (String) pairs.getValue())); itr.remove(); } if (postParameters.size() > 0) { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParameters, StandardCharsets.UTF_8); ((HttpPost) request).setEntity(entity); } } catch (Exception error) { LOGGER.error("PARSING_ERROR", error.getMessage()); LOGGER.info(error.getMessage(), error); } } }
From source file:forge.card.BoosterGenerator.java
@SuppressWarnings("unchecked") public static PrintSheet makeSheet(String sheetKey, Iterable<PaperCard> src) { PrintSheet ps = new PrintSheet(sheetKey); String[] sKey = TextUtil.splitWithParenthesis(sheetKey, ' ', 2); Predicate<PaperCard> setPred = (Predicate<PaperCard>) (sKey.length > 1 ? IPaperCard.Predicates.printedInSets(sKey[1].split(" ")) : Predicates.alwaysTrue());/*w ww. j a v a 2 s. c om*/ List<String> operators = new LinkedList<>(Arrays.asList(TextUtil.splitWithParenthesis(sKey[0], ':'))); Predicate<PaperCard> extraPred = buildExtraPredicate(operators); // source replacement operators - if one is applied setPredicate will be ignored Iterator<String> itMod = operators.iterator(); while (itMod.hasNext()) { String mainCode = itMod.next(); if (mainCode.regionMatches(true, 0, "fromSheet", 0, 9)) { // custom print sheet String sheetName = StringUtils.strip(mainCode.substring(9), "()\" "); src = StaticData.instance().getPrintSheets().get(sheetName).toFlatList(); setPred = Predicates.alwaysTrue(); } else if (mainCode.startsWith("promo")) { // get exactly the named cards, that's a tiny inlined print sheet String list = StringUtils.strip(mainCode.substring(5), "() "); String[] cardNames = TextUtil.splitWithParenthesis(list, ',', '"', '"'); List<PaperCard> srcList = new ArrayList<>(); for (String cardName : cardNames) { srcList.add(StaticData.instance().getCommonCards().getCard(cardName)); } src = srcList; setPred = Predicates.alwaysTrue(); } else { continue; } itMod.remove(); } // only special operators should remain by now - the ones that could not be turned into one predicate String mainCode = operators.isEmpty() ? null : operators.get(0).trim(); if (null == mainCode || mainCode.equalsIgnoreCase(BoosterSlots.ANY)) { // no restriction on rarity Predicate<PaperCard> predicate = Predicates.and(setPred, extraPred); ps.addAll(Iterables.filter(src, predicate)); } else if (mainCode.equalsIgnoreCase(BoosterSlots.UNCOMMON_RARE)) { // for sets like ARN, where U1 cards are considered rare and U3 are uncommon Predicate<PaperCard> predicateRares = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred); ps.addAll(Iterables.filter(src, predicateRares)); Predicate<PaperCard> predicateUncommon = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_UNCOMMON, extraPred); ps.addAll(Iterables.filter(src, predicateUncommon), 3); } else if (mainCode.equalsIgnoreCase(BoosterSlots.RARE_MYTHIC)) { // Typical ratio of rares to mythics is 53:15, changing to 35:10 in smaller sets. // To achieve the desired 1:8 are all mythics are added once, and all rares added twice per print sheet. Predicate<PaperCard> predicateMythic = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE, extraPred); ps.addAll(Iterables.filter(src, predicateMythic)); Predicate<PaperCard> predicateRare = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred); ps.addAll(Iterables.filter(src, predicateRare), 2); } else { throw new IllegalArgumentException("Booster generator: operator could not be parsed - " + mainCode); } return ps; }
From source file:org.kiji.rest.KijiRESTService.java
/** * {@inheritDoc}//from w ww . j a va 2s . c o m * * @throws IOException when instance in configuration can not be opened and closed. */ @Override public final void run(final KijiRESTConfiguration configuration, final Environment environment) throws IOException { final KijiURI clusterURI = KijiURI.newBuilder(configuration.getClusterURI()).build(); final ManagedKijiClient managedKijiClient = new ManagedKijiClient(configuration); environment.manage(managedKijiClient); // Setup the health checker for the KijiClient environment.addHealthCheck(new KijiClientHealthCheck(managedKijiClient)); // Remove all built-in Dropwizard ExceptionHandler. // Always depend on custom ones. // Inspired by Jeremy Whitlock's suggestion on thoughtspark.org. Set<Object> jerseyResources = environment.getJerseyResourceConfig().getSingletons(); Iterator<Object> jerseyResourcesIterator = jerseyResources.iterator(); while (jerseyResourcesIterator.hasNext()) { Object jerseyResource = jerseyResourcesIterator.next(); if (jerseyResource instanceof ExceptionMapper && jerseyResource.getClass().getName().startsWith("com.yammer.dropwizard.jersey")) { jerseyResourcesIterator.remove(); } } // Load admin task to manually refresh instances. environment.addTask(new RefreshInstancesTask(managedKijiClient)); // Load admin task to manually close instances and tables. environment.addTask(new CloseTask(managedKijiClient)); // Load admin task to manually shutdown the system. environment.addTask(new ShutdownTask(managedKijiClient, configuration)); // Adds custom serializers. registerSerializers(environment.getObjectMapperFactory()); // Adds exception mappers to print better exception messages to the client than what // Dropwizard does by default. environment.addProvider(new GeneralExceptionMapper()); // Load resources. for (KijiRestPlugin plugin : Lookups.get(KijiRestPlugin.class)) { LOG.info("Loading plugin {}", plugin.getClass()); plugin.install(managedKijiClient, configuration, environment); } // Allow global CORS filter. CORS off by default. if (configuration.getCORS()) { environment.addFilter(CrossOriginFilter.class, configuration.getHttpConfiguration().getRootPath()); LOG.info("Global cross-origin resource sharing is allowed."); } }
From source file:at.beris.virtualfile.FileContext.java
private void disposeFileCache() throws IOException { Iterator<Map.Entry<String, File>> it = fileCache.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, File> entry = it.next(); entry.getValue().dispose();//from w ww.jav a 2 s . c om it.remove(); } }
From source file:com.sonymobile.jenkins.plugins.gitlab.gitlabauth.folder.GroupFolderManager.java
/** * Filters groups excluded by the predicate. * * @param groups the groups/*from w w w. j a v a2 s . c o m*/ * @return the groups * @throws GitLabApiException if the connection against GitLab failed */ private Collection<GitLabGroupInfo> filterGroups(Collection<GitLabGroupInfo> groups) throws GitLabApiException { Iterator<GitLabGroupInfo> iterator = groups.iterator(); while (iterator.hasNext()) { if (!managesGroup(iterator.next())) { iterator.remove(); } } return groups; }