1 package org.apache.lucene.benchmark.byTask.tasks;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.util.Locale;
21 import java.util.StringTokenizer;
23 import org.apache.lucene.benchmark.byTask.PerfRunData;
26 * Set a {@link java.util.Locale} for use in benchmarking.
28 * Locales can be specified in the following ways:
30 * <li><code>de</code>: Language "de"
31 * <li><code>en,US</code>: Language "en", country "US"
32 * <li><code>no,NO,NY</code>: Language "no", country "NO", variant "NY"
33 * <li><code>ROOT</code>: The root (language-agnostic) Locale
34 * <li><empty string>: Erase the Locale (null)
38 public class NewLocaleTask extends PerfTask {
39 private String language;
40 private String country;
41 private String variant;
44 * Create a new {@link java.util.Locale} and set it it in the getRunData() for
45 * use by all future tasks.
47 public NewLocaleTask(PerfRunData runData) {
51 static Locale createLocale(String language, String country, String variant) {
52 if (language == null || language.length() == 0)
55 String lang = language;
56 if (lang.equalsIgnoreCase("ROOT"))
57 lang = ""; // empty language is the root locale in the JDK
59 return new Locale(lang, country, variant);
63 public int doLogic() throws Exception {
64 Locale locale = createLocale(language, country, variant);
65 getRunData().setLocale(locale);
66 System.out.println("Changed Locale to: " +
67 (locale == null ? "null" :
68 (locale.getDisplayName().length() == 0) ? "root locale" : locale));
73 public void setParams(String params) {
74 super.setParams(params);
75 language = country = variant = "";
76 StringTokenizer st = new StringTokenizer(params, ",");
77 if (st.hasMoreTokens())
78 language = st.nextToken();
79 if (st.hasMoreTokens())
80 country = st.nextToken();
81 if (st.hasMoreTokens())
82 variant = st.nextToken();
86 public boolean supportsParams() {