KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > workbench > table > VerbosityRating


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.workbench.table;
16
17 import java.io.Serializable JavaDoc;
18 import java.text.SimpleDateFormat JavaDoc;
19 import java.util.GregorianCalendar JavaDoc;
20 import java.util.Locale JavaDoc;
21
22 /**
23  * @author mindbridge
24  *
25  */

26 public class VerbosityRating implements Serializable JavaDoc
27 {
28     private static final long serialVersionUID = 1L;
29     
30     /**
31      * Method calculateVerbosity.
32      * Please note that this method is relatively slow
33      * It should not be used often, unless for fun :)
34      * @param objLocale
35      * @return int
36      */

37     public static int calculateVerbosity(Locale JavaDoc objLocale)
38     {
39         int nWeekDayVerbosity = calculateWeekDayVerbosity(objLocale);
40         int nMonthVerbosity = calculateMonthVerbosity(objLocale);
41         return nWeekDayVerbosity + nMonthVerbosity;
42     }
43
44     public static int calculateWeekDayVerbosity(Locale JavaDoc objLocale)
45     {
46         SimpleDateFormat JavaDoc objWeekDay = new SimpleDateFormat JavaDoc("EEEE", objLocale);
47
48         GregorianCalendar JavaDoc objCalendar = new GregorianCalendar JavaDoc();
49         objCalendar.set(GregorianCalendar.YEAR, 2000);
50         objCalendar.set(GregorianCalendar.MONTH, 0);
51         objCalendar.set(GregorianCalendar.DATE, 1);
52
53         int nCount = 0;
54         for (int i = 0; i < 7; i++)
55         {
56             String JavaDoc strWeekDay = objWeekDay.format(objCalendar.getTime());
57             nCount += strWeekDay.length();
58             objCalendar.add(GregorianCalendar.DATE, 1);
59         }
60
61         return nCount;
62     }
63
64     public static int calculateMonthVerbosity(Locale JavaDoc objLocale)
65     {
66         SimpleDateFormat JavaDoc objMonth = new SimpleDateFormat JavaDoc("MMMM", objLocale);
67
68         GregorianCalendar JavaDoc objCalendar = new GregorianCalendar JavaDoc();
69         objCalendar.set(GregorianCalendar.YEAR, 2000);
70         objCalendar.set(GregorianCalendar.MONTH, 0);
71         objCalendar.set(GregorianCalendar.DATE, 1);
72
73         int nCount = 0;
74         for (int i = 0; i < 12; i++)
75         {
76             String JavaDoc strMonth = objMonth.format(objCalendar.getTime());
77             nCount += strMonth.length();
78             objCalendar.add(GregorianCalendar.MONTH, 1);
79         }
80
81         return nCount;
82     }
83
84     public static void main(String JavaDoc[] arrArgs)
85     {
86         int nMax = 0;
87         int nMin = 1000;
88
89         System.out.println("Starting");
90
91         Locale JavaDoc[] arrLocales = Locale.getAvailableLocales();
92         for (int i = 0; i < arrLocales.length; i++)
93         {
94             Locale JavaDoc objLocale = arrLocales[i];
95             int nRating = calculateVerbosity(objLocale);
96             if (nRating > nMax)
97                 nMax = nRating;
98             if (nRating < nMin)
99                 nMin = nRating;
100         }
101
102         System.out.println("Min: " + nMin);
103         System.out.println("Max: " + nMax);
104     }
105
106 }
107
Popular Tags