Code example for LinkedList

Methods: addLast, getLast

0
     * @return returns itself so you can chain 
     */ 
    public BasicDBObjectBuilder push( String key ){
        BasicDBObject o = new BasicDBObject();
        _cur().put( key , o );
        _stack.addLast( o );
        return this;
    } 
 
    /** 
     * pops the active object, which means that the parent object becomes active 
     * @return returns itself so you can chain 
     */ 
    public BasicDBObjectBuilder pop(){ 
        if ( _stack.size() <= 1 )
            throw new IllegalArgumentException( "can't pop last element" );
        _stack.removeLast();
        return this;
    } 
 
    /** 
     * gets the base object 
     * @return The base object 
     */ 
    public DBObject get(){ 
        return _stack.getFirst();
    } 
 
    /** 
     * returns true if no key/value was inserted into base object 
     * @return True if empty 
     */ 
    public boolean isEmpty(){ 
        return ((BasicDBObject) _stack.getFirst()).size() == 0;
    } 
 
    private DBObject _cur(){ 
        return _stack.getLast();
    } 
 
    private final LinkedList<DBObject> _stack;
 
}