예제 #1
0
            public void nextByteDataIsReturnedOk()
            {
                this.byteDataLinkedList.add(this.byteData2);
                byteDataLinkedList.startIteration();
                Assert.Equal(null, byteDataLinkedList.checkObject());
                this.byteDataLinkedList.add(this.byteData4);
                byteDataLinkedList.startIteration();
                Assert.Equal(this.byteDataLinkedList.getFirst(), byteDataLinkedList.checkObject());

                ByteData[] byteDataList = new ByteData[3];
                byteDataList[0] = this.byteData3;
                byteDataList[1] = this.byteData0;
                byteDataList[2] = this.byteData1;
                this.byteDataLinkedList.addArray(byteDataList);
                byteDataLinkedList.startIteration();

                ByteData current = byteDataLinkedList.nextObject();

                Assert.Equal(this.byteData1, current);
                Assert.Equal(byteDataLinkedList.getFirst(), current.getPrevious());
                Assert.Equal(this.byteData2, current.getNext());

                current = byteDataLinkedList.nextObject();
                Assert.Equal(this.byteData2, current);
                Assert.Equal(this.byteData1, current.getPrevious());
                Assert.Equal(this.byteData3, current.getNext());

                current = byteDataLinkedList.nextObject();
                Assert.Equal(this.byteData3, current);
                Assert.Equal(this.byteData2, current.getPrevious());
                Assert.Equal(this.byteData4, current.getNext());

                current = byteDataLinkedList.nextObject();
                Assert.Equal(this.byteData4, current);
                Assert.Equal(this.byteData3, current.getPrevious());
                Assert.Equal(byteDataLinkedList.getLast(), current.getNext());

                current = byteDataLinkedList.nextObject();
                Assert.Equal(null, current);
            }
예제 #2
0
            /**
             * Adds new object to the right place in the linked list according to the count value.
             *
             * @param newByteData       New object
             */
            public void add(ByteData newByteData)
            {
                ByteData current = this.first;

                while (true)
                {
                    if (newByteData.getCount() < current.getCount() || current == this.last)
                    {
                        newByteData.setPrevious(current.getPrevious());
                        newByteData.setNext(current);
                        newByteData.getPrevious().setNext(newByteData);
                        newByteData.getNext().setPrevious(newByteData);
                        break;
                    }
                    current = current.getNext();
                }
            }