List of usage examples for java.util ListIterator remove
void remove();
From source file:com.exalead.io.failover.HostState.java
void killStaleConnections() { int closed = 0; ListIterator<MonitoredConnection> it = freeConnections.listIterator(); while (it.hasNext()) { MonitoredConnection free = it.next(); boolean wasStale; try {/*from ww w . jav a 2 s.com*/ wasStale = free.conn.closeIfStale(); } catch (IOException e) { wasStale = true; free.conn.close(); } if (wasStale) { closed++; it.remove(); } } logger.info("Closed " + closed + " stale connections, " + freeConnections.size() + " remaining"); }
From source file:org.apache.http2.impl.conn.tsccm.RouteSpecificPool.java
/** * Obtains a free entry from this pool, if one is available. * * @return an available pool entry, or <code>null</code> if there is none *//*from ww w .ja v a 2s . c om*/ public BasicPoolEntry allocEntry(final Object state) { if (!freeEntries.isEmpty()) { ListIterator<BasicPoolEntry> it = freeEntries.listIterator(freeEntries.size()); while (it.hasPrevious()) { BasicPoolEntry entry = it.previous(); if (entry.getState() == null || LangUtils.equals(state, entry.getState())) { it.remove(); return entry; } } } if (getCapacity() == 0 && !freeEntries.isEmpty()) { BasicPoolEntry entry = freeEntries.remove(); entry.shutdownEntry(); OperatedClientConnection conn = entry.getConnection(); try { conn.close(); } catch (IOException ex) { log.debug("I/O error closing connection", ex); } return entry; } return null; }
From source file:org.apache.fop.layoutmgr.SpaceResolver.java
/** * Resolves unresolved elements applying the space resolution rules defined in 4.3.1. * @param elems the element list/*from w w w . ja va 2s . c o m*/ */ public static void resolveElementList(List elems) { if (LOG.isTraceEnabled()) { LOG.trace(elems); } boolean first = true; boolean last = false; boolean skipNextElement = false; List unresolvedFirst = new java.util.ArrayList(); List unresolvedSecond = new java.util.ArrayList(); List currentGroup; ListIterator iter = elems.listIterator(); while (iter.hasNext()) { ListElement el = (ListElement) iter.next(); if (el.isUnresolvedElement()) { if (LOG.isTraceEnabled()) { LOG.trace("unresolved found: " + el + " " + first + "/" + last); } BreakElement breakPoss = null; //Clear temp lists unresolvedFirst.clear(); unresolvedSecond.clear(); //Collect groups if (el instanceof BreakElement) { breakPoss = (BreakElement) el; currentGroup = unresolvedSecond; } else { currentGroup = unresolvedFirst; currentGroup.add(el); } iter.remove(); last = true; skipNextElement = true; while (iter.hasNext()) { el = (ListElement) iter.next(); if (el instanceof BreakElement && breakPoss != null) { skipNextElement = false; last = false; break; } else if (currentGroup == unresolvedFirst && (el instanceof BreakElement)) { breakPoss = (BreakElement) el; iter.remove(); currentGroup = unresolvedSecond; } else if (el.isUnresolvedElement()) { currentGroup.add(el); iter.remove(); } else { last = false; break; } } //last = !iter.hasNext(); if (breakPoss == null && unresolvedSecond.isEmpty() && !last) { LOG.trace("Swap first and second parts in no-break condition," + " second part is empty."); //The first list is reversed, so swap if this shouldn't happen List swapList = unresolvedSecond; unresolvedSecond = unresolvedFirst; unresolvedFirst = swapList; } LOG.debug("----start space resolution (first=" + first + ", last=" + last + ")..."); SpaceResolver resolver = new SpaceResolver(unresolvedFirst, breakPoss, unresolvedSecond, first, last); if (!last) { iter.previous(); } resolver.generate(iter); if (!last && skipNextElement) { iter.next(); } LOG.debug("----end space resolution."); } first = false; } }
From source file:org.apache.http.impl.conn.tsccm.RouteSpecificPool.java
/** * Obtains a free entry from this pool, if one is available. * * @return an available pool entry, or <code>null</code> if there is none *//*from ww w . j av a 2 s. com*/ public BasicPoolEntry allocEntry(final Object state) { if (!freeEntries.isEmpty()) { final ListIterator<BasicPoolEntry> it = freeEntries.listIterator(freeEntries.size()); while (it.hasPrevious()) { final BasicPoolEntry entry = it.previous(); if (entry.getState() == null || LangUtils.equals(state, entry.getState())) { it.remove(); return entry; } } } if (getCapacity() == 0 && !freeEntries.isEmpty()) { final BasicPoolEntry entry = freeEntries.remove(); entry.shutdownEntry(); final OperatedClientConnection conn = entry.getConnection(); try { conn.close(); } catch (final IOException ex) { log.debug("I/O error closing connection", ex); } return entry; } return null; }
From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupDaoJena.java
public int removeUnpopulatedGroups(List<VClassGroup> groups) { if (groups == null || groups.size() == 0) return 0; int removedGroupsCount = 0; ListIterator<VClassGroup> it = groups.listIterator(); while (it.hasNext()) { VClassGroup group = it.next();/* www . j a v a 2 s . co m*/ List<VClass> classes = group.getVitroClassList(); if (classes == null || classes.size() < 1) { removedGroupsCount++; it.remove(); } } return removedGroupsCount; }
From source file:com.adobe.acs.commons.httpcache.config.impl.HttpCacheConfigImpl.java
@Activate protected void activate(Map<String, Object> configs) { // Request URIs - Whitelisted. requestUriPatterns = Arrays// w ww. java2 s. c o m .asList(PropertiesUtil.toStringArray(configs.get(PROP_REQUEST_URI_PATTERNS), new String[] {})); requestUriPatternsAsRegEx = compileToPatterns(requestUriPatterns); // Request URIs - Blacklisted. blacklistedRequestUriPatterns = Arrays.asList( PropertiesUtil.toStringArray(configs.get(PROP_BLACKLISTED_REQUEST_URI_PATTERNS), new String[] {})); blacklistedRequestUriPatternsAsRegEx = compileToPatterns(blacklistedRequestUriPatterns); // Authentication requirement. authenticationRequirement = PropertiesUtil.toString(configs.get(PROP_AUTHENTICATION_REQUIREMENT), DEFAULT_AUTHENTICATION_REQUIREMENT); // Cache store cacheStore = PropertiesUtil.toString(configs.get(PROP_CACHE_STORE), DEFAULT_CACHE_STORE); // Cache invalidation paths. cacheInvalidationPathPatterns = Arrays.asList( PropertiesUtil.toStringArray(configs.get(PROP_CACHE_INVALIDATION_PATH_PATTERNS), new String[] {})); cacheInvalidationPathPatternsAsRegEx = compileToPatterns(cacheInvalidationPathPatterns); order = PropertiesUtil.toInteger(configs.get(PROP_ORDER), DEFAULT_ORDER); filterScope = FilterScope.valueOf( PropertiesUtil.toString(configs.get(PROP_FILTER_SCOPE), DEFAULT_FILTER_SCOPE).toUpperCase()); // PIDs of cache handling rules. cacheHandlingRulesPid = new ArrayList<String>(Arrays .asList(PropertiesUtil.toStringArray(configs.get(PROP_CACHE_HANDLING_RULES_PID), new String[] {}))); ListIterator<String> listIterator = cacheHandlingRulesPid.listIterator(); while (listIterator.hasNext()) { String value = listIterator.next(); if (StringUtils.isBlank(value)) { listIterator.remove(); } } log.info("HttpCacheConfigImpl activated."); }
From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java
/** * Gets a set of boxes which covers all and only the pixels covered by * <code>A</code> and <code>B</code>. * /*from w ww .j a v a2 s . c o m*/ * @param A * a set of boxes to union with * @param B * a set of boxes to union with * @return a set of boxes corresponding to the region shared by A and B */ public static BoundingBox union(BoundingBox A, BoundingBox B) { BoundingBox temp = new BoundingBox(); LinkedList aList; temp.composed = true; int x = Math.min(A.rect.x, B.rect.x); int y = Math.min(A.rect.y, B.rect.y); int x2 = Math.max(A.rect.x + A.rect.width, B.rect.x + B.rect.width); int y2 = Math.max(A.rect.y + A.rect.height, B.rect.y + B.rect.height); temp.rect = new Rectangle(x, y, x2, y2); if (A.composed) aList = (LinkedList) A.pieces.clone(); else { aList = new LinkedList(); aList.add(A); } if (B.composed) temp = B.copy(); else { temp.pieces = new LinkedList(); temp.pieces.add(B.copy()); temp.composed = true; } ListIterator iter = aList.listIterator(0); while (iter.hasNext()) { BoundingBox child = (BoundingBox) iter.next(); Iterator ti = temp.pieces.iterator(); LinkedList childRemains = null; /* remove an offending piece of the child */ while (ti.hasNext() && (null == (childRemains = ((BoundingBox) ti.next()).subtractFrom(child)))) ; /* * Add the broken pieces into the list and break back to top loop * remove the offending rectangle and replace it with its shards, * then clean up those. */ if (childRemains != null) { ti = childRemains.iterator(); iter.remove(); while (ti.hasNext()) { iter.add(ti.next()); iter.previous(); } } } temp.pieces.addAll(aList); temp.simplify(); return (temp); }
From source file:org.broadleafcommerce.core.order.service.workflow.PriceOrderIfNecessaryActivity.java
@Override public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception { CartOperationRequest request = context.getSeedData(); Order order = request.getOrder();/*from w w w.j av a2 s . c o m*/ // If the UpdateOrderMultishipOptionActivity identified that we should delete order item multiship options, // go ahead and carry out that delete here. if (CollectionUtils.isNotEmpty(request.getMultishipOptionsToDelete())) { for (Long[] pack : request.getMultishipOptionsToDelete()) { if (pack[1] == null) { orderMultishipOptionService.deleteOrderItemOrderMultishipOptions(pack[0]); } else { orderMultishipOptionService.deleteOrderItemOrderMultishipOptions(pack[0], pack[1].intValue()); } } } // We potentially have some FulfillmentGroupItems that were identified in the FulfillmentGroupItemStrategy as // ones that should be deleted. Delete them here. if (CollectionUtils.isNotEmpty(request.getFgisToDelete())) { for (FulfillmentGroupItem fgi : request.getFgisToDelete()) { for (FulfillmentGroup fg : order.getFulfillmentGroups()) { ListIterator<FulfillmentGroupItem> fgItemIter = fg.getFulfillmentGroupItems().listIterator(); while (fgItemIter.hasNext()) { FulfillmentGroupItem fgi2 = fgItemIter.next(); if (fgi2 == fgi) { fgItemIter.remove(); fgItemDao.delete(fgi2); } } } } } // We now need to delete any OrderItems that were marked as such, including their children, if any for (OrderItem oi : request.getOisToDelete()) { order.getOrderItems().remove(oi); orderItemService.delete(oi); if (oi.getParentOrderItem() != null) { OrderItem parentItem = oi.getParentOrderItem(); parentItem.getChildOrderItems().remove(oi); } } // We need to build up a map of OrderItem to which FulfillmentGroupItems reference that particular OrderItem. // We'll also save the order item and build up a map of the unsaved items to their saved counterparts. Map<OrderItem, List<FulfillmentGroupItem>> oiFgiMap = new HashMap<OrderItem, List<FulfillmentGroupItem>>(); Map<OrderItem, OrderItem> savedOrderItems = new HashMap<OrderItem, OrderItem>(); for (OrderItem oi : order.getOrderItems()) { if (oi instanceof BundleOrderItem) { // We first need to save the discrete order items that are part of this bundle. Once they're saved, we'll // mark them and remove them from this bundle. List<DiscreteOrderItem> doisToAdd = new ArrayList<DiscreteOrderItem>(); ListIterator<DiscreteOrderItem> li = ((BundleOrderItem) oi).getDiscreteOrderItems().listIterator(); while (li.hasNext()) { DiscreteOrderItem doi = li.next(); getOiFgiMap(order, oiFgiMap, doi); DiscreteOrderItem savedDoi = (DiscreteOrderItem) orderItemService.saveOrderItem(doi); savedOrderItems.put(doi, savedDoi); li.remove(); doisToAdd.add(savedDoi); } // After the discrete order items are saved, we can re-add the saved versions to our bundle and then // save the bundle as well. ((BundleOrderItem) oi).getDiscreteOrderItems().addAll(doisToAdd); BundleOrderItem savedBoi = (BundleOrderItem) orderItemService.saveOrderItem(oi); savedOrderItems.put(oi, savedBoi); // Lastly, we'll want to go through our saved discrete order items and update the bundle that they relate // to to the saved version of the bundle. for (DiscreteOrderItem doi : savedBoi.getDiscreteOrderItems()) { doi.setBundleOrderItem(savedBoi); } } else { getOiFgiMap(order, oiFgiMap, oi); savedOrderItems.put(oi, orderItemService.saveOrderItem(oi)); } } // Now, we'll update the orderitems in the order to their saved counterparts ListIterator<OrderItem> li = order.getOrderItems().listIterator(); List<OrderItem> oisToAdd = new ArrayList<OrderItem>(); while (li.hasNext()) { OrderItem oi = li.next(); OrderItem savedOi = savedOrderItems.get(oi); oisToAdd.add(savedOi); li.remove(); } order.getOrderItems().addAll(oisToAdd); for (Entry<OrderItem, List<FulfillmentGroupItem>> entry : oiFgiMap.entrySet()) { // Update any FulfillmentGroupItems that reference order items for (FulfillmentGroupItem fgi : entry.getValue()) { fgi.setOrderItem(savedOrderItems.get(entry.getKey())); } // We also need to update the orderItem on the request in case it's used by the caller of this workflow if (entry.getKey() == request.getOrderItem()) { request.setOrderItem(savedOrderItems.get(entry.getKey())); } } // We need to add the new item to the parent's child order items as well. for (OrderItem oi : order.getOrderItems()) { if (oi.getId().equals(request.getItemRequest().getParentOrderItemId())) { oi.getChildOrderItems().add(request.getOrderItem()); } } // If a custom implementation needs to handle additional saves before the parent Order is saved, this method // can be overridden to provide that functionality. preSaveOperation(request); // Now that our collection items in our Order have been saved and the state of our Order is in a place where we // won't get a transient save exception, we are able to go ahead and save the order with optional pricing. order = orderService.save(order, request.isPriceOrder()); request.setOrder(order); return context; }
From source file:org.sonar.dotnet.tools.commons.visualstudio.VisualStudioSolution.java
/** * Remove some projects/*from ww w . jav a2s. c o m*/ * * @param skippedProjects * List of the excluded projects, using ',' as delimiter */ public void filterProjects(String skippedProjects) { if (StringUtils.isEmpty(skippedProjects)) { return; } Set<String> skippedProjectSet = new HashSet<String>(); skippedProjectSet.addAll(Arrays.asList(StringUtils.split(skippedProjects, ','))); ListIterator<VisualStudioProject> projectIterator = projects.listIterator(); while (projectIterator.hasNext()) { VisualStudioProject visualStudioProject = projectIterator.next(); if (skippedProjectSet.contains(visualStudioProject.getName())) { projectIterator.remove(); } } }
From source file:com.danga.camli.UploadThread.java
private void filterOutBlobRef(String blobRef) { // TODO: kinda lame, iterating over whole list. ListIterator<QueuedFile> iter = mQueue.listIterator(); while (iter.hasNext()) { QueuedFile qf = iter.next();//ww w .j a v a 2s .co m if (qf.getContentName().equals(blobRef)) { iter.remove(); mService.onUploadComplete(qf, false /* not uploaded */); } } }