ewe.sys
Class Locale

java.lang.Object
  extended byewe.sys.Locale

public class Locale
extends Object


Field Summary
static int AM_PM
          Use with getString()/fromString() - The full name of the AM/PM.
static int COUNTRY
          Use with getString() - The full name of the locale country.
static int COUNTRY_ENGLISH
          Use with getString() - The full English name of the locale country.
static int COUNTRY_NATIVE
          Use with getString() - The full native name of the locale country.
static int COUNTRY_SHORT
          Use with getString() - The three letter (uppercase) ISO country code.
static int CURRENCY
          Use with getString()/fromString() - Gets the currencty symbol.
static int DATE_SEPARATOR
          Use with getString() - The character(s) for the date separator.
static int DAY
          Use with getString()/fromString() - The full name of the day which is equivalent to Monday to Sunday, where 1 == Monday, 2 == Tuesday.
static int DAY_OF_WEEK
          Use with getString()/fromString() - The full name of a DAY IN THE WEEK.
static int defaultID
          This is the ID to use as the default locale identifier.
static int FIRST_DAY_OF_WEEK
          Use with getString() - The index of the first day of the week where 1 = Monday, 2 = Tuesday, ...
static int FORCE_CREATION
          This is an options for createFor() it tells the system to create a Locale that always reports the specified language and country even if the Locale is not actually supported by the underlying system.
static int FORMAT_PARSE_CURRENCY
          Parameter for format() or parse() method, used when formating/parsing a currency value.
static int FORMAT_PARSE_DATE
          Deprecated. use a Time value and set its format to be the value returned by getString() for TIME_FORMAT or DATE_FORMAT or LONG_DATE_FORMAT, and then request that Time value to convert itself to a String or to read from a String.
static int FORMAT_PARSE_NUMBER
          Parameter for format() or parse() method, used when formating/parsing a numeric value.
static int HAS_WILD_CARDS
          A compare option.
static int IGNORE_CASE
          An option for getStringComparer.
static int IGNORE_NONSPACE
          An option for getStringComparer.
static int IGNORE_SYMBOLS
          An option for getStringComparer.
static int LANGUAGE
          Use with getString() - The full name of the locale language.
static int LANGUAGE_ENGLISH
          Use with getString() - The ISO English name of the locale language.
static int LANGUAGE_NATIVE
          Use with getString() - The full native name of the locale language.
static int LANGUAGE_SHORT
          Use with getString() - The ISO two letter (lowercase) name of the locale language.
static int LOCALE_NEUTRAL
          This is the native Win32 definition of a Neutral locale ID.
static int LOCALE_SYSTEM_DEFAULT
          This is the native Win32 definition of the system default locale ID.
static int LOCALE_USER_DEFAULT
          This is the native Win32 definition of the user default locale ID.
static int LONG_DATE_FORMAT
          Use with getString() - The format for the long date display.
static int MONTH
          Use with getString()/fromString() - The full name of a month.
static int MONTH_YEAR_FORMAT
          Use with getString() - The correct format for displaying month and year only.
protected  int myLocalID
          Do not use or move this variable.
static int NO_ROUNDING
          Option for format() method when using FORMAT_PARSE_CURRENCY or FORMAT_PARSE_NUMBER It specifies not to round up the last decimal digit.
static int SHORT_DATE_FORMAT
          Use with getString() - The format for the short date display.
static int SHORT_DAY
          Use with getString()/fromString() - The short name of the day which is equivalent to Monday to Sunday, where 1 == Monday, 2 == Tuesday.
static int SHORT_DAY_OF_WEEK
          Use with getString()/fromString() - The short name of a DAY IN THE WEEK.
static int SHORT_MONTH
          Use with getString()/fromString() - The short name of a month.
static int TIME_FORMAT
          Use with getString() - The format for the time display.
static int TIME_SEPARATOR
          Use with getString() - The character(s) for the time separator.
static String unknownString
          This is the value that will be returned by getString() in some instances if the value is not known.
 
Constructor Summary
Locale()
          Creates a new default Locale object.
Locale(boolean dontSetId)
          This creates a Locale without an ID.
Locale(int id)
          Creates a new Locale object with the specified ID.
Locale(String language, String country, boolean forceSupport)
          Create a Locale for the specified language and optional country.
 
Method Summary
 void changeCase(char[] ch, int start, int length, boolean toUpper)
          This converts the character array to either upper case or lower case.
 char changeCase(char c, boolean toUpper)
          This converts the character to either upper case or lower case.
 int compare(char[] one, int oneOffset, int oneLength, char[] two, int twoOffset, int twoLength, int options)
          Compare two sections of character arrays.
 int compare(char one, char two, int options)
          Compare two characters.
 int compare(String one, String two, int options)
          Compare two strings.
static String convertCountryCode(String countryCode)
          This will convert a three letter (uppercase) ISO country code to the two letter (uppercase) ISO country code OR the other way.
static Locale createFor(String language, String country, int options)
           
static int createID(String language, String country, int options)
          This should create a locale ID based on the ISO two character language and country codes.
 String format(int what, Object value, Object layout)
          This is for formatting number/currency values etc.
 int fromString(int what, String str, int options)
          This is the reverse of getString() - it takes a locale dependent string and returns the value associated with it.
static int[] getAllIDs(int options)
          Get an array of all supported Locale IDs
 int getCalendarForMonth(Time time, int[] dayOfWeekLayout, int[] dayOfMonthLayout, boolean wrapAround)
          Get the calendar layout for the month/year that the specified Time is currently set for.
static Locale getDefault()
           
 LocalResource getLocalResource(String moduleName, boolean returnNullIfNotFound)
          This returns an object which implements LocalResource.
 String getString(int what, int forValue, int options)
          This is used to retrieve locale specific information as a String.
 Comparer getStringComparer(int options)
          Get a locale specific string comparer.
 boolean parse(String source, int what, Object value, Object layout)
          This is for parse number/currency values etc.
 void set(int id)
          Set the ID for this locale.
static boolean setDefault(String language, String country, int options)
          This attempts to set what the default language and (optionally) country for the application.
 String toString()
          Return a String representation of this object.
static boolean unknown(String value)
          This checks if the value is either null or the unknownString.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode
 

Field Detail

myLocalID

protected int myLocalID
Do not use or move this variable.


MONTH

public static final int MONTH
Use with getString()/fromString() - The full name of a month. forValue parameter must be in the range 1 to 12.

See Also:
Constant Field Values

SHORT_MONTH

public static final int SHORT_MONTH
Use with getString()/fromString() - The short name of a month. forValue parameter must be in the range 1 to 12.

See Also:
Constant Field Values

DAY_OF_WEEK

public static final int DAY_OF_WEEK
Use with getString()/fromString() - The full name of a DAY IN THE WEEK. forValue parameter must be in the range 1 to 7. A value of 1 implies the first day of the week. This may be the equivalent of Monday or Sunday (or Saturday?).

See Also:
Constant Field Values

SHORT_DAY_OF_WEEK

public static final int SHORT_DAY_OF_WEEK
Use with getString()/fromString() - The short name of a DAY IN THE WEEK. forValue parameter must be in the range 1 to 7. A value of 1 implies the first day of the week. This may be the equivalent of Monday or Sunday (or Saturday?).

See Also:
Constant Field Values

CURRENCY

public static final int CURRENCY
Use with getString()/fromString() - Gets the currencty symbol.

See Also:
Constant Field Values

AM_PM

public static final int AM_PM
Use with getString()/fromString() - The full name of the AM/PM. forValue parameter must be in the range 0 to 1.

See Also:
Constant Field Values

DAY

public static final int DAY
Use with getString()/fromString() - The full name of the day which is equivalent to Monday to Sunday, where 1 == Monday, 2 == Tuesday. etc. forValue parameter must be in the range 1 (Monday) to 7 (Sunday).

See Also:
Constant Field Values

SHORT_DAY

public static final int SHORT_DAY
Use with getString()/fromString() - The short name of the day which is equivalent to Monday to Sunday, where 1 == Monday, 2 == Tuesday. etc. forValue parameter must be in the range 1 (Monday) to 7 (Sunday).

See Also:
Constant Field Values

FIRST_DAY_OF_WEEK

public static final int FIRST_DAY_OF_WEEK
Use with getString() - The index of the first day of the week where 1 = Monday, 2 = Tuesday, ... 7 = Sunday. The value returned by getString() will be a text formatted decimal value, use ewe.sys.Convert.toInt() to convert it to an integer.

See Also:
Constant Field Values

LANGUAGE

public static final int LANGUAGE
Use with getString() - The full name of the locale language.

See Also:
Constant Field Values

LANGUAGE_ENGLISH

public static final int LANGUAGE_ENGLISH
Use with getString() - The ISO English name of the locale language.

See Also:
Constant Field Values

LANGUAGE_NATIVE

public static final int LANGUAGE_NATIVE
Use with getString() - The full native name of the locale language.

See Also:
Constant Field Values

LANGUAGE_SHORT

public static final int LANGUAGE_SHORT
Use with getString() - The ISO two letter (lowercase) name of the locale language.

See Also:
Constant Field Values

TIME_SEPARATOR

public static final int TIME_SEPARATOR
Use with getString() - The character(s) for the time separator.

See Also:
Constant Field Values

DATE_SEPARATOR

public static final int DATE_SEPARATOR
Use with getString() - The character(s) for the date separator.

See Also:
Constant Field Values

TIME_FORMAT

public static final int TIME_FORMAT
Use with getString() - The format for the time display.

See Also:
Constant Field Values

SHORT_DATE_FORMAT

public static final int SHORT_DATE_FORMAT
Use with getString() - The format for the short date display.

See Also:
Constant Field Values

LONG_DATE_FORMAT

public static final int LONG_DATE_FORMAT
Use with getString() - The format for the long date display.

See Also:
Constant Field Values

MONTH_YEAR_FORMAT

public static final int MONTH_YEAR_FORMAT
Use with getString() - The correct format for displaying month and year only.

See Also:
Constant Field Values

COUNTRY

public static final int COUNTRY
Use with getString() - The full name of the locale country.

See Also:
Constant Field Values

COUNTRY_ENGLISH

public static final int COUNTRY_ENGLISH
Use with getString() - The full English name of the locale country.

See Also:
Constant Field Values

COUNTRY_NATIVE

public static final int COUNTRY_NATIVE
Use with getString() - The full native name of the locale country.

See Also:
Constant Field Values

COUNTRY_SHORT

public static final int COUNTRY_SHORT
Use with getString() - The three letter (uppercase) ISO country code.

See Also:
Constant Field Values

FORMAT_PARSE_NUMBER

public static final int FORMAT_PARSE_NUMBER
Parameter for format() or parse() method, used when formating/parsing a numeric value.

See Also:
Constant Field Values

FORMAT_PARSE_CURRENCY

public static final int FORMAT_PARSE_CURRENCY
Parameter for format() or parse() method, used when formating/parsing a currency value.

See Also:
Constant Field Values

FORMAT_PARSE_DATE

public static final int FORMAT_PARSE_DATE
Deprecated. use a Time value and set its format to be the value returned by getString() for TIME_FORMAT or DATE_FORMAT or LONG_DATE_FORMAT, and then request that Time value to convert itself to a String or to read from a String.

Parameter for format() or parse() method, used when formating/parsing a date value.

See Also:
Constant Field Values

NO_ROUNDING

public static final int NO_ROUNDING
Option for format() method when using FORMAT_PARSE_CURRENCY or FORMAT_PARSE_NUMBER It specifies not to round up the last decimal digit. This option cannot be placed in the string format specifier.

See Also:
Constant Field Values

LOCALE_NEUTRAL

public static final int LOCALE_NEUTRAL
This is the native Win32 definition of a Neutral locale ID.

See Also:
Constant Field Values

LOCALE_USER_DEFAULT

public static final int LOCALE_USER_DEFAULT
This is the native Win32 definition of the user default locale ID.

See Also:
Constant Field Values

LOCALE_SYSTEM_DEFAULT

public static final int LOCALE_SYSTEM_DEFAULT
This is the native Win32 definition of the system default locale ID.

See Also:
Constant Field Values

defaultID

public static int defaultID
This is the ID to use as the default locale identifier. It is initially set to LOCALE_USER_DEFAULT, but it can be changed to any other.


unknownString

public static final String unknownString
This is the value that will be returned by getString() in some instances if the value is not known.

See Also:
Constant Field Values

FORCE_CREATION

public static final int FORCE_CREATION
This is an options for createFor() it tells the system to create a Locale that always reports the specified language and country even if the Locale is not actually supported by the underlying system.

See Also:
Constant Field Values

IGNORE_CASE

public static final int IGNORE_CASE
An option for getStringComparer.

See Also:
Constant Field Values

IGNORE_NONSPACE

public static final int IGNORE_NONSPACE
An option for getStringComparer.

See Also:
Constant Field Values

IGNORE_SYMBOLS

public static final int IGNORE_SYMBOLS
An option for getStringComparer.

See Also:
Constant Field Values

HAS_WILD_CARDS

public static final int HAS_WILD_CARDS
A compare option.

See Also:
Constant Field Values
Constructor Detail

Locale

public Locale(boolean dontSetId)
This creates a Locale without an ID. Don't attempt to use it unless you call set(int id) on it.


Locale

public Locale(String language,
              String country,
              boolean forceSupport)
       throws IllegalArgumentException
Create a Locale for the specified language and optional country. Additional verbose

Parameters:
language - The two letter lower case language specifier (e.g. "en").
country - The three letter upper case country specifier (e.g. "GBR"). This may be null.
forceSupport - If the specified language/country is not supported usually an IllegalArgumentException will be thrown. However if this is true then a Locale will still be created, but it will only be able to report its COUNTRY_SHORT and LANGUAGE_SHORT values (which will be same as the language and country parameters).
Throws:
IllegalArgumentException - If the specified language/country is not supported and forceSupport is false.

Locale

public Locale()
Creates a new default Locale object.


Locale

public Locale(int id)
Creates a new Locale object with the specified ID. This should be used only with LOCALE_USER_DEFAULT and LOCALE_SYSTEM_DEFAULT.

Parameters:
id - the ID to use for this locale.
See Also:
set(int)
Method Detail

unknown

public static boolean unknown(String value)
This checks if the value is either null or the unknownString.


getDefault

public static Locale getDefault()

setDefault

public static boolean setDefault(String language,
                                 String country,
                                 int options)
This attempts to set what the default language and (optionally) country for the application.

Parameters:
language - The two letter language code.
country - The three letter country code (optional).
options - If FORCE_CREATION is used as an option BUT the specified language/country does is not supported, then the default locale will still report this language and country as its language and country but will not be able to provide any other info or services.
Returns:
true if successful, false if the specified language and country is not supported AND forceSupport is false.

set

public void set(int id)
Set the ID for this locale. Effectively this changes the locale information you will get from this locale on systems that support this.

Parameters:
id - the ID to use for this locale.

convertCountryCode

public static String convertCountryCode(String countryCode)
This will convert a three letter (uppercase) ISO country code to the two letter (uppercase) ISO country code OR the other way. It will return an empty string if no conversion was found.


createID

public static int createID(String language,
                           String country,
                           int options)
This should create a locale ID based on the ISO two character language and country codes. It will return -1 if it cannot create the ID. If you are creating an ID so that you can create a new Locale, then it is better to use createFor().

Parameters:
language - the ISO-639 two character language specifier.
country - the ISO-3166 three character country specifier - this can be null and the first locale with the specified language will be used.
options - options for creating the ID. None are defined yet.
Returns:
the ID if successful, -1 if not.

createFor

public static Locale createFor(String language,
                               String country,
                               int options)
Parameters:
language - the ISO-639 two character language specifier.
country - the ISO-3166 three character country specifier - this can be null and the first locale with the specified language will be used.
options - options for creating the ID. The only supported option is FORCE_CREATION
Returns:
a new Locale if successful, null if not.

getString

public String getString(int what,
                        int forValue,
                        int options)
This is used to retrieve locale specific information as a String. Numeric values will be returned as text encoded.

Parameters:
what - should be one of MONTH, SHORT_MONTH, etc.
forValue - should be a value relative to the "what" parameter. e.g. if (what == MONTH) value should be a number for 1 to 12.
options - options for getting the information. None are defined yet.

fromString

public int fromString(int what,
                      String str,
                      int options)
This is the reverse of getString() - it takes a locale dependent string and returns the value associated with it. You use this to parse locale dependent strings.

Parameters:
what - should be one of MONTH, SHORT_MONTH, DAY, SHORT_DAY or AM_PM
str - should be a string to parse.
options - options for getting the information. None are defined yet.
Returns:

format

public String format(int what,
                     Object value,
                     Object layout)
This is for formatting number/currency values etc. "value" should either be a Long for holding integer values or a Double for holding floating point values. "layout" will in most cases be a String holding a layout pattern.

Parameters:
what - one of FORMAT_PARSE_NUMBER or FORMAT_PARSE_CURRENCY constants.
value - this should be a ewe.sys.Long() for all integer values or a ewe.sys.Double() for all floating point values.
layout - This should be String that holds the following characters:
'$' indicates that a currency symbol should be used.
',' indicates that thousands groupings should be used.
'.' separates formatting before the decimal point and after the decimal point.
'0' before the decimal point indicates the number of digits before the decimal point.
'0' after the decimal point indicates the number of digits after the decimal point.
'#' after the decimal point indicates no fixed number of digits after the decimal point.

Examples include: ",.#", "$,0000.00"

Returns:
The formatted number/currency.

parse

public boolean parse(String source,
                     int what,
                     Object value,
                     Object layout)
This is for parse number/currency values etc. "value" should either be a Long for holding integer values or a Double for holding floating point values. "layout" will in most cases be a String holding a layout pattern.

Parameters:
what - one of FORMAT_PARSE_NUMBER or FORMAT_PARSE_CURRENCY constants.
value - this should be a ewe.sys.Long() for all integer values or a ewe.sys.Double() for all floating point values.
layout - This should be String that holds the following characters:
'$' indicates that a currency symbol should be used.
',' indicates that thousands groupings should be used.
'.' separates formatting before the decimal point and after the decimal point.
'0' before the decimal point indicates the number of digits before the decimal point.
'0' after the decimal point indicates the number of digits after the decimal point.
'#' after the decimal point indicates no fixed number of digits after the decimal point.

Examples include: ",.#", "$,0000.00"

Returns:
true if successful.

getStringComparer

public Comparer getStringComparer(int options)
Get a locale specific string comparer.

Parameters:
options - IGNORE_CASE, IGNORE_NONSPACE, IGNORE_SYMBOLS possibly OR'ed together.
Returns:
A Comparer.

getAllIDs

public static int[] getAllIDs(int options)
Get an array of all supported Locale IDs

Parameters:
options - None defined yet.
Returns:
An array of all supported Locale IDs.

compare

public int compare(char one,
                   char two,
                   int options)
Compare two characters.

Parameters:
one - A character
two - A character
options - IGNORE_CASE.
Returns:
Greater than 0 if one is greater than two, less than 0 if two is less than one, 0 if they are equal.

compare

public int compare(char[] one,
                   int oneOffset,
                   int oneLength,
                   char[] two,
                   int twoOffset,
                   int twoLength,
                   int options)
Compare two sections of character arrays.

Parameters:
one - The first array.
oneOffset - The start index.
oneLength - The number of characters to compare.
two - The second array.
twoOffset - The start index.
twoLength - The number of characters to compare.
options - IGNORE_CASE, IGNORE_NONSPACE, IGNORE_SYMBOLS, HAS_WILD_CARDS.
Returns:
Greater than 0 if one is greater than two, less than 0 if two is less than one, 0 if they are equal.

compare

public int compare(String one,
                   String two,
                   int options)
Compare two strings.

Parameters:
one - The first String.
two - The second String
options - IGNORE_CASE, IGNORE_NONSPACE, IGNORE_SYMBOLS, HAS_WILD_CARDS.
Returns:
Greater than 0 if one is greater than two, less than 0 if two is less than one, 0 if they are equal.

changeCase

public char changeCase(char c,
                       boolean toUpper)
This converts the character to either upper case or lower case.


changeCase

public void changeCase(char[] ch,
                       int start,
                       int length,
                       boolean toUpper)
This converts the character array to either upper case or lower case.


getLocalResource

public LocalResource getLocalResource(String moduleName,
                                      boolean returnNullIfNotFound)
This returns an object which implements LocalResource. If local resources for the specified moduleName is not found it will return null if returnNullIfNotFound is true, otherwise it will return a LocalResource object that always returns the default object value for each call to getLocalResource().


toString

public String toString()
Description copied from class: Object
Return a String representation of this object.

Overrides:
toString in class Object
Returns:
a String representing this object.

getCalendarForMonth

public int getCalendarForMonth(Time time,
                               int[] dayOfWeekLayout,
                               int[] dayOfMonthLayout,
                               boolean wrapAround)
Get the calendar layout for the month/year that the specified Time is currently set for.

Parameters:
time - the Time specifying the month and year required.
dayOfWeekLayout - an array of 7 ints which will contain values from 1 = Monday to 7 = Sunday in the appropriate location for the day of the week for the locale. The value at index 0 will be the first day of the week in this locale (which may be Monday, Sunday or possibly Saturday).
dayOfMonthLayout - an array of 35 or 42 integers where the values 1 to 31 will be stored with 1 being stored within the range 0 to 6 depending on what day it is in. The values 2, 3 etc will follow sequentially from 1. It is possible that the values 31 and 30 may wrap around and be placed at indexes 0 and 1 if wrapAround is true. Locations where there are no days will be set to 0.
wrapAround - if this is true then if the index of values 31 and/or 30 exceed 35 then they will be wrapped to 0.
Returns:
the number of days in the month or 0 if there is a problem with the supplied Time.