/// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception> public bool Process(TextDocument doc) { IList <TextBlock> textBlocks = doc.GetTextBlocks(); if (textBlocks.Count < 2) { return(false); } bool changes = false; TextBlock prevBlock = textBlocks[0]; int offset = 1; for (ListIterator <TextBlock> it = textBlocks.ListIterator(offset); it.HasNext();) { TextBlock block = it.Next(); if (EqualLabels(prevBlock.GetLabels(), block.GetLabels())) { prevBlock.MergeNext(block); it.Remove(); changes = true; } else { prevBlock = block; } } return(changes); }
/// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception> public virtual bool Process(TextDocument doc) { IList <TextBlock> textBlocks = doc.GetTextBlocks(); bool changes = false; if (textBlocks.Count < 2) { return(false); } TextBlock b1 = textBlocks[0]; for (ListIterator <TextBlock> it = textBlocks.ListIterator(1); it.HasNext();) { TextBlock b2 = it.Next(); bool similar = (b1.GetTextDensity() == b2.GetTextDensity()); if (similar) { b1.MergeNext(b2); it.Remove(); changes = true; } else { b1 = b2; } } return(changes); }
/// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception> public bool Process(TextDocument doc) { IList <TextBlock> textBlocks = doc.GetTextBlocks(); if (textBlocks.Count < 2) { return(false); } TextBlock prevBlock = textBlocks[0]; bool changes = false; do { changes = false; for (ListIterator <TextBlock> it = textBlocks.ListIterator(1); it.HasNext();) { TextBlock block = it.Next(); if (prevBlock.IsContent() && block.GetLinkDensity() < 0.56 && !block.HasLabel(DefaultLabels .STRICTLY_NOT_CONTENT)) { prevBlock.MergeNext(block); it.Remove(); changes = true; } else { prevBlock = block; } } }while (changes); return(true); }
/// <summary>Try to remove extraneous items from the set of sampled items.</summary> /// <remarks> /// Try to remove extraneous items from the set of sampled items. This checks /// if an item is unnecessary based on the desired error bounds, and merges it /// with the adjacent item if it is. /// </remarks> private void Compress() { if (samples.Count < 2) { return; } ListIterator <SampleQuantiles.SampleItem> it = samples.ListIterator(); SampleQuantiles.SampleItem prev = null; SampleQuantiles.SampleItem next = it.Next(); while (it.HasNext()) { prev = next; next = it.Next(); if (prev.g + next.g + next.delta <= AllowableError(it.PreviousIndex())) { next.g += prev.g; // Remove prev. it.remove() kills the last thing returned. it.Previous(); it.Previous(); it.Remove(); // it.next() is now equal to next, skip it back forward again it.Next(); } } }
/// <summary> /// Removes from this list all of the elements whose index is between /// {@code fromIndex}, inclusive, and {@code toIndex}, exclusive. /// Shifts any succeeding elements to the left (reduces their index). /// This call shortens the list by {@code (toIndex - fromIndex)} elements. /// (If {@code toIndex==fromIndex}, this operation has no effect.) /// /// <para>This method is called by the {@code clear} operation on this list /// and its subLists. Overriding this method to take advantage of /// the internals of the list implementation can <i>substantially</i> /// improve the performance of the {@code clear} operation on this list /// and its subLists. /// /// </para> /// <para>This implementation gets a list iterator positioned before /// {@code fromIndex}, and repeatedly calls {@code ListIterator.next} /// followed by {@code ListIterator.remove} until the entire range has /// been removed. <b>Note: if {@code ListIterator.remove} requires linear /// time, this implementation requires quadratic time.</b> /// /// </para> /// </summary> /// <param name="fromIndex"> index of first element to be removed </param> /// <param name="toIndex"> index after last element to be removed </param> protected internal virtual void RemoveRange(int fromIndex, int toIndex) { ListIterator <E> it = ListIterator(fromIndex); for (int List_Fields.i = 0, n = toIndex - fromIndex; List_Fields.i < n; List_Fields.i++) { it.Next(); it.Remove(); } }
public void RemoveInIteratorTest() { ExtendedOneWayLinkedListWithHead <int> lista = new ExtendedOneWayLinkedListWithHead <int>(); lista.Add(1); lista.Add(2); lista.Add(3); List <int> actual = new List <int>(); ListIterator <int> iterator = lista.GetListIterator(); Assert.ThrowsException <System.IndexOutOfRangeException>(() => iterator.Remove()); while (iterator.HasNext()) { iterator.Next(); iterator.Remove(); Assert.ThrowsException <System.IndexOutOfRangeException>(() => iterator.Remove()); } Assert.ThrowsException <System.IndexOutOfRangeException>(() => iterator.Next()); Assert.AreEqual(0, actual.Count); }
/// <summary> /// Removes the element at the specified position in this list (optional /// operation). Shifts any subsequent elements to the left (subtracts one /// from their indices). Returns the element that was removed from the /// list. /// /// <para>This implementation first gets a list iterator pointing to the /// indexed element (with <tt>listIterator(index)</tt>). Then, it removes /// the element with <tt>ListIterator.remove</tt>. /// /// </para> /// <para>Note that this implementation will throw an /// <tt>UnsupportedOperationException</tt> if the list iterator does not /// implement the <tt>remove</tt> operation. /// /// </para> /// </summary> /// <exception cref="UnsupportedOperationException"> {@inheritDoc} </exception> /// <exception cref="IndexOutOfBoundsException"> {@inheritDoc} </exception> public virtual E Remove(int index) { try { ListIterator <E> e = ListIterator(index); E outCast = e.Next(); e.Remove(); return(outCast); } catch (NoSuchElementException) { throw new IndexOutOfBoundsException("Index: " + index); } }
internal virtual void Normalize() { for (ListIterator <ComparableVersion.Item> iterator = ListIterator(Count); iterator .HasPrevious();) { ComparableVersion.Item item = iterator.Previous(); if (item.IsNull()) { iterator.Remove(); } else { // remove null trailing items: 0, "", empty list break; } } }
internal static IList <XAttr> FilterINodeXAttrs(IList <XAttr> existingXAttrs, IList <XAttr> toFilter, IList <XAttr> filtered) { if (existingXAttrs == null || existingXAttrs.IsEmpty() || toFilter == null || toFilter .IsEmpty()) { return(existingXAttrs); } // Populate a new list with XAttrs that pass the filter IList <XAttr> newXAttrs = Lists.NewArrayListWithCapacity(existingXAttrs.Count); foreach (XAttr a in existingXAttrs) { bool add = true; for (ListIterator <XAttr> it = toFilter.ListIterator(); it.HasNext();) { XAttr filter = it.Next(); Preconditions.CheckArgument(!KeyidXattr.EqualsIgnoreValue(filter), "The encryption zone xattr should never be deleted." ); if (UnreadableBySuperuserXattr.EqualsIgnoreValue(filter)) { throw new AccessControlException("The xattr '" + HdfsServerConstants.SecurityXattrUnreadableBySuperuser + "' can not be deleted."); } if (a.EqualsIgnoreValue(filter)) { add = false; it.Remove(); filtered.AddItem(filter); break; } } if (add) { newXAttrs.AddItem(a); } } return(newXAttrs); }
/// <summary> /// Generates a list of numbers from a string. /// </summary> /// <param name="ranges">the comma separated ranges</param> /// <param name="maxNumber">the maximum number in the range</param> /// <returns>a list with the numbers as Integer </returns> public static ArrayList Expand(string ranges, int maxNumber) { SequenceList parse = new SequenceList(ranges); ArrayList list = new ArrayList(); bool sair = false; while (!sair) { sair = parse.GetAttributes(); if (parse.Low == -1 && parse.High == -1 && !parse.Even && !parse.Odd) { continue; } if (parse.Low < 1) { parse.Low = 1; } if (parse.High < 1 || parse.High > maxNumber) { parse.High = maxNumber; } if (parse.Low > maxNumber) { parse.Low = maxNumber; } //System.out.Println("low="+parse.low+",high="+parse.high+",odd="+parse.odd+",even="+parse.even+",inverse="+parse.inverse); int inc = 1; if (parse.Inverse) { if (parse.Low > parse.High) { int t = parse.Low; parse.Low = parse.High; parse.High = t; } for (ListIterator it = new ListIterator(list); it.HasNext();) { int n = (int)it.Next(); if (parse.Even && (n & 1) == 1) { continue; } if (parse.Odd && (n & 1) == 0) { continue; } if (n >= parse.Low && n <= parse.High) { it.Remove(); } } } else { if (parse.Low > parse.High) { inc = -1; if (parse.Odd || parse.Even) { --inc; if (parse.Even) { parse.Low &= ~1; } else { parse.Low -= ((parse.Low & 1) == 1 ? 0 : 1); } } for (int k = parse.Low; k >= parse.High; k += inc) { list.Add(k); } } else { if (parse.Odd || parse.Even) { ++inc; if (parse.Odd) { parse.Low |= 1; } else { parse.Low += ((parse.Low & 1) == 1 ? 1 : 0); } } for (int k = parse.Low; k <= parse.High; k += inc) { list.Add(k); } } } } return(list); }
/** * Removes the bookmark entries for a number of page ranges. The page ranges * consists of a number of pairs with the start/end page range. The page numbers * are inclusive. * @param list the bookmarks * @param pageRange the page ranges, always in pairs. */ public static void EliminatePages(ArrayList list, int[] pageRange) { if (list == null) { return; } for (ListIterator it = new ListIterator(list); it.HasNext();) { Hashtable map = (Hashtable)it.Next(); bool hit = false; if ("GoTo".Equals(map["Action"])) { String page = (String)map["Page"]; if (page != null) { page = page.Trim(); int idx = page.IndexOf(' '); int pageNum; if (idx < 0) { pageNum = int.Parse(page); } else { pageNum = int.Parse(page.Substring(0, idx)); } int len = pageRange.Length & 0x7ffffffe; for (int k = 0; k < len; k += 2) { if (pageNum >= pageRange[k] && pageNum <= pageRange[k + 1]) { hit = true; break; } } } } ArrayList kids = (ArrayList)map["Kids"]; if (kids != null) { EliminatePages(kids, pageRange); if (kids.Count == 0) { map.Remove("Kids"); kids = null; } } if (hit) { if (kids == null) { it.Remove(); } else { map.Remove("Action"); map.Remove("Page"); map.Remove("Named"); } } } }
/** * Removes the bookmark entries for a number of page ranges. The page ranges * consists of a number of pairs with the start/end page range. The page numbers * are inclusive. * @param list the bookmarks * @param pageRange the page ranges, always in pairs. */ public static void EliminatePages(IList <Dictionary <String, Object> > list, int[] pageRange) { if (list == null) { return; } for (ListIterator <Dictionary <String, Object> > it = new ListIterator <Dictionary <string, object> >(list); it.HasNext();) { Dictionary <String, Object> map = it.Next(); bool hit = false; if (map.ContainsKey("Action") && "GoTo".Equals(map["Action"])) { String page = null; if (map.ContainsKey("Page")) { page = (String)map["Page"]; } if (page != null) { page = page.Trim(); int idx = page.IndexOf(' '); int pageNum; if (idx < 0) { pageNum = int.Parse(page); } else { pageNum = int.Parse(page.Substring(0, idx)); } int len = pageRange.Length & 0x7ffffffe; for (int k = 0; k < len; k += 2) { if (pageNum >= pageRange[k] && pageNum <= pageRange[k + 1]) { hit = true; break; } } } } IList <Dictionary <String, Object> > kids = null; if (map.ContainsKey("Kids")) { kids = (IList <Dictionary <String, Object> >)map["Kids"]; } if (kids != null) { EliminatePages(kids, pageRange); if (kids.Count == 0) { map.Remove("Kids"); kids = null; } } if (hit) { if (kids == null) { it.Remove(); } else { map.Remove("Action"); map.Remove("Page"); map.Remove("Named"); } } } }
public void Remove() { iterator.Remove(); subList.SizeChanged(false); end--; }
/// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception> public bool Process(TextDocument doc) { IList <TextBlock> textBlocks = doc.GetTextBlocks(); if (textBlocks.Count < 2) { return(false); } bool changes = false; TextBlock prevBlock; int offset; if (contentOnly) { prevBlock = null; offset = 0; foreach (TextBlock tb in textBlocks) { offset++; if (tb.IsContent()) { prevBlock = tb; break; } } if (prevBlock == null) { return(false); } } else { prevBlock = textBlocks[0]; offset = 1; } for (ListIterator <TextBlock> it = textBlocks.ListIterator <TextBlock>(offset); it.HasNext();) { TextBlock block = it.Next(); if (!block.IsContent()) { prevBlock = block; continue; } int diffBlocks = block.GetOffsetBlocksStart() - prevBlock.GetOffsetBlocksEnd() - 1; if (diffBlocks <= maxBlocksDistance) { bool ok = true; if (contentOnly) { if (!prevBlock.IsContent() || !block.IsContent()) { ok = false; } } if (ok && sameTagLevelOnly && prevBlock.GetTagLevel() != block.GetTagLevel()) { ok = false; } if (ok) { prevBlock.MergeNext(block); it.Remove(); changes = true; } else { prevBlock = block; } } else { prevBlock = block; } } return(changes); }