List of usage examples for java.util Iterator remove
default void remove()
From source file:es.caib.zkib.jxpath.util.ValueUtils.java
/** * Remove the index'th element from the supplied collection. * @param collection to edit/*from w ww . j av a2 s .c o m*/ * @param index int * @return the resulting collection */ public static Object remove(Object collection, int index) { collection = getValue(collection); if (collection == null) { return null; } if (index >= getLength(collection)) { throw new JXPathException("No such element at index " + index); } if (collection.getClass().isArray()) { int length = Array.getLength(collection); Object smaller = Array.newInstance(collection.getClass().getComponentType(), length - 1); if (index > 0) { System.arraycopy(collection, 0, smaller, 0, index); } if (index < length - 1) { System.arraycopy(collection, index + 1, smaller, index, length - index - 1); } return smaller; } if (collection instanceof List) { int size = ((List) collection).size(); if (index < size) { ((List) collection).remove(index); } return collection; } if (collection instanceof Collection) { Iterator it = ((Collection) collection).iterator(); for (int i = 0; i < index; i++) { if (!it.hasNext()) { break; } it.next(); } if (it.hasNext()) { it.next(); it.remove(); } return collection; } throw new JXPathException("Cannot remove " + collection.getClass().getName() + "[" + index + "]"); }
From source file:com.icesoft.faces.util.event.servlet.ContextEventRepeater.java
private static void removeBufferedEvents(final String iceFacesId, final int viewNumber) { synchronized (BUFFERED_CONTEXT_EVENTS) { Iterator _bufferedContextEvents = BUFFERED_CONTEXT_EVENTS.iterator(); while (_bufferedContextEvents.hasNext()) { Object event = _bufferedContextEvents.next(); if (event instanceof ViewNumberRetrievedEvent && ((ViewNumberRetrievedEvent) event).getICEfacesID().equals(iceFacesId) && ((ViewNumberRetrievedEvent) event).getViewNumber() == viewNumber) { _bufferedContextEvents.remove(); }//w w w. j a v a2s .co m } } }
From source file:eulermind.importer.LineNode.java
private static void brokenSentencesToTree(LineNode root) { //????/*w w w . j a v a2s .c om*/ ArrayList<Integer> lineStarts = new ArrayList<>(); String combinedLine = ""; for (int i = 0; i < root.getChildCount(); i++) { lineStarts.add(combinedLine.length()); combinedLine += root.getChildAt(i).m_trimLine + (i < root.getChildCount() - 1 ? " " : ""); } lineStarts.add(combinedLine.length()); // //??? BreakIterator boundary = BreakIterator.getSentenceInstance(getStringULocale(combinedLine)); boundary.setText(combinedLine); ArrayList<Integer> icuSentenceStarts = new ArrayList<>(); for (int icuSentenceStart = boundary.first(); icuSentenceStart != BreakIterator.DONE; //icuSentenceStartcombinedLine.length() icuSentenceStart = boundary.next()) { icuSentenceStarts.add(icuSentenceStart); } //??? Iterator<Integer> lineStartIter = lineStarts.iterator(); while (lineStartIter.hasNext()) { Integer lineStart = lineStartIter.next(); if (!(icuSentenceStarts.contains(lineStart - 1) || icuSentenceStarts.contains(lineStart))) { lineStartIter.remove(); } } assert (lineStarts.contains(combinedLine.length())); //??? //1 ????, ?linsStarts.size == 2 (0combinedLine.length()) root.getChildCount >= 2 //2 ???? if (lineStarts.size() == 2 && root.getChildCount() >= 2 || lineStarts.size() - 1 == root.getChildCount()) { return; } assert (lineStarts.size() - 1 < root.getChildCount()); root.removeAllChildren(); //?? // ?? // ???? for (int lineIdx = 0; lineIdx < lineStarts.size() - 1; lineIdx++) { int lineStart = lineStarts.get(lineIdx); int lineEnd = lineStarts.get(lineIdx + 1); int firstSentenceInThisLine = 0; int firstSentenceInNextLine = 0; for (firstSentenceInThisLine = 0; firstSentenceInThisLine < icuSentenceStarts.size() - 1; firstSentenceInThisLine++) { int sentenceStart = icuSentenceStarts.get(firstSentenceInThisLine); if (lineStart <= sentenceStart && sentenceStart < lineEnd) { break; } } for (firstSentenceInNextLine = firstSentenceInThisLine + 1; firstSentenceInNextLine < icuSentenceStarts.size() - 1; firstSentenceInNextLine++) { int sentenceStart = icuSentenceStarts.get(firstSentenceInNextLine); if (sentenceStart >= lineEnd) { break; } } assert firstSentenceInNextLine - firstSentenceInThisLine >= 1; if (firstSentenceInNextLine - firstSentenceInThisLine == 1) { int sentenceStart = icuSentenceStarts.get(firstSentenceInThisLine); int sentenceEnd = icuSentenceStarts.get(firstSentenceInNextLine); LineNode lineNode = new LineNode(combinedLine.substring(sentenceStart, sentenceEnd)); root.add(lineNode); } else { LineNode lineNode = new LineNode("p"); for (int sentence = firstSentenceInThisLine; sentence < firstSentenceInNextLine; sentence++) { int sentenceStart = icuSentenceStarts.get(sentence); int sentenceEnd = icuSentenceStarts.get(sentence + 1); LineNode sentenceNode = new LineNode(combinedLine.substring(sentenceStart, sentenceEnd)); lineNode.add(sentenceNode); } root.add(lineNode); } } //s_logger.info("ccccccccccc: {}", lineTreeToString(root)); }
From source file:sce.RESTAppMetricJob.java
public static String printMap(Map mp) { String result = ""; Iterator it = mp.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); //System.out.println(pairs.getKey() + " = " + pairs.getValue()); result += pairs.getKey() + " = " + pairs.getValue() + "\n"; it.remove(); // avoids a ConcurrentModificationException }/*from w w w .j a v a 2 s. com*/ return result; }
From source file:com.aurel.track.exchange.excel.ExcelFieldMatchBL.java
/** * Match by fieldConfigBean labels/*from www. jav a2 s.c o m*/ * @param excelColumnNames * @param fieldConfigsMap * @param previousMappings */ private static void addMatch(Set<String> excelColumnNames, Map<String, TFieldConfigBean> fieldConfigsMap, Map<String, Integer> previousMappings) { if (!excelColumnNames.isEmpty()) { Iterator<String> itrExcelColumNames = excelColumnNames.iterator(); while (itrExcelColumNames.hasNext()) { String columName = itrExcelColumNames.next(); if (fieldConfigsMap.containsKey(columName)) { TFieldConfigBean fieldConfigBean = fieldConfigsMap.get(columName); if (fieldConfigBean != null) { previousMappings.put(columName, fieldConfigBean.getObjectID()); itrExcelColumNames.remove(); } } } } }
From source file:de.icongmbh.oss.maven.plugin.javassist.ClassnameExtractor.java
/** * Wrapping the iterator (as reference) of class file names and extract full qualified class name * on//from ww w . ja v a2 s .c o m * {@link Iterator#next()}. * <p> * It is possible that {@link Iterator#hasNext()} returns {@code true} and {@link Iterator#next()} * returns {@code null}. * </p> * * @param parentDirectory to remove from {@code classFile} and maybe {@code null}. * @param classFileIterator to extract the names from. Must not be {@code null}. * @return iterator of full qualified class names based on passed classFiles or {@code null} * @see #extractClassNameFromFile(File, File) */ // DANGEROUS call by reference public static Iterator<String> iterateClassnames(final File parentDirectory, final Iterator<File> classFileIterator) { return new Iterator<String>() { @Override public boolean hasNext() { return classFileIterator == null ? false : classFileIterator.hasNext(); } @Override public String next() { final File classFile = classFileIterator.next(); try { // possible returns null return extractClassNameFromFile(parentDirectory, classFile); } catch (final IOException e) { throw new RuntimeException(e.getMessage()); } } @Override public void remove() { classFileIterator.remove(); } }; }
From source file:com.github.drochetti.javassist.maven.ClassnameExtractor.java
/** * Wrapping passed iterator (as reference) of class file names and extract full qualified class name on * {@link Iterator#next()}./*w ww . j ava 2 s . c om*/ * <p> * It is possible that {@link Iterator#hasNext()} returns <code>true</code> * and {@link Iterator#next()} returns <code>null</code>. * * @param parentDirectory * @param classFiles * @return iterator of full qualified class names based on passed classFiles * or <code>null</code> * @see #extractClassNameFromFile(File, File) */ // DANGEROUS call by reference public static Iterator<String> iterateClassnames(final File parentDirectory, final Iterator<File> classFileIterator) { return new Iterator<String>() { // @Override public boolean hasNext() { return classFileIterator == null ? false : classFileIterator.hasNext(); } // @Override public String next() { final File classFile = classFileIterator.next(); try { // possible returns null return extractClassNameFromFile(parentDirectory, classFile); } catch (final IOException e) { throw new RuntimeException(e.getMessage()); } } // @Override public void remove() { classFileIterator.remove(); } }; }
From source file:com.linkedin.pinot.core.realtime.impl.kafka.KafkaConsumerManager.java
public static void closeAllConsumers() { try {//from ww w . j av a2 s . co m // Shutdown all consumers synchronized (KafkaConsumerManager.class) { LOGGER.info("Trying to shutdown all the kafka consumers"); Iterator<ConsumerAndIterator> consumerIterator = CONSUMER_AND_ITERATOR_FOR_CONFIG_KEY.values() .iterator(); while (consumerIterator.hasNext()) { ConsumerAndIterator consumerAndIterator = consumerIterator.next(); LOGGER.info("Trying to shutdown consumer/iterator {}", consumerAndIterator.getId()); try { consumerAndIterator.getConsumer().shutdown(); } catch (Exception e) { LOGGER.warn("Caught exception while shutting down Kafka consumer with id {}", consumerAndIterator.getId(), e); } consumerIterator.remove(); } CONSUMER_AND_ITERATOR_FOR_CONFIG_KEY.clear(); CONSUMER_RELEASE_TIME.clear(); } } catch (Exception e) { LOGGER.warn("Caught exception during shutting down all kafka consumers", e); } }
From source file:com.btisystems.pronx.ems.App.java
/** * Load mibs from list of source files./*from w w w .j a v a 2 s . c om*/ * * @param group DeviceGroup * @param loader Mib Loader * @param source Mib Source * @param interfaceMap Supported Interfaces * @return */ private static Collection<String> compileMibs(final DeviceGroup group, final MibLoader loader, final MibSource source, final Map<String, JDefinedClass> interfaceMap) { // Get complete package name using group + source. final String packageName = buildPackageName(group.getPackageName(), source.getPackageName()); final List<MibValueSymbol> rootSymbols = locateRootSymbols(loader, source.getRootObjects()); final Map<String, List<MibValueSymbol>> symbolMap = locateChildSymbols(rootSymbols, source.getExcludedRootObjects()); final MibEntityCompiler compiler = new MibEntityCompiler(symbolMap, packageName, interfaceMap, codeModel); compiler.importDependencies(); for (List<MibValueSymbol> symbolList : symbolMap.values()) { final Iterator<MibValueSymbol> iterator = symbolList.iterator(); while (iterator.hasNext()) { final MibValueSymbol symbol = iterator.next(); if (MibEntityCompiler.IMPORTED_SYMBOLS.contains(getOidFromSymbol(symbol))) { LOG.debug("removing common symbol:{}", getOidFromSymbol(symbol)); iterator.remove(); } } } compiler.compile(codeModel); compileNotifications(loader, packageName, source.isGenerateNotificationObjects()); final Map<String, JDefinedClass> classes = compiler.getEntityClasses(); return compiler.generateRootEntity(classes); }
From source file:com.ikanow.infinit.e.processing.generic.aggregation.AssociationAggregationUtils.java
public static void synchronizeEventFeature(AssociationFeaturePojo eventFeature, ObjectId communityId) { DBCollection eventFeatureDb = DbManager.getFeature().getAssociation(); // NOTE: Important that feeds update occurs before synchronization, since the sync "corrupts" the event if (_diagnosticMode || (null != eventFeature.getDb_sync_time()) || (null != eventFeature.getDb_sync_prio())) { // Else this is a new feature so don't need to update the feature DB, only the index (if db_sync_prio null then have to update to avoid b/g aggergation loop) // (note that db_sync_prio will in practice not be set when this is a new feature because it will have same sync_doccount as doc_count) long nCurrTime = System.currentTimeMillis(); //(query from top of the function, basically lookup on gaz_index) BasicDBObject update2 = new BasicDBObject(); update2.put(AssociationFeaturePojo.db_sync_time_, Long.toString(nCurrTime)); update2.put(AssociationFeaturePojo.db_sync_doccount_, eventFeature.getDoccount()); BasicDBObject update = new BasicDBObject(MongoDbManager.set_, update2); // (also can be added to below) BasicDBObject update3 = new BasicDBObject(EntityFeaturePojo.db_sync_prio_, 1); update.put(MongoDbManager.unset_, update3); BasicDBObject query = new BasicDBObject(AssociationFeaturePojo.index_, eventFeature.getIndex()); query.put(AssociationFeaturePojo.communityId_, communityId); // Keep the number of entity1 and entity2 sets down to a reasonable number // (In the end would like to be able to do this based on date rather than (essentially) completely randomly) int nSize; BasicDBObject toPull = null;//from www .ja v a 2s .co m if (null != eventFeature.getEntity1()) { if ((nSize = eventFeature.getEntity1().size()) > AssociationFeaturePojo.entity_MAXFIELDS) { if (null == toPull) toPull = new BasicDBObject(); ArrayList<String> ent1ToRemove = new ArrayList<String>( eventFeature.getEntity1().size() - AssociationFeaturePojo.entity_MAXFIELDS); Iterator<String> it = eventFeature.getEntity1().iterator(); while (it.hasNext() && (nSize > AssociationFeaturePojo.entity_MAXFIELDS)) { String ent = it.next(); if (-1 == ent.indexOf('/')) { // (ie don't remove the index) nSize--; it.remove(); // (this removes from the index) ent1ToRemove.add(ent); } } toPull.put(AssociationFeaturePojo.entity1_, ent1ToRemove); // (this removes from the database) } } if (null != eventFeature.getEntity2()) { if ((nSize = eventFeature.getEntity2().size()) > AssociationFeaturePojo.entity_MAXFIELDS) { if (null == toPull) toPull = new BasicDBObject(); ArrayList<String> ent2ToRemove = new ArrayList<String>( eventFeature.getEntity2().size() - AssociationFeaturePojo.entity_MAXFIELDS); Iterator<String> it = eventFeature.getEntity2().iterator(); while (it.hasNext() && (nSize > AssociationFeaturePojo.entity_MAXFIELDS)) { String ent = it.next(); if (-1 == ent.indexOf('/')) { // (ie don't remove the index) nSize--; it.remove(); // (this removes from the index) ent2ToRemove.add(ent); } } toPull.put(AssociationFeaturePojo.entity2_, ent2ToRemove); // (this removes from the database) } } if (null != toPull) { update.put(MongoDbManager.pullAll_, toPull); // (this removes from the database) } //TESTED (2.1.4.3b, including no index removal clause) if (_diagnosticMode) { if ((null != eventFeature.getDb_sync_time()) || (null != eventFeature.getDb_sync_prio())) { if (_logInDiagnosticMode) System.out.println("AssociationAggregationUtils.synchronizeEventFeature, featureDB: " + query.toString() + " / " + update.toString()); } else { if (_logInDiagnosticMode) System.out.println( "(WOULD NOT RUN) EventAggregationUtils.synchronizeEventFeature, featureDB: " + query.toString() + " / " + update.toString()); } } else { eventFeatureDb.update(query, update, false, true); } } if (_diagnosticMode) { if (_logInDiagnosticMode) System.out.println("AssociationAggregationUtils.synchronizeEventFeature, synchronize: " + new StringBuffer(eventFeature.getIndex()).append(':').append(communityId).toString() + " = " + IndexManager.mapToIndex(eventFeature, new AssociationFeaturePojoIndexMap())); } else { ElasticSearchManager esm = IndexManager.getIndex(AssociationFeaturePojoIndexMap.indexName_); esm.addDocument(eventFeature, new AssociationFeaturePojoIndexMap(), null, true); } }