Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/voytechs/jnetstream/npl/NodeList.java


1   /*
2    * File: NodeList.java
3    * Auth: Mark Bednarczyk
4    * Date: DATE
5    *   Id: $Id: NodeList.java,v 1.1.1.1 2003/09/22 16:32:18 voytechs Exp $
6    ********************************************
7    Copyright (C) 2003  Mark Bednarczyk
8   
9    This program is free software; you can redistribute it and/or
10   modify it under the terms of the GNU General Public License
11   as published by the Free Software Foundation; either version 2
12   of the License, or (at your option) any later version.
13  
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18  
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software
21   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22   ********************************************
23   * $Log: NodeList.java,v $
24   * Revision 1.1.1.1  2003/09/22 16:32:18  voytechs
25   * Initial import.
26   *
27   */
28  package com.voytechs.jnetstream.npl;
29  
30  import java.lang.*;
31  import java.util.*;
32  
33  /**
34   * 
35   */
36  public class NodeList 
37    extends Node 
38    implements Visitable {
39  
40    /* Internal attributes */
41    private static final boolean debug = false;
42  
43    private LinkedList list = new LinkedList();
44  
45    public boolean visit(Visitor visitor, Object user1, Object user2) throws NodeException { return(visitor.traverse(this, user1, user2)); }
46  
47    public void add(int index, Node node) { list.add(index, node); }
48    public boolean add(Node node) { return(list.add(node)); }
49  
50    public void addFirst(Node node) { list.addFirst(node); }
51    public void addLast(Node node) { list.addLast(node); }
52  
53    public void clear() { list.clear(); }
54    public boolean contains(Node node) { return(list.contains(node)); }
55    public int indexOf(Node node) { return(list.indexOf(node)); }
56    public boolean empty() { return(list.size() == 0); }
57    public int size() { return(list.size()); }
58  
59    public Node get(int index) { return((Node)list.get(index)); }
60    public Node getFirst() { return((Node)list.getFirst()); }
61    public Node getLast() { return((Node)list.getLast()); }
62  
63    /**
64     * Convenience functions that assume a specific type of node.
65     */
66    public int getInt(int index) { return( ((IntNode)list.get(index)).getInt()); }
67    public String getString(int index) { return( ((StringNode)list.get(index)).getString()); }
68    public boolean getBoolean(int index) { return( ((BooleanNode)list.get(index)).getBoolean()); }
69  
70    public boolean remove(Node node) { return(list.remove(node)); }
71    public Node remove(int index) { return((Node)list.remove(index)); }
72  
73    public String toString() {
74      return(list.toString());
75    }
76  
77  
78    public boolean canOptimize() { return(false); }
79    public Node optimize() { return(this); }
80  
81    public void merge(NodeList list) {
82  
83      for(int i = 0; i < list.size(); i++)
84        add(list.get(i));
85    }
86  
87  
88    /**
89     * Test function for NodeList
90     * @param args command line arguments
91     */
92    public static void main(String [] args) {
93    }
94  
95  } /* END OF: NodeList */