KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > collect > WritableDataImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.diagnostics.collect;
24
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import com.sun.enterprise.diagnostics.Data;
30
31 /**
32  *
33  * @author Manisha Umbarje
34  */

35 public class WritableDataImpl implements WritableData {
36     
37     protected List JavaDoc<Data> children;
38     
39     protected List JavaDoc<String JavaDoc> values;
40     
41     protected List JavaDoc<List JavaDoc<String JavaDoc>> table;
42     
43     protected String JavaDoc source;
44     protected String JavaDoc type;
45     
46     private static int INITIAL_CAPACITY = 5;
47     
48     public WritableDataImpl() {
49         this("", DataType.CONTAINER);
50     }
51     public WritableDataImpl(String JavaDoc type) {
52         this("",type);
53     }
54     /** Creates a new instance of WritableDataImpl */
55     public WritableDataImpl(String JavaDoc source, String JavaDoc type) {
56         this(source,type, 5,20);
57     }
58     
59     public WritableDataImpl(String JavaDoc source, String JavaDoc type,
60             int initialValuesCapacity) {
61         this(source, type, INITIAL_CAPACITY, initialValuesCapacity);
62         
63     }
64     public WritableDataImpl(String JavaDoc source, String JavaDoc type,
65         int initialChildrenCapacity, int initialValuesCapacity) {
66         this(source,type, initialChildrenCapacity,
67                 initialValuesCapacity,INITIAL_CAPACITY);
68         
69     }
70     public WritableDataImpl(String JavaDoc source, String JavaDoc type,
71             int initialChildrenCapacity,
72         int initialValuesCapacity, int initialTableCapacity) {
73         
74         this.source= source;
75         this.type = type;
76         children = new ArrayList JavaDoc(initialChildrenCapacity);
77         values = new ArrayList JavaDoc(initialValuesCapacity);
78         table = new ArrayList JavaDoc(initialTableCapacity);
79         
80     }
81     
82     public void addChild(Data dataObj) {
83         if(dataObj != null)
84             children.add(dataObj);
85     }
86     
87     public void addValue(String JavaDoc value) {
88         values.add(value);
89     }
90     
91     public void addRow(List JavaDoc<String JavaDoc> list) {
92         if(list != null)
93             table.add(list);
94     }
95     public Iterator JavaDoc<Data> getChildren() {
96         return children.iterator();
97     }
98     
99     
100     public Iterator JavaDoc<String JavaDoc> getValues() {
101         return values.iterator();
102     }
103     public Iterator JavaDoc<Iterator JavaDoc<String JavaDoc>> getTable() {
104         List JavaDoc<Iterator JavaDoc<String JavaDoc>> listOfIterators = new ArrayList JavaDoc();
105         Iterator JavaDoc<List JavaDoc<String JavaDoc>> iterator = table.iterator();
106         while(iterator.hasNext()) {
107             List JavaDoc row = iterator.next();
108             listOfIterators.add(row.iterator());
109         }
110         return listOfIterators.iterator();
111     }
112     public String JavaDoc getSource() {
113         return source;
114     }
115     public String JavaDoc getType() {
116         return type;
117     }
118 }
119
Popular Tags