public virtual void RangePartAndEqualsNullTest() { PageRange.IPageRangePart odd = PageRange.PageRangePartOddEven.ODD; PageRange.IPageRangePart seq = new PageRange.PageRangePartSequence(2, 14); PageRange.PageRangePartAnd pageRangePartAnd = new PageRange.PageRangePartAnd(odd, seq); NUnit.Framework.Assert.IsFalse(pageRangePartAnd.Equals(null)); }
public virtual void IsRangePartAndInRangeFalseTest() { PageRange.IPageRangePart odd = PageRange.PageRangePartOddEven.ODD; PageRange.IPageRangePart seq = new PageRange.PageRangePartSequence(2, 14); PageRange.PageRangePartAnd pageRangePartAnd = new PageRange.PageRangePartAnd(odd, seq); NUnit.Framework.Assert.IsFalse(pageRangePartAnd.IsPageInRange(1)); }
public virtual void AddCustomAnd() { PageRange range = new PageRange(); PageRange.IPageRangePart odd = PageRange.PageRangePartOddEven.ODD; PageRange.IPageRangePart seq = new PageRange.PageRangePartSequence(2, 14); PageRange.IPageRangePart and = new PageRange.PageRangePartAnd(odd, seq); range.AddPageRangePart(and); NUnit.Framework.Assert.AreEqual(range.GetQualifyingPageNums(15), JavaUtil.ArraysAsList(3, 5, 7, 9, 11, 13) ); }
public virtual void RangePartAndNotEqualsAndHashCodeTest() { PageRange.IPageRangePart odd = PageRange.PageRangePartOddEven.ODD; PageRange.IPageRangePart seq = new PageRange.PageRangePartSequence(2, 14); PageRange.PageRangePartAnd pageRangePartAnd = new PageRange.PageRangePartAnd(odd, seq); PageRange.PageRangePartAnd pageRangePartAnd2 = new PageRange.PageRangePartAnd(); bool result = pageRangePartAnd.Equals(pageRangePartAnd2); NUnit.Framework.Assert.IsFalse(result); NUnit.Framework.Assert.AreNotEqual(pageRangePartAnd.GetHashCode(), pageRangePartAnd2.GetHashCode()); }
/// <summary> /// Constructs a /// <see cref="PageRange"/> /// instance from a range in a string form, /// for example: "1-12, 15, 45-66". More advanced forms are also available, /// for example: /// - "3-" to indicate from page 3 to the last page /// - "odd" for all odd pages /// - "even" for all even pages /// - "3- & odd" for all odd pages starting from page 3 /// A complete example for pages 1 to 5, page 8 then odd pages starting from /// page 9: "1-5, 8, odd & 9-". /// </summary> /// <param name="pageRange">a String of page ranges</param> public PageRange(String pageRange) { pageRange = iText.IO.Util.StringUtil.ReplaceAll(pageRange, "\\s+", ""); foreach (String pageRangePart in iText.IO.Util.StringUtil.Split(pageRange, ",")) { PageRange.IPageRangePart cond = GetRangeObject(pageRangePart); if (cond != null) { sequences.Add(cond); } } }
private static PageRange.IPageRangePart GetRangeObject(String rangeDef) { if (rangeDef.Contains("&")) { IList <PageRange.IPageRangePart> conditions = new List <PageRange.IPageRangePart>(); foreach (String pageRangeCond in iText.IO.Util.StringUtil.Split(rangeDef, "&")) { PageRange.IPageRangePart cond = GetRangeObject(pageRangeCond); if (cond != null) { conditions.Add(cond); } } if (conditions.Count > 0) { return(new PageRange.PageRangePartAnd(conditions.ToArray(new PageRange.IPageRangePart[] { }))); } else { return(null); } } else { Match matcher; if ((matcher = iText.IO.Util.StringUtil.Match(SEQUENCE_PATTERN, rangeDef)).Success) { int start = System.Convert.ToInt32(iText.IO.Util.StringUtil.Group(matcher, 1)); if (iText.IO.Util.StringUtil.Group(matcher, 2) != null) { return(new PageRange.PageRangePartSequence(start, System.Convert.ToInt32(iText.IO.Util.StringUtil.Group(matcher , 2)))); } else { return(new PageRange.PageRangePartAfter(start)); } } else { if ((matcher = iText.IO.Util.StringUtil.Match(SINGLE_PAGE_PATTERN, rangeDef)).Success) { return(new PageRange.PageRangePartSingle(System.Convert.ToInt32(iText.IO.Util.StringUtil.Group(matcher, 1) ))); } else { if ("odd".EqualsIgnoreCase(rangeDef)) { return(PageRange.PageRangePartOddEven.ODD); } else { if ("even".EqualsIgnoreCase(rangeDef)) { return(PageRange.PageRangePartOddEven.EVEN); } } } } return(null); } }
/// <summary>Adds any page range part to this page range.</summary> /// <remarks> /// Adds any page range part to this page range. Users may define and plug in /// custom implementations for behavior not found in the standard library. /// </remarks> /// <param name="part"> /// a custom implementation of /// <see cref="IPageRangePart"/> /// </param> /// <returns>this range, already modified</returns> public virtual iText.Kernel.Utils.PageRange AddPageRangePart(PageRange.IPageRangePart part) { sequences.Add(part); return(this); }