KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > biff > CountryCode


1 /*********************************************************************
2 *
3 * Copyright (C) 2005 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.biff;
21
22 import common.Logger;
23
24 /**
25  * Enumeration type for the excel country codes
26  */

27 public class CountryCode
28 {
29   /**
30    * The logger
31    */

32   private static Logger logger = Logger.getLogger(CountryCode.class);
33
34   /**
35    * The country code
36    */

37   private int value;
38
39   /**
40    * The ISO 3166 two letter country mnemonic (as used by the Locale class)
41    */

42   private String JavaDoc code;
43
44   /**
45    * The long description
46    */

47   private String JavaDoc description;
48   
49   /**
50    * The array of country codes
51    */

52   private static CountryCode[] codes = new CountryCode[0];
53
54   /**
55    * Constructor
56    */

57   private CountryCode(int v, String JavaDoc c, String JavaDoc d)
58   {
59     value = v;
60     code = c;
61     description = d;
62
63     CountryCode[] newcodes = new CountryCode[codes.length+1];
64     System.arraycopy(codes, 0, newcodes, 0, codes.length);
65     newcodes[codes.length] = this;
66     codes = newcodes;
67   }
68
69   /**
70    * Constructor used to create an arbitrary code with a specified value.
71    * Doesn't add the latest value to the static array
72    */

73   private CountryCode(int v)
74   {
75     value = v;
76     description = "Arbitrary";
77     code = "??";
78   }
79
80   /**
81    * Accessor for the excel value
82    *
83    * @return the excel value
84    */

85   public int getValue()
86   {
87     return value;
88   }
89
90   /**
91    * Accessor for the string
92    *
93    * @return the two character iso 3166 string
94    */

95   public String JavaDoc getCode()
96   {
97     return code;
98   }
99
100   /**
101    * Gets the country code for the given two character mnemonic string
102    */

103   public static CountryCode getCountryCode(String JavaDoc s)
104   {
105     if (s == null || s.length() != 2)
106     {
107       logger.warn("Please specify two character ISO 3166 country code");
108       return USA;
109     }
110
111     CountryCode code = UNKNOWN;
112     for (int i = 0 ; i < codes.length && code == UNKNOWN ; i++)
113     {
114       if (codes[i].code.equals(s))
115       {
116         code = codes[i];
117       }
118     }
119
120     return code;
121   }
122
123   /**
124    * Creates an arbitrary country code with the specified value. Used
125    * when copying sheets, and the country code isn't initialized as part
126    * of the static data below
127    */

128   public static CountryCode createArbitraryCode(int i)
129   {
130     return new CountryCode(i);
131   }
132   
133   // The country codes
134
public final static CountryCode USA = new CountryCode(0x1, "US", "USA");
135   public final static CountryCode CANADA =
136     new CountryCode(0x2, "CA", "Canada");
137   public final static CountryCode GREECE =
138     new CountryCode(0x1e, "GR", "Greece");
139   public final static CountryCode NETHERLANDS =
140     new CountryCode(0x1f, "NE", "Netherlands");
141   public final static CountryCode BELGIUM =
142     new CountryCode(0x20, "BE", "Belgium");
143   public final static CountryCode FRANCE =
144     new CountryCode(0x21, "FR", "France");
145   public final static CountryCode SPAIN = new CountryCode(0x22, "ES", "Spain");
146   public final static CountryCode ITALY = new CountryCode(0x27, "IT", "Italy");
147   public final static CountryCode SWITZERLAND =
148     new CountryCode(0x29, "CH", "Switzerland");
149   public final static CountryCode UK =
150     new CountryCode(0x2c, "UK", "United Kingdowm");
151   public final static CountryCode DENMARK =
152     new CountryCode(0x2d, "DK", "Denmark");
153   public final static CountryCode SWEDEN =
154     new CountryCode(0x2e, "SE", "Sweden");
155   public final static CountryCode NORWAY =
156     new CountryCode(0x2f, "NO", "Norway");
157   public final static CountryCode GERMANY =
158     new CountryCode(0x31, "DE", "Germany");
159   public final static CountryCode PHILIPPINES =
160     new CountryCode(0x3f, "PH", "Philippines");
161   public final static CountryCode CHINA =
162     new CountryCode(0x56, "CN", "China");
163   public final static CountryCode INDIA =
164     new CountryCode(0x5b, "IN", "India");
165   public final static CountryCode UNKNOWN =
166     new CountryCode(0xffff, "??", "Unknown");
167 }
168
Popular Tags