Esempio n. 1
0
        /// <summary>
        /// {@inheritDoc}
        ///
        /// <para>This implementation first gets a list iterator that points to the end
        /// of the list (with {@code listIterator(size())}).  Then, it iterates
        /// backwards over the list until the specified element is found, or the
        /// beginning of the list is reached.
        ///
        /// </para>
        /// </summary>
        /// <exception cref="ClassCastException">   {@inheritDoc} </exception>
        /// <exception cref="NullPointerException"> {@inheritDoc} </exception>
        public virtual int LastIndexOf(Object o)
        {
            ListIterator <E> it = ListIterator(Size());

            if (o == null)
            {
                while (it.HasPrevious())
                {
                    if (it.Previous() == null)
                    {
                        return(it.NextIndex());
                    }
                }
            }
            else
            {
                while (it.HasPrevious())
                {
                    if (o.Equals(it.Previous()))
                    {
                        return(it.NextIndex());
                    }
                }
            }
            return(-1);
        }
        /// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception>
        public bool Process(TextDocument doc)
        {
            bool changes             = false;
            int  words               = 0;
            IList <TextBlock> blocks = doc.GetTextBlocks();

            if (!blocks.IsEmpty())
            {
                ListIterator <TextBlock> it = blocks.ListIterator <TextBlock>(blocks.Count);
                TextBlock tb;
                while (it.HasPrevious())
                {
                    tb = it.Previous();
                    if (tb.HasLabel(DefaultLabels.INDICATES_END_OF_TEXT))
                    {
                        tb.AddLabel(DefaultLabels.STRICTLY_NOT_CONTENT);
                        tb.RemoveLabel(DefaultLabels.MIGHT_BE_CONTENT);
                        tb.SetIsContent(false);
                        changes = true;
                    }
                    else
                    {
                        if (tb.IsContent())
                        {
                            words += tb.GetNumWords();
                            if (words > 200)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(changes);
        }
Esempio n. 3
0
        public void ForwardAndBackIteratorTest()
        {
            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();

            actual.Add(iterator.Next());
            actual.Add(iterator.Next());
            actual.Add(iterator.Previous());
            actual.Add(iterator.Next());
            actual.Add(iterator.Next());

            while (iterator.HasPrevious())
            {
                actual.Add(iterator.Previous());
            }
            Assert.ThrowsException <System.IndexOutOfRangeException>(() => iterator.Previous());

            List <int> lista2 = new List <int> {
                1, 2, 2, 2, 3, 3, 2, 1
            };

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

            while (iterator1.MoveNext() && iterator2.MoveNext())
            {
                Assert.AreEqual(iterator1.Current, iterator2.Current);
            }
        }
Esempio n. 4
0
        /// <returns>true, if the string currently being matched does match.</returns>
        public virtual bool IsMatch()
        {
            ListIterator <Head> headIterator = heads.ListIterator(heads.Count);

            while (headIterator.HasPrevious())
            {
                Head head = headIterator.Previous();
                if (head == LastHead.INSTANCE)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 5
0
        /// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception>
        public bool Process(TextDocument doc)
        {
            IList <TextBlock> textBlocks = doc.GetTextBlocks();

            if (textBlocks.Count < 2)
            {
                return(false);
            }
            int       maxNumWords  = -1;
            TextBlock largestBlock = null;
            int       level        = -1;
            int       i            = 0;
            int       n            = -1;

            foreach (TextBlock tb in textBlocks)
            {
                if (tb.IsContent())
                {
                    int nw = tb.GetNumWords();
                    if (nw > maxNumWords)
                    {
                        largestBlock = tb;
                        maxNumWords  = nw;
                        n            = i;
                        if (expandToSameLevelText)
                        {
                            level = tb.GetTagLevel();
                        }
                    }
                }
                i++;
            }
            foreach (TextBlock tb_1 in textBlocks)
            {
                if (tb_1 == largestBlock)
                {
                    tb_1.SetIsContent(true);
                }
                else
                {
                    tb_1.SetIsContent(false);
                    tb_1.AddLabel(DefaultLabels.MIGHT_BE_CONTENT);
                }
            }
            if (expandToSameLevelText && n != -1)
            {
                for (ListIterator <TextBlock> it = textBlocks.ListIterator(n); it.HasPrevious();)
                {
                    TextBlock tb_2 = it.Previous();
                    int       tl   = tb_2.GetTagLevel();
                    if (tl < level)
                    {
                        break;
                    }
                    else
                    {
                        if (tl == level)
                        {
                            tb_2.SetIsContent(true);
                        }
                    }
                }
                for (ListIterator <TextBlock> it_1 = textBlocks.ListIterator(n); it_1.HasNext();)
                {
                    TextBlock tb_2 = it_1.Next();
                    int       tl   = tb_2.GetTagLevel();
                    if (tl < level)
                    {
                        break;
                    }
                    else
                    {
                        if (tl == level)
                        {
                            tb_2.SetIsContent(true);
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 6
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Reservation.Exceptions.PlanningException
        ///     "/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Reservation.Exceptions.ContractValidationException
        ///     "/>
        private bool ComputeAllocation(ReservationId reservationId, string user, Plan plan
                                       , ReservationDefinition contract, ReservationAllocation oldReservation)
        {
            Log.Info("placing the following ReservationRequest: " + contract);
            Resource totalCapacity = plan.GetTotalCapacity();
            // Here we can addd logic to adjust the ResourceDefinition to account for
            // system "imperfections" (e.g., scheduling delays for large containers).
            // Align with plan step conservatively (i.e., ceil arrival, and floor
            // deadline)
            long earliestStart = contract.GetArrival();
            long step          = plan.GetStep();

            if (earliestStart % step != 0)
            {
                earliestStart = earliestStart + (step - (earliestStart % step));
            }
            long deadline = contract.GetDeadline() - contract.GetDeadline() % plan.GetStep();
            // setup temporary variables to handle time-relations between stages and
            // intermediate answers
            long curDeadline = deadline;
            long oldDeadline = -1;
            IDictionary <ReservationInterval, ReservationRequest> allocations = new Dictionary
                                                                                <ReservationInterval, ReservationRequest>();
            RLESparseResourceAllocation tempAssigned = new RLESparseResourceAllocation(plan.GetResourceCalculator
                                                                                           (), plan.GetMinimumAllocation());
            IList <ReservationRequest> stages = contract.GetReservationRequests().GetReservationResources
                                                    ();
            ReservationRequestInterpreter type = contract.GetReservationRequests().GetInterpreter
                                                     ();

            // Iterate the stages in backward from deadline
            for (ListIterator <ReservationRequest> li = stages.ListIterator(stages.Count); li.
                 HasPrevious();)
            {
                ReservationRequest currentReservationStage = li.Previous();
                // validate the RR respect basic constraints
                ValidateInput(plan, currentReservationStage, totalCapacity);
                // run allocation for a single stage
                IDictionary <ReservationInterval, ReservationRequest> curAlloc = PlaceSingleStage(
                    plan, tempAssigned, currentReservationStage, earliestStart, curDeadline, oldReservation
                    , totalCapacity);
                if (curAlloc == null)
                {
                    // if we did not find an allocation for the currentReservationStage
                    // return null, unless the ReservationDefinition we are placing is of
                    // type ANY
                    if (type != ReservationRequestInterpreter.RAny)
                    {
                        throw new PlanningException("The GreedyAgent" + " couldn't find a valid allocation for your request"
                                                    );
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    // if we did find an allocation add it to the set of allocations
                    allocations.PutAll(curAlloc);
                    // if this request is of type ANY we are done searching (greedy)
                    // and can return the current allocation (break-out of the search)
                    if (type == ReservationRequestInterpreter.RAny)
                    {
                        break;
                    }
                    // if the request is of ORDER or ORDER_NO_GAP we constraint the next
                    // round of allocation to precede the current allocation, by setting
                    // curDeadline
                    if (type == ReservationRequestInterpreter.ROrder || type == ReservationRequestInterpreter
                        .ROrderNoGap)
                    {
                        curDeadline = FindEarliestTime(curAlloc.Keys);
                        // for ORDER_NO_GAP verify that the allocation found so far has no
                        // gap, return null otherwise (the greedy procedure failed to find a
                        // no-gap
                        // allocation)
                        if (type == ReservationRequestInterpreter.ROrderNoGap && oldDeadline > 0)
                        {
                            if (oldDeadline - FindLatestTime(curAlloc.Keys) > plan.GetStep())
                            {
                                throw new PlanningException("The GreedyAgent" + " couldn't find a valid allocation for your request"
                                                            );
                            }
                        }
                        // keep the variable oldDeadline pointing to the last deadline we
                        // found
                        oldDeadline = curDeadline;
                    }
                }
            }
            // / If we got here is because we failed to find an allocation for the
            // ReservationDefinition give-up and report failure to the user
            if (allocations.IsEmpty())
            {
                throw new PlanningException("The GreedyAgent" + " couldn't find a valid allocation for your request"
                                            );
            }
            // create reservation with above allocations if not null/empty
            ReservationRequest ZeroRes = ReservationRequest.NewInstance(Resource.NewInstance(
                                                                            0, 0), 0);
            long firstStartTime = FindEarliestTime(allocations.Keys);

            // add zero-padding from arrival up to the first non-null allocation
            // to guarantee that the reservation exists starting at arrival
            if (firstStartTime > earliestStart)
            {
                allocations[new ReservationInterval(earliestStart, firstStartTime)] = ZeroRes;
                firstStartTime = earliestStart;
            }
            // consider to add trailing zeros at the end for simmetry
            // Actually add/update the reservation in the plan.
            // This is subject to validation as other agents might be placing
            // in parallel and there might be sharing policies the agent is not
            // aware off.
            ReservationAllocation capReservation = new InMemoryReservationAllocation(reservationId
                                                                                     , contract, user, plan.GetQueueName(), firstStartTime, FindLatestTime(allocations
                                                                                                                                                           .Keys), allocations, plan.GetResourceCalculator(), plan.GetMinimumAllocation());

            if (oldReservation != null)
            {
                return(plan.UpdateReservation(capReservation));
            }
            else
            {
                return(plan.AddReservation(capReservation));
            }
        }
Esempio n. 7
0
 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;
         }
     }
 }
Esempio n. 8
0
		private void CompareListIterators(ListIterator it1, ListIterator it2)
		{
			while (it1.HasPrevious())
			{
				NUnit.Framework.Assert.AreEqual(it1.Previous(), it2.Previous());
			}
			NUnit.Framework.Assert.IsFalse(it2.HasPrevious());
			CompareIterators(it1, it2);
		}
        /// <exception cref="NBoilerpipe.BoilerpipeProcessingException"></exception>
        public bool Process(TextDocument doc)
        {
            IList <TextBlock> textBlocks = doc.GetTextBlocks();

            if (textBlocks.Count < 2)
            {
                return(false);
            }
            bool      changes    = false;
            int       remaining  = textBlocks.Count;
            TextBlock blockBelow = null;
            TextBlock block;

            for (ListIterator <TextBlock> it = textBlocks.ListIterator <TextBlock>(textBlocks.Count); it.HasPrevious
                     ();)
            {
                if (--remaining <= 0)
                {
                    break;
                }
                if (blockBelow == null)
                {
                    blockBelow = it.Previous();
                    continue;
                }
                block = it.Previous();
                ICollection <string> labels = block.GetLabels();
                if (labels != null && !labels.IsEmpty())
                {
                    foreach (string l in labels)
                    {
                        blockBelow.AddLabel(labelPrefix + l);
                    }
                    changes = true;
                }
                blockBelow = block;
            }
            return(changes);
        }