本文整理汇总了Java中com.ibm.icu.util.TimeZone.getAvailableIDs方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.getAvailableIDs方法的具体用法?Java TimeZone.getAvailableIDs怎么用?Java TimeZone.getAvailableIDs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.icu.util.TimeZone
的用法示例。
在下文中一共展示了TimeZone.getAvailableIDs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findLocal
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Returns a collection of time zone display name matches for the specified types in the
* given text at the given offset. This method only finds matches from the local trie,
* that contains 1) generic location names and 2) long/short generic partial location names,
* used by this object.
* @param text the text
* @param start the start offset in the text
* @param types the set of name types.
* @return A collection of match info.
*/
private synchronized Collection<GenericMatchInfo> findLocal(String text, int start, EnumSet<GenericNameType> types) {
GenericNameSearchHandler handler = new GenericNameSearchHandler(types);
_gnamesTrie.find(text, start, handler);
if (handler.getMaxMatchLen() == (text.length() - start) || _gnamesTrieFullyLoaded) {
// perfect match
return handler.getMatches();
}
// All names are not yet loaded into the local trie.
// Load all available names into the trie. This could be very heavy.
Set<String> tzIDs = TimeZone.getAvailableIDs(SystemTimeZoneType.CANONICAL, null, null);
for (String tzID : tzIDs) {
loadStrings(tzID);
}
_gnamesTrieFullyLoaded = true;
// now, try it again
handler.resetResults();
_gnamesTrie.find(text, start, handler);
return handler.getMatches();
}
示例2: getZoneStrings
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Returns time zone strings.
* <p>
* The array returned by this API is a two dimensional String array and
* each row contains at least following strings:
* <ul>
* <li>ZoneStrings[n][0] - System time zone ID
* <li>ZoneStrings[n][1] - Long standard time display name
* <li>ZoneStrings[n][2] - Short standard time display name
* <li>ZoneStrings[n][3] - Long daylight saving time display name
* <li>ZoneStrings[n][4] - Short daylight saving time display name
* </ul>
* When a localized display name is not available, the corresponding
* array element will be <code>null</code>.
* <p>
* <b>Note</b>: ICU implements the time zone display name formatting algorithm
* specified by <a href="http://www.unicode.org/reports/tr35/">UTS#35 Unicode
* Locale Data Markup Language(LDML)</a>. The algorithm supports historic
* display name changes and various different types of names not available in
* {@link java.text.DateFormatSymbols#getZoneStrings()}. For accessing the full
* set of time zone string data used by ICU implementation, you should use
* {@link TimeZoneNames} APIs instead.
*
* @return the time zone strings.
* @stable ICU 2.0
*/
public String[][] getZoneStrings() {
if (zoneStrings != null) {
return duplicate(zoneStrings);
}
String[] tzIDs = TimeZone.getAvailableIDs();
TimeZoneNames tznames = TimeZoneNames.getInstance(validLocale);
tznames.loadAllDisplayNames();
NameType types[] = {
NameType.LONG_STANDARD, NameType.SHORT_STANDARD,
NameType.LONG_DAYLIGHT, NameType.SHORT_DAYLIGHT
};
long now = System.currentTimeMillis();
String[][] array = new String[tzIDs.length][5];
for (int i = 0; i < tzIDs.length; i++) {
String canonicalID = TimeZone.getCanonicalID(tzIDs[i]);
if (canonicalID == null) {
canonicalID = tzIDs[i];
}
array[i][0] = tzIDs[i];
tznames.getDisplayNames(canonicalID, types, now, array[i], 1);
}
zoneStrings = array;
return zoneStrings;
}
示例3: parseZoneID
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Parse a zone ID.
* @param text the text contains a time zone ID string at the position.
* @param pos the position.
* @return The zone ID parsed.
*/
private static String parseZoneID(String text, ParsePosition pos) {
String resolvedID = null;
if (ZONE_ID_TRIE == null) {
synchronized (TimeZoneFormat.class) {
if (ZONE_ID_TRIE == null) {
// Build zone ID trie
TextTrieMap<String> trie = new TextTrieMap<String>(true);
String[] ids = TimeZone.getAvailableIDs();
for (String id : ids) {
trie.put(id, id);
}
ZONE_ID_TRIE = trie;
}
}
}
int[] matchLen = new int[] {0};
Iterator<String> itr = ZONE_ID_TRIE.get(text, pos.getIndex(), matchLen);
if (itr != null) {
resolvedID = itr.next();
pos.setIndex(pos.getIndex() + matchLen[0]);
} else {
// TODO
// We many need to handle rule based custom zone ID (See ZoneMeta.parseCustomID),
// such as GM+05:00. However, the public parse method in this class also calls
// parseOffsetLocalizedGMT and custom zone IDs are likely supported by the parser,
// so we might not need to handle them here.
pos.setErrorIndex(pos.getIndex());
}
return resolvedID;
}
示例4: parseShortZoneID
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Parse a short zone ID.
* @param text the text contains a time zone ID string at the position.
* @param pos the position.
* @return The zone ID for the parsed short zone ID.
*/
private static String parseShortZoneID(String text, ParsePosition pos) {
String resolvedID = null;
if (SHORT_ZONE_ID_TRIE == null) {
synchronized (TimeZoneFormat.class) {
if (SHORT_ZONE_ID_TRIE == null) {
// Build short zone ID trie
TextTrieMap<String> trie = new TextTrieMap<String>(true);
Set<String> canonicalIDs = TimeZone.getAvailableIDs(SystemTimeZoneType.CANONICAL, null, null);
for (String id : canonicalIDs) {
String shortID = ZoneMeta.getShortID(id);
if (shortID != null) {
trie.put(shortID, id);
}
}
// Canonical list does not contain Etc/Unknown
trie.put(UNKNOWN_SHORT_ZONE_ID, UNKNOWN_ZONE_ID);
SHORT_ZONE_ID_TRIE = trie;
}
}
}
int[] matchLen = new int[] {0};
Iterator<String> itr = SHORT_ZONE_ID_TRIE.get(text, pos.getIndex(), matchLen);
if (itr != null) {
resolvedID = itr.next();
pos.setIndex(pos.getIndex() + matchLen[0]);
} else {
pos.setErrorIndex(pos.getIndex());
}
return resolvedID;
}
示例5: createRightComponent
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
private void createRightComponent( Composite composite )
{
Label formatLabel = new Label( composite, SWT.CENTER | SWT.SINGLE );
formatLabel.setText( LABEL_FORMAT );
formatLabel.setBounds( 0, 8, 60, 30 );
combo = new Combo( composite, SWT.READ_ONLY | SWT.DROP_DOWN );
List list = TimeFormat.getDefaultFormat( ).getSupportList( );
String[] items = new String[list.size( )];
list.toArray( items );
combo.setBounds( 60, 2, 150, 30 );
combo.setVisibleItemCount( 30 );
combo.setItems( items );
combo.select( 0 );
Label zoneLabel = new Label( composite, SWT.CENTER );
zoneLabel.setText( LABEL_TIMEZONE );
zoneLabel.setBounds( 0, 108, 60, 30 );
zoneCombo = new Combo( composite, SWT.READ_ONLY | SWT.SINGLE );
zoneCombo.setVisibleItemCount( 30 );
items = TimeZone.getAvailableIDs( );
zoneCombo.setBounds( 60, 102, 150, 30 );
zoneCombo.setItems( items );
zoneCombo.select( 0 );
}
示例6: getWindowsTimeZoneIDForSysTimeZoneIDs
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
@Test
public void getWindowsTimeZoneIDForSysTimeZoneIDs(){
int validZonesCount = 0;
String[] availableIDs = TimeZone.getAvailableIDs();
for(String sysTimeZoneID : availableIDs){
String windowsID = TimeZone.getWindowsID(sysTimeZoneID);
if(null != windowsID){
log.info(sysTimeZoneID+" maps to "+windowsID);
validZonesCount++;
}else{
log.warn("NO MAPPING FOR "+sysTimeZoneID);
}
}
log.info(validZonesCount +"/"+availableIDs.length +" system time zone ids can be mapped to a windows time zone id");
}
示例7: getCanonicalCountry
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
/**
* Return the canonical country code for this tzid. If we have none, or if the time zone
* is not associated with a country or unknown, return null. When the given zone is the
* primary zone of the country, true is set to isPrimary.
*/
public static String getCanonicalCountry(String tzid, Output<Boolean> isPrimary) {
isPrimary.value = Boolean.FALSE;
String country = getRegion(tzid);
if (country != null && country.equals(kWorld)) {
return null;
}
// Check the cache
Boolean singleZone = SINGLE_COUNTRY_CACHE.get(tzid);
if (singleZone == null) {
Set<String> ids = TimeZone.getAvailableIDs(SystemTimeZoneType.CANONICAL_LOCATION, country, null);
assert(ids.size() >= 1);
singleZone = Boolean.valueOf(ids.size() <= 1);
SINGLE_COUNTRY_CACHE.put(tzid, singleZone);
}
if (singleZone) {
isPrimary.value = Boolean.TRUE;
} else {
// Note: We may cache the primary zone map in future.
// Even a country has multiple zones, one of them might be
// dominant and treated as a primary zone.
try {
UResourceBundle bundle = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "metaZones");
UResourceBundle primaryZones = bundle.get("primaryZones");
String primaryZone = primaryZones.getString(country);
if (tzid.equals(primaryZone)) {
isPrimary.value = Boolean.TRUE;
} else {
// The given ID might not be a canonical ID
String canonicalID = getCanonicalCLDRID(tzid);
if (canonicalID != null && canonicalID.equals(primaryZone)) {
isPrimary.value = Boolean.TRUE;
}
}
} catch (MissingResourceException e) {
// ignore
}
}
return country;
}
示例8: find
import com.ibm.icu.util.TimeZone; //导入方法依赖的package包/类
@Override
public synchronized Collection<MatchInfo> find(CharSequence text, int start, EnumSet<NameType> nameTypes) {
if (text == null || text.length() == 0 || start < 0 || start >= text.length()) {
throw new IllegalArgumentException("bad input text or range");
}
NameSearchHandler handler = new NameSearchHandler(nameTypes);
Collection<MatchInfo> matches;
// First try of lookup.
matches = doFind(handler, text, start);
if (matches != null) {
return matches;
}
// All names are not yet loaded into the trie.
// We may have loaded names for formatting several time zones,
// and might be parsing one of those.
// Populate the parsing trie from all of the already-loaded names.
addAllNamesIntoTrie();
// Second try of lookup.
matches = doFind(handler, text, start);
if (matches != null) {
return matches;
}
// There are still some names we haven't loaded into the trie yet.
// Load everything now.
internalLoadAllDisplayNames();
// Set default time zone location names
// for time zones without explicit display names.
// TODO: Should this logic be moved into internalLoadAllDisplayNames?
Set<String> tzIDs = TimeZone.getAvailableIDs(SystemTimeZoneType.CANONICAL, null, null);
for (String tzID : tzIDs) {
if (!_tzNamesMap.containsKey(tzID)) {
ZNames.createTimeZoneAndPutInCache(_tzNamesMap, null, tzID);
}
}
addAllNamesIntoTrie();
_namesTrieFullyLoaded = true;
// Third try: we must return this one.
return doFind(handler, text, start);
}