KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > util > NbBundleTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.util;
21
22 import org.openide.utildata.UtilClass;
23 import org.netbeans.performance.Benchmark;
24 import java.util.ResourceBundle JavaDoc;
25
26 public class NbBundleTest extends Benchmark {
27
28     public NbBundleTest(String JavaDoc name) {
29         super( name, new Integer JavaDoc[] {
30             new Integer JavaDoc(1), new Integer JavaDoc(10), new Integer JavaDoc(100), new Integer JavaDoc(1000)
31         });
32     }
33
34     private String JavaDoc[] keys;
35
36     protected void setUp() {
37         int count = getIterationCount();
38         int param = ((Integer JavaDoc)getArgument()).intValue();
39         keys = new String JavaDoc[param];
40         for( int i=0; i<param; i++ ) {
41             keys[i] = "MSG_BundleTest_" + i;
42         }
43     }
44     
45     protected void tearDown() {
46         keys=null;
47     }
48         
49     public void testGetMessageUsingClass() throws Exception JavaDoc {
50         int count = getIterationCount();
51         int magnitude = ((Integer JavaDoc)getArgument()).intValue();
52
53         while( count-- > 0 ) {
54             // do the stuff here,
55
for( int number = 0; number < magnitude; number++ ) {
56                 NbBundle.getMessage( UtilClass.class, keys[number] );
57             }
58         }
59     }
60
61     public void testGetMessageUsingClassFullBrand() throws Exception JavaDoc {
62         int count = getIterationCount();
63         int magnitude = ((Integer JavaDoc)getArgument()).intValue();
64     NbBundle.setBranding("brand1");
65
66         while( count-- > 0 ) {
67             // do the stuff here,
68
for( int number = 0; number < magnitude; number++ ) {
69                 NbBundle.getMessage( UtilClass.class, keys[number] );
70             }
71         }
72     NbBundle.setBranding(null);
73     }
74
75     public void testGetMessageUsingEmptyBrand() throws Exception JavaDoc {
76         int count = getIterationCount();
77         int magnitude = ((Integer JavaDoc)getArgument()).intValue();
78     NbBundle.setBranding("brand2");
79
80         while( count-- > 0 ) {
81             // do the stuff here,
82
for( int number = 0; number < magnitude; number++ ) {
83                 NbBundle.getMessage( UtilClass.class, keys[number] );
84             }
85         }
86     
87     NbBundle.setBranding(null);
88     }
89
90     private ResourceBundle JavaDoc bundle;
91     private synchronized ResourceBundle JavaDoc getBundle() {
92         if( bundle == null ) {
93             bundle = NbBundle.getBundle( UtilClass.class );
94         }
95         return bundle;
96     }
97     
98     private synchronized void clearBundle() {
99         bundle = null;
100     }
101     
102     public void testGetMessageUsingLazyCache() throws Exception JavaDoc {
103         int count = getIterationCount();
104         int magnitude = ((Integer JavaDoc)getArgument()).intValue();
105
106         while( count-- > 0 ) {
107             // do the stuff here,
108
for( int number = 0; number < magnitude; number++ ) {
109                 getBundle().getString( keys[number] );
110             }
111             clearBundle();
112         }
113     }
114
115     public void testGetMessageUsingCachedBundle() throws Exception JavaDoc {
116         int count = getIterationCount();
117         int magnitude = ((Integer JavaDoc)getArgument()).intValue();
118
119         while( count-- > 0 ) {
120             ResourceBundle JavaDoc bundle = NbBundle.getBundle( UtilClass.class );
121             // do the stuff here,
122
for( int number = 0; number < magnitude; number++ ) {
123                 bundle.getString( keys[number] );
124             }
125         }
126     }
127
128     public void testGetMessageUsingCachedBundleFullBrand() throws Exception JavaDoc {
129         int count = getIterationCount();
130         int magnitude = ((Integer JavaDoc)getArgument()).intValue();
131     NbBundle.setBranding("brand1");
132
133         while( count-- > 0 ) {
134             ResourceBundle JavaDoc bundle = NbBundle.getBundle( UtilClass.class );
135             // do the stuff here,
136
for( int number = 0; number < magnitude; number++ ) {
137                 bundle.getString( keys[number] );
138             }
139         }
140     NbBundle.setBranding(null);
141     }
142
143
144     public void testGetMessageUsingCachedBundleEmptyBrand() throws Exception JavaDoc {
145         int count = getIterationCount();
146         int magnitude = ((Integer JavaDoc)getArgument()).intValue();
147     NbBundle.setBranding("brand2");
148
149         while( count-- > 0 ) {
150             ResourceBundle JavaDoc bundle = NbBundle.getBundle( UtilClass.class );
151             // do the stuff here,
152
for( int number = 0; number < magnitude; number++ ) {
153                 bundle.getString( keys[number] );
154             }
155         }
156     NbBundle.setBranding(null);
157     }
158     
159     public static void main(String JavaDoc[] args) {
160     simpleRun( NbBundleTest.class );
161     }
162 }
163
Popular Tags