KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > api > data > autobinding > DataRowExpressionEvaluator


1 /*******************************************************************************
2  * Copyright (c) 2004 Actuate Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Actuate Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.birt.chart.examples.api.data.autobinding;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.birt.chart.factory.DataRowExpressionEvaluatorAdapter;
18
19 public class DataRowExpressionEvaluator extends
20         DataRowExpressionEvaluatorAdapter
21 {
22
23     private int k = 0;
24     private Object JavaDoc[] column;
25     private Map JavaDoc map;
26
27     public DataRowExpressionEvaluator( String JavaDoc[] set, Object JavaDoc[][] data )
28     {
29         if ( set == null )
30         {
31             throw new IllegalArgumentException JavaDoc( );
32         }
33
34         map = new HashMap JavaDoc( );
35         for ( int i = 0; i < set.length; i++ )
36         {
37             map.put( set[i], data[i] );
38         }
39     }
40
41     /*
42      * (non-Javadoc)
43      *
44      * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#evaluate(java.lang.String)
45      */

46     public Object JavaDoc evaluate( String JavaDoc expression )
47     {
48         column = (Object JavaDoc[]) map.get( expression );
49         return column[k];
50     }
51
52     /*
53      * (non-Javadoc)
54      *
55      * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#first()
56      */

57     public boolean first( )
58     {
59         k = 0;
60
61         if ( map.size( ) > 0 )
62         {
63             column = (Object JavaDoc[]) map.values( ).iterator( ).next( );
64
65             if ( column != null && k < column.length )
66             {
67                 return true;
68             }
69         }
70
71         return false;
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#next()
78      */

79     public boolean next( )
80     {
81         if ( column != null && k < ( column.length - 1 ) )
82         {
83             k++;
84             return true;
85         }
86         return false;
87     }
88
89     /*
90      * (non-Javadoc)
91      *
92      * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#close()
93      */

94     public void close( )
95     {
96         // Doing nothing.
97
}
98
99 }
Popular Tags