From 75672f0b3ac006737b954a7f92a97216986803cf Mon Sep 17 00:00:00 2001 From: Andrew John Hughes Date: Thu, 9 Aug 2012 10:49:31 +0100 Subject: Fix warnings in java.util.TimeZone. 2012-08-09 Andrew John Hughes * java/util/TimeZone.java: (defaultZone()): Use parameterized PrivilegedAction. (aliases0): Add type parameters. (timezones0); Likewise. (timezones()): Likewise. (getDateParams(String)): Fix indenting. (getTimeZoneInternal(String)): Remove redundant casts. (getAvailableIDs(int)): Add type parameters. (getAvailableIDs(File,String,ArrayList)): Likewise. (getAvailableIDs()): Likewise. Signed-off-by: Andrew John Hughes --- ChangeLog | 13 ++++++++ java/util/TimeZone.java | 84 ++++++++++++++++++++++++------------------------- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74ca3616b..2591ebad1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2012-08-09 Andrew John Hughes + + * java/util/TimeZone.java: + (defaultZone()): Use parameterized PrivilegedAction. + (aliases0): Add type parameters. + (timezones0); Likewise. + (timezones()): Likewise. + (getDateParams(String)): Fix indenting. + (getTimeZoneInternal(String)): Remove redundant casts. + (getAvailableIDs(int)): Add type parameters. + (getAvailableIDs(File,String,ArrayList)): Likewise. + (getAvailableIDs()): Likewise. + 2012-07-03 Andrew John Hughes Update copyright headers throughout. diff --git a/java/util/TimeZone.java b/java/util/TimeZone.java index 8436440f8..a8b2b51cf 100644 --- a/java/util/TimeZone.java +++ b/java/util/TimeZone.java @@ -1,5 +1,5 @@ /* java.util.TimeZone - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -102,10 +102,10 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable /* Look up default timezone */ if (defaultZone0 == null) { - defaultZone0 = (TimeZone) AccessController.doPrivileged - (new PrivilegedAction() + defaultZone0 = AccessController.doPrivileged + (new PrivilegedAction() { - public Object run() + public TimeZone run() { TimeZone zone = null; @@ -146,21 +146,21 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable /** * JDK 1.1.x compatibility aliases. */ - private static HashMap aliases0; + private static HashMap aliases0; /** * HashMap for timezones by ID. */ - private static HashMap timezones0; + private static HashMap timezones0; /* initialize this static field lazily to overhead if * it is not needed: */ // Package-private to avoid a trampoline. - static HashMap timezones() + static HashMap timezones() { if (timezones0 == null) { - HashMap timezones = new HashMap(); + HashMap timezones = new HashMap(); timezones0 = timezones; zoneinfo_dir = SystemProperties.getProperty("gnu.java.util.zoneinfo.dir"); @@ -169,7 +169,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable if (zoneinfo_dir != null) { - aliases0 = new HashMap(); + aliases0 = new HashMap(); // These deprecated aliases for JDK 1.1.x compatibility // should take precedence over data files read from @@ -1152,28 +1152,28 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable // Month, week of month, day of week - // "Mm.w.d". d is between 0 (Sunday) and 6. Week w is - // between 1 and 5; Week 1 is the first week in which day d - // occurs and Week 5 specifies the last d day in the month. - // Month m is between 1 and 12. + // "Mm.w.d". d is between 0 (Sunday) and 6. Week w is + // between 1 and 5; Week 1 is the first week in which day d + // occurs and Week 5 specifies the last d day in the month. + // Month m is between 1 and 12. month = Integer.parseInt(date.substring(1, date.indexOf('.'))); int week = Integer.parseInt(date.substring(date.indexOf('.') + 1, date.lastIndexOf('.'))); int dayOfWeek = Integer.parseInt(date.substring(date.lastIndexOf('.') + 1)); - dayOfWeek++; // Java day of week is one-based, Sunday is first day. - - if (week == 5) - day = -1; // last day of month is -1 in java, 5 in TZ - else - { - // First day of week starting on or after. For example, - // to specify the second Sunday of April, set month to - // APRIL, day-of-month to 8, and day-of-week to -SUNDAY. - day = (week - 1) * 7 + 1; - dayOfWeek = -dayOfWeek; - } + dayOfWeek++; // Java day of week is one-based, Sunday is first day. + + if (week == 5) + day = -1; // last day of month is -1 in java, 5 in TZ + else + { + // First day of week starting on or after. For example, + // to specify the second Sunday of April, set month to + // APRIL, day-of-month to 8, and day-of-week to -SUNDAY. + day = (week - 1) * 7 + 1; + dayOfWeek = -dayOfWeek; + } month--; // Java month is zero-based. return new int[] { month, day, dayOfWeek }; @@ -1469,7 +1469,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable { synchronized (TimeZone.class) { - tz = (TimeZone) timezones().get(ID); + tz = timezones().get(ID); if (tz != null) { if (!tz.getID().equals(ID)) @@ -1497,7 +1497,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable // aliases0 is never changing after first timezones(), so should // be safe without synchronization. - String zonename = (String) aliases0.get(ID); + String zonename = aliases0.get(ID); if (zonename == null) zonename = ID; @@ -1605,17 +1605,17 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable { synchronized (TimeZone.class) { - HashMap h = timezones(); + HashMap h = timezones(); int count = 0; if (zoneinfo_dir == null) { - Iterator iter = h.entrySet().iterator(); + Iterator> iter = h.entrySet().iterator(); while (iter.hasNext()) { // Don't iterate the values, since we want to count // doubled values (aliases) - Map.Entry entry = (Map.Entry) iter.next(); - if (((TimeZone) entry.getValue()).getRawOffset() == rawOffset) + Map.Entry entry = iter.next(); + if (entry.getValue().getRawOffset() == rawOffset) count++; } @@ -1624,8 +1624,8 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable iter = h.entrySet().iterator(); while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); - if (((TimeZone) entry.getValue()).getRawOffset() == rawOffset) + Map.Entry entry = iter.next(); + if (entry.getValue().getRawOffset() == rawOffset) ids[count++] = (String) entry.getKey(); } return ids; @@ -1651,7 +1651,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable return ids; } - private static int getAvailableIDs(File d, String prefix, ArrayList list) + private static int getAvailableIDs(File d, String prefix, ArrayList list) { String[] files = d.list(); int count = files.length; @@ -1691,9 +1691,9 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable { synchronized (TimeZone.class) { - HashMap h = timezones(); + HashMap h = timezones(); if (zoneinfo_dir == null) - return (String[]) h.keySet().toArray(new String[h.size()]); + return h.keySet().toArray(new String[h.size()]); if (availableIDs != null) { @@ -1704,7 +1704,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable } File d = new File(zoneinfo_dir); - ArrayList list = new ArrayList(30); + ArrayList list = new ArrayList(30); int count = getAvailableIDs(d, "", list) + aliases0.size(); availableIDs = new String[count]; String[] ids = new String[count]; @@ -1712,7 +1712,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable count = 0; for (int i = 0; i < list.size(); i++) { - String[] s = (String[]) list.get(i); + String[] s = list.get(i); for (int j = 0; j < s.length; j++) if (s[j] != null) { @@ -1721,12 +1721,12 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable } } - Iterator iter = aliases0.entrySet().iterator(); + Iterator> iter = aliases0.entrySet().iterator(); while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); - availableIDs[count] = (String) entry.getKey(); - ids[count++] = (String) entry.getKey(); + Map.Entry entry = iter.next(); + availableIDs[count] = entry.getKey(); + ids[count++] = entry.getKey(); } return ids; -- cgit v1.2.1