/** * Returns the system's installed time zone IDs. Any of these IDs can be * passed to {@link #getTimeZone} to lookup the corresponding time zone * instance. */ public static synchronized String[] getAvailableIDs() { return ZoneInfoDB.getInstance().getAvailableIDs(); }
/** * Returns a shared, mutable array containing the constants of this enum. It * is an error to modify the returned array. * * @hide */ @SuppressWarnings("unchecked") // the cache always returns the type matching enumType public static <T extends Enum<T>> T[] getSharedConstants(Class<T> enumType) { return (T[]) sharedConstantsCache.get(enumType); }
/** * Clear the cache, calling {@link #entryEvicted} on each removed entry. */ public synchronized final void evictAll() { trimToSize(0); } }
@Override public boolean equals(Object obj) { if (!(obj instanceof ZoneInfo)) { return false; } ZoneInfo other = (ZoneInfo) obj; return getID().equals(other.getID()) && hasSameRules(other); }
public static String getBestDateTimePattern(String skeleton, String localeName) { String key = skeleton + "\t" + localeName; synchronized (CACHED_PATTERNS) { String pattern = CACHED_PATTERNS.get(key); if (pattern == null) { pattern = getBestDateTimePatternNative(skeleton, localeName); CACHED_PATTERNS.put(key, pattern); } return pattern; } }
public static void sneakyThrow(Throwable t) { SneakyThrow.<Error>sneakyThrow2(t); }
/** * Records that 'hostname' is known not to have any associated addresses. (I.e. insert a * negative cache entry.) */ public void putUnknownHost(String hostname, String detailMessage) { cache.put(hostname, new AddressCacheEntry(detailMessage)); } }
/** * Removes all entries from the cache. */ public void clear() { cache.evictAll(); }
@Override public String toString() { return Objects.toString(this); }
@Override public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis) { // XXX This assumes Gregorian always; Calendar switches from // Julian to Gregorian in 1582. What calendar system are the // arguments supposed to come from? long calc = (year / 400) * MILLISECONDS_PER_400_YEARS; year %= 400; calc += year * (365 * MILLISECONDS_PER_DAY); calc += ((year + 3) / 4) * MILLISECONDS_PER_DAY; if (year > 0) { calc -= ((year - 1) / 100) * MILLISECONDS_PER_DAY; } boolean isLeap = (year == 0 || (year % 4 == 0 && year % 100 != 0)); int[] mlen = isLeap ? LEAP : NORMAL; calc += mlen[month] * MILLISECONDS_PER_DAY; calc += (day - 1) * MILLISECONDS_PER_DAY; calc += millis; calc -= mRawOffset; calc -= UNIX_OFFSET; return getOffset(calc); }
public TzDataAndroid(String... paths) { for (String path : paths) { if (loadData(path)) { return; } } // We didn't find any usable tzdata on disk, so let's just hard-code knowledge of "GMT". // This is actually implemented in TimeZone itself, so if this is the only time zone // we report, we won't be asked any more questions. System.logE("Couldn't find any tzdata!"); version = "missing"; zoneTab = "# Emergency fallback data.\n"; ids = new String[] { "GMT" }; byteOffsets = rawUtcOffsets = new int[1]; }
public TimeZone makeTimeZone(String id) throws IOException { return makeTimeZone(id, true); }
@Implementation protected static Object getInstance() { return TimeZoneFinder.createInstanceForTests(readTzlookup()); }
/** * Returns the IDs of the time zones whose offset from UTC is {@code * offsetMillis}. Any of these IDs can be passed to {@link #getTimeZone} to * lookup the corresponding time zone instance. * * @return a possibly-empty array. */ public static synchronized String[] getAvailableIDs(int offsetMillis) { return ZoneInfoDB.getInstance().getAvailableIDs(offsetMillis); }
/** * Returns true if {@code pattern} equals either "*" or {@code s}. Pattern * may be {@code null}. */ private static boolean matchesNameOrWildcard(String pattern, String s) { return "*".equals(pattern) || Objects.equal(pattern, s); } }
/** * Returns the cached InetAddress[] associated with 'hostname'. Returns null if nothing is known * about 'hostname'. Returns a String suitable for use as an UnknownHostException detail * message if 'hostname' is known not to exist. */ public Object get(String hostname) { AddressCacheEntry entry = cache.get(hostname); // Do we have a valid cache entry? if (entry != null && entry.expiryNanos >= System.nanoTime()) { return entry.value; } // Either we didn't find anything, or it had expired. // No need to remove expired entries: the caller will provide a replacement shortly. return null; }
/** * Associates the given 'addresses' with 'hostname'. The association will expire after a * certain length of time. */ public void put(String hostname, InetAddress[] addresses) { cache.put(hostname, new AddressCacheEntry(addresses)); }