Exemple #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());
        }
Exemple #3
0
 public E next()
 {
     if (iterator.nextIndex() < end)
     {
         return(iterator.next());
     }
     throw new NoSuchElementException();
 }
Exemple #4
0
        //public abstract ListIterator<E> listIterator(int location);

        public override E remove(int location)
        {
            try {
                ListIterator <E> it = listIterator(location);
                E result            = it.next();
                it.remove();
                return(result);
            } catch (NoSuchElementException) {
                throw new java.lang.IndexOutOfBoundsException();
            }
        }
Exemple #5
0
        public static void sort(java.util.List <T> list)
        {
            Object[] a = list.toArray();
            Array.Sort <Object>(a);
            ListIterator <T> i = list.listIterator();

            for (int j = 0; j < a.Length; j++)
            {
                i.next();
                i.set((T)a[j]);
            }
        }
Exemple #6
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));
        }
Exemple #7
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);
        }
Exemple #8
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);
        }
Exemple #9
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);
        }
Exemple #10
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());
        }
Exemple #11
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");
        }
Exemple #12
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();
             }
         }
     }
 }
Exemple #13
0
        internal virtual void alignWords(LinkedList linkedList, NISTAlign.StringRenderer stringRenderer)
        {
            ListIterator listIterator  = this.referenceItems.listIterator();
            ListIterator listIterator2 = this.hypothesisItems.listIterator();
            object       obj           = null;
            object       obj2          = null;

            this.alignedReferenceWords  = new LinkedList();
            this.alignedHypothesisWords = new LinkedList();
            for (int i = linkedList.size() - 2; i >= 0; i--)
            {
                int    num = ((Integer)linkedList.get(i)).intValue();
                string text;
                if (num != 2)
                {
                    obj  = listIterator.next();
                    text = stringRenderer.getRef(obj, obj2);
                }
                else
                {
                    text = null;
                }
                string text2;
                if (num != 3)
                {
                    obj2  = listIterator2.next();
                    text2 = stringRenderer.getHyp(obj, obj2);
                }
                else
                {
                    text2 = null;
                }
                switch (num)
                {
                case 1:
                    text  = String.instancehelper_toUpperCase(text);
                    text2 = String.instancehelper_toUpperCase(text2);
                    break;

                case 2:
                    text2 = String.instancehelper_toUpperCase(text2);
                    break;

                case 3:
                    text = String.instancehelper_toUpperCase(text);
                    break;
                }
                if (text == null)
                {
                    text = String.instancehelper_substring("********************************************", 0, String.instancehelper_length(text2));
                }
                if (text2 == null)
                {
                    text2 = String.instancehelper_substring("********************************************", 0, String.instancehelper_length(text));
                }
                if (String.instancehelper_length(text) > String.instancehelper_length(text2))
                {
                    text2 = String.instancehelper_concat(text2, String.instancehelper_substring("                                            ", 0, String.instancehelper_length(text) - String.instancehelper_length(text2)));
                }
                else if (String.instancehelper_length(text) < String.instancehelper_length(text2))
                {
                    text = String.instancehelper_concat(text, String.instancehelper_substring("                                            ", 0, String.instancehelper_length(text2) - String.instancehelper_length(text)));
                }
                this.alignedReferenceWords.add(text);
                this.alignedHypothesisWords.add(text2);
            }
        }
Exemple #14
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++;
     }
 }
Exemple #15
0
        public Network()
        {
            Random R = new Random();
            inlayer = new LinkedList<InNetworkNode>();
            outlayer = new LinkedList<NetworkNode>();
            hlayer1 = new LinkedList<NetworkNode>();
            hlayer2 = new LinkedList<NetworkNode>();
            for (int i = 0; i < 14; i++)
            {
                InNetworkNode bob = new InNetworkNode();
                inlayer.AddLast(bob);
            }
            for (int i = 0; i < 28; i++)
            {
                NetworkNode bob = new NetworkNode();
                hlayer1.AddLast(bob);
                ListIterator<InNetworkNode> iter = new ListIterator<InNetworkNode>(inlayer);
                int n = 0;
                int m = 0;
                int col=0;
                int type = 0;
                switch (i)
                {
                    case 0: { n = 0; m = 2; type = ROW; } break;
                    case 1: { n = 3; m = 5; type = ROW; } break;
                    case 2: { n = 6; m = 8; type = ROW; } break;
                    case 3: { n = 9; m = 11; type = ROW; } break;
                    case 4: { n = 12; m = 14; type = ROW; } break;
                    case 5: { col=0; type = COL; } break;
                    case 6: { col=1; type = COL; } break;
                    case 7: { col=2; type = COL; } break;
                }
                 /*
                 if (type == ROW)
                {
                    for (int j = n; j <= m; j++)
                    {
                        bob.addNode(inlayer.ElementAt(j), (float)R.NextDouble() * 2 - 1);
                    }
                }
                else
                {
                    switch (col)
                    {
                        case 0: {
                            bob.addNode(inlayer.ElementAt(0), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(3), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(6), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(9), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(12), (float)R.NextDouble() * 2 - 1);
                        } break;
                        case 1: {
                            bob.addNode(inlayer.ElementAt(1), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(4), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(7), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(10), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(13), (float)R.NextDouble() * 2 - 1);
                        } break;
                        case 2: {
                            bob.addNode(inlayer.ElementAt(2), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(5), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(8), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(11), (float)R.NextDouble() * 2 - 1);
                            bob.addNode(inlayer.ElementAt(14), (float)R.NextDouble() * 2 - 1);
                        } break;
                    }
                }
               */

                for (int j = 0; j < 15; j++)
                {
                    bob.addNode(iter.next().Value, (float)R.NextDouble());
                }

            }

            for (int i = 0; i < 14; i++)
            {
                NetworkNode bob = new NetworkNode();
                hlayer2.AddLast(bob);
                ListIterator<NetworkNode> iter2 = new ListIterator<NetworkNode>(hlayer1);
                for (int j = 0; j < 8; j++)
                {
                    bob.addNode(iter2.next().Value, (float)R.NextDouble() * 2 - 1);
                }
            }

            for (int i = 0; i < 4; i++)
            {
                NetworkNode bob = new NetworkNode();
                outlayer.AddLast(bob);
                ListIterator<NetworkNode> iter = new ListIterator<NetworkNode>(hlayer2);
                for (int j = 0; j < 8; j++)
                {
                    bob.addNode(iter.next().Value, (float)R.NextDouble() * 2 - 1);
                }
            }
        }
Exemple #16
0
 public E next()
 {
     return(iterator.next());
 }
Exemple #17
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;
        }