Example #1
0
        // Comparison and hashing

        /// <summary>
        /// Compares the specified object with this list for equality.  Returns
        /// {@code true} if and only if the specified object is also a list, both
        /// lists have the same size, and all corresponding pairs of elements in
        /// the two lists are <i>equal</i>.  (Two elements {@code e1} and
        /// {@code e2} are <i>equal</i> if {@code (e1==null ? e2==null :
        /// e1.equals(e2))}.)  In other words, two lists are defined to be
        /// equal if they contain the same elements in the same order.<para>
        ///
        /// This implementation first checks if the specified object is this
        /// list. If so, it returns {@code true}; if not, it checks if the
        /// specified object is a list. If not, it returns {@code false}; if so,
        /// it iterates over both lists, comparing corresponding pairs of elements.
        /// If any comparison returns {@code false}, this method returns
        /// {@code false}.  If either iterator runs out of elements before the
        /// other it returns {@code false} (as the lists are of unequal length);
        /// otherwise it returns {@code true} when the iterations complete.
        ///
        /// </para>
        /// </summary>
        /// <param name="o"> the object to be compared for equality with this list </param>
        /// <returns> {@code true} if the specified object is equal to this list </returns>
        public override bool Equals(Object o)
        {
            if (o == this)
            {
                return(true);
            }
            if (!(o is List))
            {
                return(false);
            }

            ListIterator <E> e1 = ListIterator();
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: ListIterator<?> e2 = ((List<?>) o).listIterator();
            ListIterator <?> e2 = ((List <?>)o).ListIterator();

            while (e1.HasNext() && e2.HasNext())
            {
                E      o1 = e1.Next();
                Object o2 = e2.Next();
                if (!(o1 == null ? o2 == null : o1.Equals(o2)))
                {
                    return(false);
                }
            }
            return(!(e1.HasNext() || e2.HasNext()));
        }
Example #2
0
        // Search Operations

        /// <summary>
        /// {@inheritDoc}
        ///
        /// <para>This implementation first gets a list iterator (with
        /// {@code listIterator()}).  Then, it iterates over the list until the
        /// specified element is found or the end of the list is reached.
        ///
        /// </para>
        /// </summary>
        /// <exception cref="ClassCastException">   {@inheritDoc} </exception>
        /// <exception cref="NullPointerException"> {@inheritDoc} </exception>
        public virtual int IndexOf(Object o)
        {
            ListIterator <E> it = ListIterator();

            if (o == null)
            {
                while (it.HasNext())
                {
                    if (it.Next() == null)
                    {
                        return(it.PreviousIndex());
                    }
                }
            }
            else
            {
                while (it.HasNext())
                {
                    if (o.Equals(it.Next()))
                    {
                        return(it.PreviousIndex());
                    }
                }
            }
            return(-1);
        }
Example #3
0
        /// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception>
        public virtual bool Process(TextDocument doc)
        {
            IList <TextBlock> textBlocks = doc.GetTextBlocks();
            bool hasChanges             = false;
            ListIterator <TextBlock> it = textBlocks.ListIterator(0);

            if (!it.HasNext())
            {
                return(false);
            }
            TextBlock prevBlock    = TextBlock.EMPTY_START;
            TextBlock currentBlock = it.Next();
            TextBlock nextBlock    = it.HasNext() ? it.Next() : TextBlock.EMPTY_START;

            hasChanges = Classify(prevBlock, currentBlock, nextBlock) | hasChanges;
            if (nextBlock != TextBlock.EMPTY_START)
            {
                while (it.HasNext())
                {
                    prevBlock    = currentBlock;
                    currentBlock = nextBlock;
                    nextBlock    = it.Next();
                    hasChanges   = Classify(prevBlock, currentBlock, nextBlock) | hasChanges;
                }
                prevBlock    = currentBlock;
                currentBlock = nextBlock;
                nextBlock    = TextBlock.EMPTY_START;
                hasChanges   = Classify(prevBlock, currentBlock, nextBlock) | hasChanges;
            }
            return(hasChanges);
        }
        /// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception>
        public virtual bool Process(TextDocument doc)
        {
            IList <TextBlock> tbs = doc.GetTextBlocks();

            if (tbs.Count < 3)
            {
                return(false);
            }
            TextBlock a = tbs[0];
            TextBlock b = tbs[1];
            TextBlock c;
            bool      hasChanges = false;

            for (ListIterator <TextBlock> it = tbs.ListIterator(2); it.HasNext();)
            {
                c = it.Next();
                if (!b.IsContent() && a.IsContent() && c.IsContent() && cond.MeetsCondition(b))
                {
                    b.SetIsContent(true);
                    hasChanges = true;
                }
                a = c;
                if (!it.HasNext())
                {
                    break;
                }
                b = it.Next();
            }
            return(hasChanges);
        }
 public void HasNextReturnFalseIfThereIsNoNextIndex()
 {
     for (int i = 0; i < collection.Count; i++)
     {
         list.Move();
     }
     Assert.IsFalse(list.HasNext());
 }
Example #6
0
        public void TestHasNextMethod()
        {
            ListIterator listIterator = new ListIterator(new string[] { "a", "b", "c" });

            FieldInfo fieldInfo = GetIndexFieldInfo();

            fieldInfo.SetValue(listIterator, 1);
            Assert.That(() => listIterator.HasNext(), Is.EqualTo(true));
            fieldInfo.SetValue(listIterator, 2);
            Assert.That(() => listIterator.HasNext(), Is.EqualTo(false));
        }
Example #7
0
            /// <summary>Parse a list of comma-separated nodes.</summary>
            /// <exception cref="System.IO.IOException"/>
            internal override void Parse(IList <Parser.Token> args, JobConf job)
            {
                ListIterator <Parser.Token> i = args.ListIterator();

                while (i.HasNext())
                {
                    Parser.Token t = i.Next();
                    t.GetNode().SetID(i.PreviousIndex() >> 1);
                    kids.AddItem(t.GetNode());
                    if (i.HasNext() && !Parser.TType.Comma.Equals(i.Next().GetType()))
                    {
                        throw new IOException("Expected ','");
                    }
                }
            }
Example #8
0
        /// <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();
                }
            }
        }
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split();

        ListIterator collectons = new ListIterator(input.Skip(1));
        string       commands;

        while ((commands = Console.ReadLine()) != "END")
        {
            try
            {
                switch (commands)
                {
                case "Move":
                    Console.WriteLine(collectons.Move());
                    break;

                case "HasNext":
                    Console.WriteLine(collectons.HasNext());
                    break;

                case "Print":
                    Console.WriteLine(collectons.Print());
                    break;
                }
            }
            catch (ArgumentNullException e)
            {
            }
        }
    }
Example #10
0
        /// <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);
        }
Example #11
0
        public void SetInIteratorTest()
        {
            ExtendedOneWayLinkedListWithHead <int> lista = new ExtendedOneWayLinkedListWithHead <int>();

            lista.Add(1);
            lista.Add(2);
            lista.Add(3);
            ListIterator <int> iterator = lista.GetListIterator();

            Assert.ThrowsException <System.IndexOutOfRangeException>(() => iterator.Set(8));
            while (iterator.HasNext())
            {
                iterator.Next();
                iterator.Set(8);
            }

            List <int> lista2 = new List <int> {
                8, 8, 8
            };

            Assert.AreEqual(lista2.Count, lista.Count);
            IEnumerator <int> iterator1 = lista.GetEnumerator();
            IEnumerator <int> iterator2 = lista2.GetEnumerator();

            while (iterator1.MoveNext() && iterator2.MoveNext())
            {
                Assert.AreEqual(iterator1.Current, iterator2.Current);
            }
        }
Example #12
0
    public static void Main()
    {
        string input;

        while ((input = Console.ReadLine()) != "END")
        {
            var tokens  = input.Split().ToArray();
            var command = tokens[0];
            try
            {
                switch (command)
                {
                case "Create":
                    iterator = new ListIterator(tokens.Skip(1).ToList());
                    break;

                case "HasNext":
                    Console.WriteLine(iterator.HasNext());
                    break;

                case "Move":
                    Console.WriteLine(iterator.Move());
                    break;

                case "Print":
                    iterator.Print();
                    break;
                }
            }
            catch (ArgumentNullException exception)
            {
                Console.WriteLine(exception.Message);
            }
        }
    }
Example #13
0
        /// <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);
        }
Example #14
0
        public void TestValidHasNext()
        {
            int[] values = new[] { 1, 2, 3, 5, 67, 7 };
            ListIterator <int> listyIterator = new ListIterator <int>(values.ToList());

            listyIterator.HasNext();
        }
        /// <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);
        }
        public void HasNextShouldReturnFalseIfThereIsNothingOnTheNextIndex()
        {
            var writerMock = new Mock <IWriter>();
            var strings    = new[] { "Ivan" };
            var iterator   = new ListIterator(writerMock.Object, strings);

            Assert.IsFalse(iterator.HasNext());
        }
        public void HasNextShouldReturnTrueIfThereIsAnythingOnTheNextIndex()
        {
            var writerMock = new Mock <IWriter>();
            var strings    = new[] { "Ivan", "Pesho", "Gosho" };
            var iterator   = new ListIterator(writerMock.Object, strings);

            Assert.IsTrue(iterator.HasNext());
        }
Example #18
0
    public void HasNextTest_ReturnsFalse()
    {
        ListIterator listIterator = new ListIterator(new string[] { "1", "2", "3" });

        listIterator.Move();
        listIterator.Move();
        Assert.That(listIterator.HasNext(), Is.EqualTo(false));
    }
    public void HasNextReturnsTrueIfIndexInRange()
    {
        string[] parameters = new string[] { "Pesho", "Gosho", "Sasho", "Stamat", "Balkan" };

        ListIterator iterator = new ListIterator(parameters);

        Assert.That(iterator.HasNext(), Is.EqualTo(true));
    }
Example #20
0
        public void TestIfHasNextReturnsFasle()
        {
            ListIterator listIterator = new ListIterator(new string[] { "Gosho", "Pesho" });

            listIterator.Move();
            listIterator.Move();
            Assert.AreEqual(listIterator.HasNext(), false);
        }
    public void HasNextReturnsFalseIfIndexNotInRange()
    {
        string[] parameters = new string[] { "Pesho" };

        ListIterator iterator = new ListIterator(parameters);

        Assert.That(iterator.HasNext(), Is.EqualTo(false));
    }
Example #22
0
        public void HasNextIndex_CheckForNextIndex_ReturnTrue()
        {
            //Arrange
            var list = new ListIterator(new[] { "", "" });

            //Assert
            Assert.That(() => list.HasNext(), Is.True);
        }
Example #23
0
        public void HasNextReturnsTrue()
        {
            string[] testData = new string[] { "aa", "bb", "cc" };

            ListIterator li = new ListIterator(testData);

            Assert.That(li.HasNext(), Is.True);
        }
Example #24
0
        public void HasNext_WorksCorrectly(int amount)
        {
            string[] arr = new string[amount];
            for (int i = 0; i < amount; i++)
            {
                arr[i] = i.ToString();
            }

            ListIterator iterator = new ListIterator(arr);

            for (int i = 0; i < amount - 1; i++)
            {
                Assert.True(iterator.HasNext());
                iterator.Move();
            }

            Assert.False(iterator.HasNext());
        }
Example #25
0
        private static void ExecuteCommands()
        {
            string[]     inputArgs = Console.ReadLine().Split();
            ListIterator iterator  = new ListIterator(inputArgs.Skip(1));
            //MethodInfo[] iteratorMethods = iterator.GetType().GetMethods();

            string command = string.Empty;

            while (!(command = Console.ReadLine()).Equals("END"))
            {
                try
                {
                    switch (command)
                    {
                    case "HasNext":
                        Console.WriteLine(iterator.HasNext());
                        break;

                    case "Move":
                        Console.WriteLine(iterator.Move());
                        break;

                    case "Print":
                        Console.WriteLine(iterator.Print());
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                //try
                //{
                //    var parsedMethod = iteratorMethods.FirstOrDefault(m => m.Name == command);

                //    if (parsedMethod == null)
                //    {
                //        Console.WriteLine($"This option {command} does not exists");
                //    }

                //    Console.WriteLine(parsedMethod.Invoke(iterator, new object[] { }));
                //}
                //catch (TargetInvocationException tie)
                //{
                //    if (tie.InnerException is InvalidOperationException)
                //    {
                //        Console.WriteLine(tie.InnerException.Message);
                //    }
                //}
                //catch (ArgumentNullException ane)
                //{
                //    Console.WriteLine(ane.Message);
                //}
            }
        }
Example #26
0
        public void HasNext_IfLastIndex_ShouldReturnFalse()
        {
            var list = new List <string> {
                "a"
            };
            var iterator = new ListIterator(list);
            var expected = false;

            Assert.AreEqual(expected, iterator.HasNext());
        }
Example #27
0
        public void HasNext_IfNotLastIndex_ShouldReturnTrue()
        {
            var list = new List <string> {
                "a", "b", "c"
            };
            var iterator = new ListIterator(list);
            var expected = true;

            Assert.AreEqual(expected, iterator.HasNext());
        }
        public void TestHasNext_ToReturnTrue()
        {
            var list = new List <string>()
            {
                "1", "2", "3"
            };
            var listIterator = new ListIterator(list);

            Assert.That(listIterator.HasNext(), Is.EqualTo(true));
        }
        public void TestHasNext_ToReturnFalse()
        {
            var list = new List <string>()
            {
                "1"
            };
            var listIterator = new ListIterator(list);

            Assert.That(listIterator.HasNext(), Is.EqualTo(false));
        }
Example #30
0
    public static void Main()
    {
        string input = Console.ReadLine();

        var tokens = input.Split();

        ListIterator listIterator;

        try
        {
            listIterator = new ListIterator(tokens.Skip(1).ToArray());
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
        while (input != "END")
        {
            tokens = input.Split();

            var result = string.Empty;

            var command = tokens[0];

            switch (command)
            {
            case "Move":
                result = listIterator.Move().ToString();
                break;

            case "HasNext":
                result = listIterator.HasNext().ToString();
                break;

            case "Print":
                try
                {
                    listIterator.Print();
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine(ioe.Message);
                }
                break;
            }

            if (!string.IsNullOrEmpty(result))
            {
                Console.WriteLine(result);
            }

            input = Console.ReadLine();
        }
    }