Exemplo n.º 1
0
        public virtual void JavaCollectionsUtilTest()
        {
            IList <int> emptyList = JavaCollectionsUtil.EmptyList <int>();

            Assert.IsEmpty(emptyList);
            Assert.Throws <NotSupportedException>(() => emptyList.Add(10));

            IDictionary <int, int> emptyMap = JavaCollectionsUtil.EmptyMap <int, int>();

            Assert.IsEmpty(emptyMap);
            Assert.Throws <NotSupportedException>(() => { emptyMap[5] = 10; });

            IEnumerator <int> emptyIterator = JavaCollectionsUtil.EmptyIterator <int>();

            Assert.False(emptyIterator.MoveNext());

            IList <int> unmodifiableList = JavaCollectionsUtil.UnmodifiableList <int>(new int[] { 10, 20, 30, 20 }.ToList());

            Assert.Throws <NotSupportedException>(() => unmodifiableList.Insert(0, 20));
            Assert.Throws <NotSupportedException>(() => { unmodifiableList[2] = 50; });
            int test = unmodifiableList[3];

            Assert.Throws <NotSupportedException>(() => JavaCollectionsUtil.Sort(unmodifiableList));

            IDictionary <int, int> unodifiableMap = JavaCollectionsUtil.UnmodifiableMap(new Dictionary <int, int>()
            {
                { 1, 20 },
                { 2, 40 },
                { 70, 80 },
            });

            test = unodifiableMap[2];
            Assert.Throws <KeyNotFoundException>(() => { int temp = unodifiableMap[3]; });
            Assert.Throws <NotSupportedException>(() => { unodifiableMap[11] = 11; });

            IList <int> singletonList = JavaCollectionsUtil.SingletonList(4);

            Assert.AreEqual(4, singletonList[0]);
            Assert.Throws <NotSupportedException>(() => singletonList.Add(9));

            List <int> x = new int[] { 60, 50, 20 }.ToList();

            JavaCollectionsUtil.Sort(x);
            Assert.AreEqual(20, x[0]);
            Assert.AreEqual(60, x[2]);

            x = new int[] { -1, 0, 1 }.ToList();
            JavaCollectionsUtil.Reverse(x);
            Assert.AreEqual(1, x[0]);
            Assert.AreEqual(0, x[1]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders all the rows to a
        /// <see cref="iText.Layout.Element.Table"/>
        /// object.
        /// </summary>
        /// <param name="colgroupsHelper">the colgroups helper class</param>
        /// <returns>the table</returns>
        public virtual Table ToTable(WaitingColgroupsHelper colgroupsHelper)
        {
            Table table;

            if (numberOfColumns > 0)
            {
                table = new Table(GetColWidths(colgroupsHelper));
            }
            else
            {
                // if table is empty, create empty table with single column
                table = new Table(1);
            }
            AccessiblePropHelper.TrySetLangAttribute(table, lang);
            if (headerRows != null)
            {
                for (int i = 0; i < headerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(headerRows[i]);
                    }
                    for (int j = 0; j < headerRows[i].Count; j++)
                    {
                        Cell       cell       = headerRows[i][j].cell;
                        ColWrapper colWrapper = colgroupsHelper.GetColWrapper(j);
                        if (colWrapper != null)
                        {
                            if (headerLang == null && cell.GetAccessibilityProperties().GetLanguage() == null)
                            {
                                if (colWrapper.GetLang() != null)
                                {
                                    cell.GetAccessibilityProperties().SetLanguage(colWrapper.GetLang());
                                }
                            }
                        }
                        table.AddHeaderCell(cell);
                    }
                    if (i != headerRows.Count - 1)
                    {
                        table.GetHeader().StartNewRow();
                    }
                }
                AccessiblePropHelper.TrySetLangAttribute(table.GetHeader(), headerLang);
            }
            if (footerRows != null)
            {
                for (int i = 0; i < footerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(footerRows[i]);
                    }
                    for (int j = 0; j < footerRows[i].Count; j++)
                    {
                        Cell       cell       = footerRows[i][j].cell;
                        ColWrapper colWrapper = colgroupsHelper.GetColWrapper(j);
                        if (colWrapper != null)
                        {
                            if (footerLang == null && cell.GetAccessibilityProperties().GetLanguage() == null)
                            {
                                if (colWrapper.GetLang() != null)
                                {
                                    cell.GetAccessibilityProperties().SetLanguage(colWrapper.GetLang());
                                }
                            }
                        }
                        table.AddFooterCell(cell);
                    }
                    if (i != footerRows.Count - 1)
                    {
                        table.GetFooter().StartNewRow();
                    }
                }
                AccessiblePropHelper.TrySetLangAttribute(table.GetFooter(), footerLang);
            }
            if (rows != null)
            {
                for (int i = 0; i < rows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(rows[i]);
                    }
                    for (int j = 0; j < rows[i].Count; j++)
                    {
                        table.AddCell(rows[i][j].cell);
                    }
                    if (i != rows.Count - 1)
                    {
                        table.StartNewRow();
                    }
                }
            }
            if (caption != null)
            {
                table.SetCaption(caption);
            }
            return(table);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Renders all the rows to a
        /// <see cref="iText.Layout.Element.Table"/>
        /// object.
        /// </summary>
        /// <param name="colgroupsHelper">the colgroups helper class</param>
        /// <returns>the table</returns>
        public virtual Table ToTable(WaitingColgroupsHelper colgroupsHelper)
        {
            Table table;

            if (numberOfColumns > 0)
            {
                table = new Table(GetColWidths(colgroupsHelper));
            }
            else
            {
                // if table is empty, create empty table with single column
                table = new Table(1);
            }
            if (headerRows != null)
            {
                for (int i = 0; i < headerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(headerRows[i]);
                    }
                    for (int j = 0; j < headerRows[i].Count; j++)
                    {
                        table.AddHeaderCell(headerRows[i][j].cell);
                    }
                    if (i != headerRows.Count - 1)
                    {
                        table.GetHeader().StartNewRow();
                    }
                }
            }
            if (footerRows != null)
            {
                for (int i = 0; i < footerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(footerRows[i]);
                    }
                    for (int j = 0; j < footerRows[i].Count; j++)
                    {
                        table.AddFooterCell(footerRows[i][j].cell);
                    }
                    if (i != footerRows.Count - 1)
                    {
                        table.GetFooter().StartNewRow();
                    }
                }
            }
            if (rows != null)
            {
                for (int i = 0; i < rows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(rows[i]);
                    }
                    for (int j = 0; j < rows[i].Count; j++)
                    {
                        table.AddCell(rows[i][j].cell);
                    }
                    if (i != rows.Count - 1)
                    {
                        table.StartNewRow();
                    }
                }
            }
            if (caption != null)
            {
                table.SetCaption(caption);
            }
            return(table);
        }