List of usage examples for java.util ListIterator remove
void remove();
From source file:org.etudes.component.app.melete.MeleteCHServiceImpl.java
public List getListofMediaFromCollection(String collId) { try {/*from ww w . j av a 2 s . c o m*/ if (!isUserAuthor()) { logger.info("User is not authorized to access meleteDocs collection"); return null; } // setup a security advisor meleteSecurityService.pushAdvisor(); ContentCollection c = getContentservice().getCollection(collId); List mem = c.getMemberResources(); if (mem == null) return null; ListIterator memIt = mem.listIterator(); while (memIt != null && memIt.hasNext()) { ContentEntity ce = (ContentEntity) memIt.next(); if (ce.isResource()) { String contentextension = ((ContentResource) ce).getContentType(); // if(contentextension.equals(MIME_TYPE_EDITOR)) // memIt.remove(); } else memIt.remove(); } return mem; } catch (Exception e) { logger.error(e.toString()); } finally { // clear the security advisor meleteSecurityService.popAdvisor(); } return null; }
From source file:org.etudes.component.app.melete.MeleteCHServiceImpl.java
public List getListofImagesFromCollection(String collId) { try {/*from w w w. j a va 2 s . c om*/ // setup a security advisor meleteSecurityService.pushAdvisor(); long starttime = System.currentTimeMillis(); logger.debug("time to get all collectionMap" + starttime); ContentCollection c = getContentservice().getCollection(collId); List mem = c.getMemberResources(); if (mem == null) return null; ListIterator memIt = mem.listIterator(); while (memIt != null && memIt.hasNext()) { ContentEntity ce = (ContentEntity) memIt.next(); if (ce.isResource()) { String contentextension = ((ContentResource) ce).getProperties() .getProperty(ce.getProperties().getNamePropContentType()); if (!contentextension.startsWith("image")) { memIt.remove(); } } else memIt.remove(); } long endtime = System.currentTimeMillis(); logger.debug("end time to get all collectionMap" + (endtime - starttime)); return mem; } catch (Exception e) { logger.error(e.toString()); } finally { // clear the security advisor meleteSecurityService.popAdvisor(); } return null; }
From source file:net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl.java
@Override public Command reconcileFlows(ArrayList<OFMatchReconcile> ofmRcList) { ListIterator<OFMatchReconcile> iter = ofmRcList.listIterator(); while (iter.hasNext()) { OFMatchReconcile ofm = iter.next(); // Remove the STOPPed flow. if (Command.STOP == reconcileFlow(ofm)) { iter.remove(); }/*from ww w .j ava2 s. c o m*/ } if (ofmRcList.size() > 0) { return Command.CONTINUE; } else { return Command.STOP; } }
From source file:uk.ac.ucl.excites.sapelli.storage.eximport.csv.CSVRecordsImporter.java
private void parseHeaderRow(String row) throws Exception { // Check row length: if (row.isEmpty()) throw new IllegalArgumentException("Header row cannot be null"); // Get separator by reading last char of the header: try {//from w ww. j a va 2 s .c o m separator = Separator.getSeparator(row.charAt(row.length() - 1)); } catch (IllegalArgumentException iae) { separator = CSVRecordsExporter.DEFAULT_SEPARATOR; addWarning("Header row does no contain separator hint, trying to parse file using default separator (" + separator.toString() + ")."); } // Split header row: List<String> headers = splitRow(row); // Parse attribute headers: Long modelID = null; Integer modelSchemaNo = null; String schemaName = null; try { ListIterator<String> headerIter = headers.listIterator(headers.size()); String attributeHeader; int equalsPos; // Iterate over headers back to front until we hit one without '=': while (headerIter.hasPrevious() && (equalsPos = (attributeHeader = headerIter.previous()).indexOf('=')) != -1) { switch (attributeHeader.substring(0, equalsPos)) { case Schema.ATTRIBUTE_MODEL_ID: modelID = Long.valueOf(attributeHeader.substring(equalsPos + 1)); break; case Schema.ATTRIBUTE_MODEL_SCHEMA_NUMBER: modelSchemaNo = Integer.valueOf(attributeHeader.substring(equalsPos + 1)); break; case Schema.ATTRIBUTE_SCHEMA_NAME: schemaName = deescapeAndUnquote(attributeHeader.substring(equalsPos + 1)); break; case Exporter.ATTRIBUTE_EXPORTED_AT: try { exportedAt = new TimeStamp(Exporter.ExportedAtFormatter.withOffsetParsed() .parseDateTime(attributeHeader.substring(equalsPos + 1))); } catch (Exception e) { addWarning( "Error upon parsing exportedAt time: " + attributeHeader.substring(equalsPos + 1)); } break; default: addWarning("Ignored unrecognised attribute header: " + attributeHeader); } // Remove attribute header: headerIter.remove(); } } catch (Exception e) { // don't throw here client.logWarning("Error upon parsing CSV attribute header: " + ExceptionHelpers.getMessageAndCause(e)); } // Get schema: if (modelID != null && modelSchemaNo != null) { Schema headerSchema = null; try { headerSchema = client.getSchema(modelID, modelSchemaNo, schemaName); } catch (Exception e) { if (schema != null) addWarning("Could not find schema: " + e.getMessage() + ". Using fallback schema (" + schema.toString() + ")."); else throw e; } if (schema != null && !headerSchema.equals(schema)) addWarning("CSV schema (" + headerSchema.toString() + ") is different from given fallback schema (" + schema.toString() + ")."); schema = headerSchema; // !!! } else { String error = "No (readable) model/schema information in header!"; if (schema != null) addWarning(error + " Using fallback schema (" + schema.toString() + ")."); else throw new Exception("Could not find model/schema information in header!"); } if (schema != null) { // Parse column headers: List<ColumnPointer<?>> headerColumnPointers = new ArrayList<ColumnPointer<?>>(headers.size()); for (String columnHeader : headers) // (the remaining headers should all be qualified column names) headerColumnPointers.add(ColumnPointer.ByName(schema, columnHeader, false, false)); // if we get her nothing went wrong above: this.columnPointers = headerColumnPointers; } }
From source file:com.robonobo.eon.SEONConnection.java
private void storePktForLater(SEONPacket pkt) throws EONException { // If the packet is after our last one, put it at the end, otherwise // search where to put it if (recvdPkts.size() == 0) recvdPkts.add(pkt);/*from ww w. j a v a 2 s . co m*/ else if (mod.gt(pkt.getSequenceNumber(), recvdPkts.getLast().getSequenceNumber())) recvdPkts.addLast(pkt); else { // TODO If this is still too slow, we could cut out the iterator // creation by creating a custom list class with a resettable // iterator... ListIterator<SEONPacket> iter = recvdPkts.listIterator(); while (iter.hasNext()) { SEONPacket itPkt = iter.next(); if (pkt.getSequenceNumber() == itPkt.getSequenceNumber()) { if (itPkt.getPayloadSize() == 0) { // This is a data pkt coming after a bare ack - replace it with the data pkt iter.remove(); iter.add(pkt); } // Otherwise this is just a duplicate pkt - ignore break; } else if (mod.lt(pkt.getSequenceNumber(), itPkt.getSequenceNumber())) { // Insert the pkt *before* the current pkt iter.previous(); iter.add(pkt); break; } } } }
From source file:org.commonjava.maven.ext.common.model.Project.java
private void resolveDeps(MavenSessionHandler session, List<Dependency> deps, boolean includeManagedDependencies, HashMap<ArtifactRef, Dependency> resolvedDependencies) throws ManipulationException { ListIterator<Dependency> iterator = deps.listIterator(deps.size()); // Iterate in reverse order so later deps take precedence while (iterator.hasPrevious()) { Dependency d = iterator.previous(); String g = PropertyResolver.resolveInheritedProperties(session, this, "${project.groupId}".equals(d.getGroupId()) ? getGroupId() : d.getGroupId()); String a = PropertyResolver.resolveInheritedProperties(session, this, "${project.artifactId}".equals(d.getArtifactId()) ? getArtifactId() : d.getArtifactId()); String v = PropertyResolver.resolveInheritedProperties(session, this, d.getVersion()); if (includeManagedDependencies && isEmpty(v)) { v = "*"; }//from ww w . j av a2 s .co m if (isNotEmpty(g) && isNotEmpty(a) && isNotEmpty(v)) { SimpleArtifactRef sar = new SimpleArtifactRef(g, a, v, d.getType(), d.getClassifier()); // If the GAVTC already exists within the map it means we have a duplicate entry. While Maven // technically allows this it does warn that this leads to unstable models. In PME case this breaks // the indexing as we don't have duplicate entries. Given they are exact matches, remove older duplicate. if (resolvedDependencies.containsKey(sar)) { logger.error("Found duplicate entry within dependency list. Key of {} and dependency {}", sar, d); iterator.remove(); } else { Dependency old = resolvedDependencies.put(sar, d); if (old != null) { logger.error( "Internal project dependency resolution failure ; replaced {} in store by {}:{}:{}.", old, g, a, v); throw new ManipulationException( "Internal project dependency resolution failure ; replaced " + old + " by " + d); } } } } }
From source file:org.apache.poi.ss.format.CellNumberFormatter.java
private void interpretCommas(StringBuffer sb) { // In the integer part, commas at the end are scaling commas; other commas mean to show thousand-grouping commas ListIterator<Special> it = specials.listIterator(integerEnd()); boolean stillScaling = true; integerCommas = false;//w w w . j a v a 2 s .com while (it.hasPrevious()) { Special s = it.previous(); if (s.ch != ',') { stillScaling = false; } else { if (stillScaling) { scale /= 1000; } else { integerCommas = true; } } } if (decimalPoint != null) { it = specials.listIterator(fractionalEnd()); while (it.hasPrevious()) { Special s = it.previous(); if (s.ch != ',') { break; } else { scale /= 1000; } } } // Now strip them out -- we only need their interpretation, not their presence it = specials.listIterator(); int removed = 0; while (it.hasNext()) { Special s = it.next(); s.pos -= removed; if (s.ch == ',') { removed++; it.remove(); sb.deleteCharAt(s.pos); } } }
From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.MessageCenterFragment.java
public void updateMessageSentStates() { dateStampsSeen.clear();/*from w w w. j a v a2s . co m*/ MessageCenterUtil.CompoundMessageCommonInterface lastSent = null; Set<String> uniqueNonce = new HashSet<String>(); int removedItems = 0; ListIterator<MessageCenterListItem> listItemIterator = listItems.listIterator(); while (listItemIterator.hasNext()) { int adapterMessagePosition = listItemIterator.nextIndex() - removedItems; MessageCenterListItem message = listItemIterator.next(); if (message instanceof ApptentiveMessage) { /* Check if there is any duplicate messages and remove if found. * add() of a Set returns false if the element already exists. */ if (!uniqueNonce.add(((ApptentiveMessage) message).getNonce())) { listItemIterator.remove(); messageCenterRecyclerViewAdapter.notifyItemRemoved(adapterMessagePosition); removedItems++; continue; } // Update timestamps ApptentiveMessage apptentiveMessage = (ApptentiveMessage) message; Double sentOrReceivedAt = apptentiveMessage.getCreatedAt(); String dateStamp = createDatestamp(sentOrReceivedAt); if (dateStamp != null) { if (dateStampsSeen.add(dateStamp)) { if (apptentiveMessage.setDatestamp(dateStamp)) { messageCenterRecyclerViewAdapter.notifyItemChanged(adapterMessagePosition); } } else { if (apptentiveMessage.clearDatestamp()) { messageCenterRecyclerViewAdapter.notifyItemChanged(adapterMessagePosition); } } } //Find last sent if (apptentiveMessage.isOutgoingMessage()) { if (sentOrReceivedAt != null && sentOrReceivedAt > Double.MIN_VALUE) { lastSent = (MessageCenterUtil.CompoundMessageCommonInterface) apptentiveMessage; lastSent.setLastSent(false); } } } } if (lastSent != null) { lastSent.setLastSent(true); } }
From source file:cz.cesnet.shongo.connector.device.CiscoMCUConnector.java
/** * Populates the results list - puts the original objects instead of item stubs. * <p/>//from ww w .ja va2 s . co m * If there was a previous call to the same command, the changed items are just stubs in the new result set. To use * the results, this method populates all the stubs and puts the objects from the previous call in their place. * * @param results list of results, some of which may be stubs; gets modified so that it contains no stubs * @param currentRevision the revision of this results * @param lastRevision the revision of the previous call of the same command * @param command the command called to get the supplied results * @param enumField the field name from which the supplied results where taken within the command result */ private void populateResultsFromCache(List<Map<String, Object>> results, Integer currentRevision, Integer lastRevision, Command command, String enumField) throws CommandException { // we got just the difference since lastRevision (or full set if this is the first issue of the command) final String cacheId = getCommandCacheId(command); if (lastRevision != null) { // fill the values that have not changed since lastRevision ListIterator<Map<String, Object>> iterator = results.listIterator(); while (iterator.hasNext()) { Map<String, Object> item = iterator.next(); if (isItemDead(item)) { // from the MCU API: "The device will also never return a dead record if listAll is set to true." // unfortunately, the buggy MCU still reports some items as dead even though listAll = true, so we // must remove them by ourselves (according to the API, a dead item should not have been ever // listed when listAll = true) iterator.remove(); } else if (!hasItemChanged(item)) { ResultsCache cache = resultsCache.get(cacheId); Map<String, Object> it = cache.getItem(item); if (it == null) { throw new CommandException( "Item reported as not changed by the device, but was not found in the cache: " + item); } iterator.set(it); } } } // store the results and the revision number for the next time ResultsCache rc = resultsCache.get(cacheId); if (rc == null) { rc = new ResultsCache(); resultsCache.put(cacheId, rc); } rc.store(currentRevision, results); }
From source file:marytts.modules.phonemiser.AllophoneSet.java
/** * Syllabify a string of allophones. If stress markers are provided, they are preserved; otherwise, primary stress will be * assigned to the initial syllable./*from w w w. j ava2 s. c o m*/ * <p> * The syllabification algorithm itself follows the <i>Core Syllabification Principle (CSP)</i> from <blockquote>G.N. Clements * (1990) "The role of the sonority cycle in core syllabification." In: J. Kingston & M.E. Beckman (Eds.), * <em>Papers in Laboratory Phonology I: Between the Grammar and Physics of Speech</em>, Ch. 17, pp. 283-333, Cambridge * University Press.</blockquote> * * @param phoneString * phoneString * @return a syllabified string; individual allophones are separated by spaces, and syllables, by dashes. * @throws IllegalArgumentException * if the <b>phoneString</b> is empty or contains a symbol that satisfies none of the following conditions: * <ol> * <li>the symbol corresponds to an Allophone, or</li> <li>the symbol is a stress symbol (cf. {@link Stress}), or * </li> <li>the symbol is a syllable boundary (<code>-</code>)</li> * </ol> * */ public String syllabify(String phoneString) throws IllegalArgumentException { // Before we process, a sanity check: if (phoneString.trim().isEmpty()) { throw new IllegalArgumentException("Cannot syllabify empty phone string"); } // First, split phoneString into a List of allophone Strings... List<String> allophoneStrings = splitIntoAllophoneList(phoneString, true); // ...and create from it a List of generic Objects List<Object> phonesAndSyllables = new ArrayList<Object>(allophoneStrings); // Create an iterator ListIterator<Object> iterator = phonesAndSyllables.listIterator(); // First iteration (left-to-right): // CSP (a): Associate each [+syllabic] segment to a syllable node. Syllable currentSyllable = null; while (iterator.hasNext()) { String phone = (String) iterator.next(); try { // either it's an Allophone Allophone allophone = getAllophone(phone); if (allophone.isSyllabic()) { // if /6/ immediately follows a non-diphthong vowel, it should be appended instead of forming its own syllable boolean appendR = false; if (allophone.getFeature("ctype").equals("r")) { // it's an /6/ if (iterator.previousIndex() > 1) { Object previousPhoneOrSyllable = phonesAndSyllables.get(iterator.previousIndex() - 1); if (previousPhoneOrSyllable == currentSyllable) { // the /6/ immediately follows the current syllable if (!currentSyllable.getLastAllophone().isDiphthong()) { // the vowel immediately preceding the /6/ is not a diphthong appendR = true; } } } } if (appendR) { iterator.remove(); currentSyllable.appendAllophone(allophone); } else { currentSyllable = new Syllable(allophone); iterator.set(currentSyllable); } } } catch (IllegalArgumentException e) { // or a stress or boundary marker if (!getIgnoreChars().contains(phone)) { throw e; } } } // Second iteration (right-to-left): // CSP (b): Given P (an unsyllabified segment) preceding Q (a syllabified segment), adjoin P to the syllable containing Q // iff P has lower sonority rank than Q (iterative). currentSyllable = null; boolean foundPrimaryStress = false; iterator = phonesAndSyllables.listIterator(phonesAndSyllables.size()); while (iterator.hasPrevious()) { Object phoneOrSyllable = iterator.previous(); if (phoneOrSyllable instanceof Syllable) { currentSyllable = (Syllable) phoneOrSyllable; } else if (currentSyllable == null) { // haven't seen a Syllable yet in this iteration continue; } else { String phone = (String) phoneOrSyllable; try { // it's an Allophone -- prepend to the Syllable Allophone allophone = getAllophone(phone); if (allophone.sonority() < currentSyllable.getFirstAllophone().sonority()) { iterator.remove(); currentSyllable.prependAllophone(allophone); } } catch (IllegalArgumentException e) { // it's a provided stress marker -- assign it to the Syllable switch (phone) { case Stress.PRIMARY: iterator.remove(); currentSyllable.setStress(Stress.PRIMARY); foundPrimaryStress = true; break; case Stress.SECONDARY: iterator.remove(); currentSyllable.setStress(Stress.SECONDARY); break; case "-": iterator.remove(); // TODO handle syllable boundaries break; default: throw e; } } } } // Third iteration (left-to-right): // CSP (c): Given Q (a syllabified segment) followed by R (an unsyllabified segment), adjoin R to the syllable containing // Q iff has a lower sonority rank than Q (iterative). Syllable initialSyllable = currentSyllable; currentSyllable = null; iterator = phonesAndSyllables.listIterator(); while (iterator.hasNext()) { Object phoneOrSyllable = iterator.next(); if (phoneOrSyllable instanceof Syllable) { currentSyllable = (Syllable) phoneOrSyllable; } else { String phone = (String) phoneOrSyllable; try { // it's an Allophone -- append to the Syllable Allophone allophone; try { allophone = getAllophone(phone); } catch (IllegalArgumentException e) { // or a stress or boundary marker -- remove if (getIgnoreChars().contains(phone)) { iterator.remove(); continue; } else { throw e; } } if (currentSyllable == null) { // haven't seen a Syllable yet in this iteration iterator.remove(); if (initialSyllable == null) { // haven't seen any syllable at all initialSyllable = new Syllable(allophone); iterator.add(initialSyllable); } else { initialSyllable.prependAllophone(allophone); } } else { // append it to the last seen Syllable iterator.remove(); currentSyllable.appendAllophone(allophone); } } catch (IllegalArgumentException e) { throw e; } } } // if primary stress was not provided, assign it to initial syllable if (!foundPrimaryStress) { initialSyllable.setStress(Stress.PRIMARY); } // join Syllables with dashes and return the String return StringUtils.join(phonesAndSyllables, " - "); }