KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > threads > JMeterVariables


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterVariables.java,v 1.9 2004/02/17 17:27:00 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.threads;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Map JavaDoc;
24
25 /**
26  * @version $Revision: 1.9 $
27  */

28 public class JMeterVariables
29 {
30     private Map JavaDoc variables = new HashMap JavaDoc();
31     private int iteration = 0;
32
33     public JMeterVariables()
34     {
35     }
36
37     public String JavaDoc getThreadName()
38     {
39         return Thread.currentThread().getName();
40     }
41
42     public int getIteration()
43     {
44         return iteration;
45     }
46
47     public void incIteration()
48     {
49         iteration++;
50     }
51
52     public void initialize()
53     {
54         variables.clear();
55     }
56
57     public Object JavaDoc remove(String JavaDoc key)
58     {
59         return variables.remove(key);
60     }
61     public void put(String JavaDoc key, String JavaDoc value)
62     {
63         variables.put(key, value);
64     }
65     
66     public void putObject(String JavaDoc key, Object JavaDoc value)
67     {
68         variables.put(key, value);
69     }
70
71     public void putAll(Map JavaDoc vars)
72     {
73         Iterator JavaDoc iter = vars.keySet().iterator();
74         while (iter.hasNext())
75         {
76             String JavaDoc item = (String JavaDoc) iter.next();
77             put(item, (String JavaDoc) vars.get(item));
78
79         }
80     }
81     
82     public void putAll(JMeterVariables vars)
83     {
84         putAll(vars.variables);
85     }
86
87     /**
88      * Returns null values if variable doesn't exist. Users of this must check
89      * for null.
90      */

91     public String JavaDoc get(String JavaDoc key)
92     {
93         return (String JavaDoc) variables.get(key);
94     }
95     
96     public Object JavaDoc getObject(String JavaDoc key)
97     {
98         return variables.get(key);
99     }
100 }
Popular Tags