Esempio n. 1
0
        /**
         * Searches this list for the specified object and returns the index of the
         * first occurrence.
         *
         * @param object
         *            the object to search for.
         * @return the index of the first occurrence of the object, or -1 if it was
         *         not found.
         */
        public virtual int indexOf(Object obj)
        {
            ListIterator <E> it = listIterator();

            if (obj != null)
            {
                while (it.hasNext())
                {
                    if (obj.equals(it.next()))
                    {
                        return(it.previousIndex());
                    }
                }
            }
            else
            {
                while (it.hasNext())
                {
                    if (it.next() == null)
                    {
                        return(it.previousIndex());
                    }
                }
            }
            return(-1);
        }
        private void testListIterator(List <DSInteger> the_list)
        {
            ListIterator <DSInteger> it = the_list.listIterator();

            int count = 0;

            while (it.hasNext())
            {
                count++;
                it.next();
            }

            //you are at the last item, not one before the first item when the
            //initial loop begins
            count--;

            while (it.hasPrevious())
            {
                count--;
                it.previous();
            }
            Assert.AreEqual(0, count);

            //test values returned
            it = the_list.listIterator();
            Assert.AreEqual(30, it.next().value);
            Assert.AreEqual(60, it.next().value);

            //test removal
            DSInteger removed = it.remove();

            Assert.AreEqual(60, removed.value);
            Assert.AreEqual(90, it.next().value);

            it.next(); //120
            it.next(); //150

            //test removing the last item
            Assert.AreEqual(false, it.hasNext());
            Assert.AreEqual(150, it.remove().value);
            Assert.AreEqual(false, it.hasNext());
            Assert.AreEqual(90, it.previous().value);
            Assert.AreEqual(true, it.hasNext());
            Assert.AreEqual(120, it.next().value);

            //test removing the first item
            the_list.clear();
            addInitialItems(the_list);
            it = the_list.listIterator();
            Assert.AreEqual(false, it.hasPrevious());
            Assert.AreEqual(30, it.next().value);
            it.remove();
            Assert.AreEqual(false, it.hasPrevious());
            Assert.AreEqual(60, it.next().value);
            Assert.AreEqual(90, it.next().value);
            Assert.AreEqual(60, it.previous().value);
            Assert.AreEqual(false, it.hasPrevious());
        }
Esempio n. 3
0
        private static int[] CountPaths(int start, int end, int maxDistancia, bool countHops)
        {
            List <Situacao> situacoes  = new List <Situacao>();
            LinkedList      Distancias = new LinkedList();

            Situacao current = new Situacao {
                Ponto = start, Distancia = 0
            };                                                                     //initialize current

            /* note: this loop is organized counter-intuitively.  this is to insure that
             * start is never current when we're checking if we've found a path. otherwise
             * when start==end we would always find a Distancia-0 path and there's never one */
            while (true)
            {
                LinkedList   neighborList = getNeighbors(current.Ponto); //get neighbor list
                ListIterator i            = neighborList.listIterator(0);
                while (i.hasNext())
                {
                    Ponto neighbor = (Ponto)i.next();                 //for each neighbor

                    int DistanciaFromStart = current.Distancia;
                    if (countHops)
                    {
                        DistanciaFromStart += 1;
                    }
                    else
                    {
                        DistanciaFromStart += neighbor.Distancia;
                    }

                    if (DistanciaFromStart <= maxDistancia)        //if within range, add to queue
                    {
                        situacoes.Add(new Situacao {
                            Ponto = neighbor.Valor, Distancia = DistanciaFromStart
                        });
                    }
                }

                try
                {
                    current = (Situacao)situacoes.removeFirst(); //try to get next node to explore
                }
                catch { break; }                                 //break if none

                if (current.Ponto == end)                        //if we found another path to end
                {
                    Distancias.add(current.Distancia);           //take down its Distancia
                }
            }

            return(listToArray(Distancias));
        }
Esempio n. 4
0
        public override E set(int location, E obj)
        {
            ListIterator <E> it = listIterator(location);

            if (!it.hasNext())
            {
                throw new java.lang.IndexOutOfBoundsException();
            }
            E result = it.next();

            it.set(obj);
            return(result);
        }
Esempio n. 5
0
        public Model add(List l)
        {
            ListIterator iter = l.listIterator();

            while (iter.hasNext())
            {
                Object obj = iter.next();
                if (obj is Statement)
                {
                    this._g.Assert(JenaConverter.FromJena((Statement)obj, this._mapping));
                }
            }
            return(this);
        }
Esempio n. 6
0
        public static int ShortestPath(int start, int end)
        {
            var Situacao = new Situacao[27];

            Situacao[start] = new Situacao {
                Distancia = 0, Status = false
            };
            int current = start;

            do
            {
                LinkedList   neighborList = getNeighbors(current);  //get neighbors
                ListIterator i            = neighborList.listIterator(0);
                while (i.hasNext())                                 //for each neighbor
                {
                    Ponto neighbor = (Ponto)i.next();
                    int   DistanciaThroughCurrent = Situacao[current].Distancia + neighbor.Distancia;
                    if (Situacao[neighbor.Valor] == null)           //if we've never seen it before
                    {                                               // add it to Situacao list
                        Situacao[neighbor.Valor] = new Situacao {
                            Distancia = DistanciaThroughCurrent, Status = false
                        };
                    }
                    //if we've found a shorter path
                    else if (Situacao[neighbor.Valor].Distancia > DistanciaThroughCurrent)
                    {
                        Situacao[neighbor.Valor].Distancia = DistanciaThroughCurrent; //change Distancia
                    }
                }  //done going through neighbors

                Situacao[current].Status = true; //we should never come back to the current node

                if (current == end)              // This only happens on the first iteration since
                {
                    Situacao[current] = null;    // it is the loop exit condition, so if its true then
                }
                // current == start == end.  We want to find this node again
                // so we pretend we haven't seen it yet

                current = GetClosest(Situacao);   //the next node is the closest onea
                if (current == -1)
                {
                    throw new Exception("No such path");  //if no more next nodes
                }
            } while (current != end);

            return(Situacao[end].Distancia);
        }
Esempio n. 7
0
        private string toString(LinkedList linkedList)
        {
            if (linkedList == null || linkedList.isEmpty())
            {
                return("");
            }
            StringBuilder stringBuilder = new StringBuilder();
            ListIterator  listIterator  = linkedList.listIterator();

            while (listIterator.hasNext())
            {
                stringBuilder.append(listIterator.next()).append(' ');
            }
            stringBuilder.setLength(stringBuilder.length() - 1);
            return(stringBuilder.toString());
        }
Esempio n. 8
0
        }                           //in the list, so we could get two with different wieghts if

        //the input is careless

        public static int Distance(int v1, int v2)
        {
            CheckValid(v1); CheckValid(v2);
            ListIterator i = nodeList[v1].listIterator(0);

            while (i.hasNext())

            {
                Ponto current = (Ponto)i.next();          //get the next edge in the adjacency-list
                if (current.node == v2)
                {
                    return(current.distance);
                }
            }
            throw new Exception("No such edge");
        }
Esempio n. 9
0
 internal virtual void optimize()
 {
     for (int i = 0; i < this.arcList.size(); i++)
     {
         GrammarArc grammarArc = (GrammarArc)this.arcList.get(i);
         this.arcList.set(i, this.optimizeArc(grammarArc));
     }
     if (this.isEmpty())
     {
         ListIterator listIterator = this.arcList.listIterator();
         while (listIterator.hasNext())
         {
             GrammarArc grammarArc = (GrammarArc)listIterator.next();
             if (this == grammarArc.getGrammarNode())
             {
                 listIterator.remove();
             }
         }
     }
 }
Esempio n. 10
0
 public bool hasNext()
 {
     return(iterator.hasNext());
 }
Esempio n. 11
0
 public void pushInputs(float[] farray)
 {
     ListIterator<InNetworkNode> iter = new ListIterator<InNetworkNode>(this.inlayer);
     int i = 0;
     while(iter.hasNext()){
         InNetworkNode bob = iter.next().Value;
         bob.setOutput(farray[i]);
         i++;
     }
 }
Esempio n. 12
0
        public float[] pullOutputs()
        {
            ListIterator<NetworkNode> iterhidden1 = new  ListIterator<NetworkNode>(hlayer1);
            ListIterator<NetworkNode> iterhidden2 = new ListIterator<NetworkNode>(hlayer2);
            ListIterator<NetworkNode> iterout = new  ListIterator<NetworkNode>(outlayer);
            while(iterhidden1.hasNext()){
                iterhidden1.next().Value.UpdateOutput();
            }

            while (iterhidden2.hasNext())
            {
                iterhidden2.next().Value.UpdateOutput();
            }

            while(iterout.hasNext()){
                iterout.next().Value.UpdateOutput();
            }
            ListIterator<NetworkNode> iterfinal = new ListIterator<NetworkNode>(outlayer);
            int i = 0;
            float[] barray = new float[4];
            while(iterfinal.hasNext()){
                NetworkNode bob = iterfinal.next().Value;
                barray[i] = (bob.getOutput())>0.6f?1:0;
                i++;
            }
            return barray;
        }