FileDocCategorySizeDatePackage
LList.javaAPI DocGlassfish v2 API3650Wed Aug 30 15:34:16 BST 2006persistence.antlr.collections.impl

LList

public class LList extends Object implements List, Stack
A Linked List Implementation (not thread-safe for simplicity) (adds to the tail) (has an enumeration)

Fields Summary
protected LLCell
head
protected LLCell
tail
protected int
length
Constructors Summary
Methods Summary
public voidadd(java.lang.Object o)
Add an object to the end of the list.

param
o the object to add



                        
        
        append(o);
    
public voidappend(java.lang.Object o)
Append an object to the end of the list.

param
o the object to append

        LLCell n = new LLCell(o);
        if (length == 0) {
            head = tail = n;
            length = 1;
        }
        else {
            tail.next = n;
            tail = n;
            length++;
        }
    
protected java.lang.ObjectdeleteHead()
Delete the object at the head of the list.

return
the object found at the head of the list.
exception
NoSuchElementException if the list is empty.

        if (head == null) throw new NoSuchElementException();
        Object o = head.data;
        head = head.next;
        length--;
        return o;
    
public java.lang.ObjectelementAt(int i)
Get the ith element in the list.

param
i the index (from 0) of the requested element.
return
the object at index i NoSuchElementException is thrown if i out of range

        int j = 0;
        for (LLCell p = head; p != null; p = p.next) {
            if (i == j) return p.data;
            j++;
        }
        throw new NoSuchElementException();
    
public java.util.Enumerationelements()
Return an enumeration of the list elements

        return new LLEnumeration(this);
    
public intheight()
How high is the stack?

        return length;
    
public booleanincludes(java.lang.Object o)
Answers whether or not an object is contained in the list

param
o the object to test for inclusion.
return
true if object is contained else false.

        for (LLCell p = head; p != null; p = p.next) {
            if (p.data.equals(o)) return true;
        }
        return false;
    
protected voidinsertHead(java.lang.Object o)
Insert an object at the head of the list.

param
o the object to add

        LLCell c = head;
        head = new LLCell(o);
        head.next = c;
        length++;
        if (tail == null) tail = head;
    
public intlength()
Return the length of the list.

        return length;
    
public java.lang.Objectpop()
Pop the top element of the stack off.

return
the top of stack that was popped off.
exception
NoSuchElementException if the stack is empty.

        Object o = deleteHead();
        return o;
    
public voidpush(java.lang.Object o)
Push an object onto the stack.

param
o the object to push

        insertHead(o);
    
public java.lang.Objecttop()

        if (head == null) throw new NoSuchElementException();
        return head.data;