Skip to content

Commit

Permalink
Code cleanups from FindBugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Sep 4, 2009
1 parent aeaacc9 commit e3df573
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/org/hyperic/hq/hqapi1/HQConnection.java
Expand Up @@ -146,14 +146,14 @@ <T> T doGet(String path, Map<String, String[]> params, Class<T> resultClass)
}

boolean append = false;
for (String key : params.keySet()) {
String[] vals = params.get(key);
for (String val : vals) {

for (Map.Entry<String,String[]> e : params.entrySet()) {
for (String val : e.getValue()) {
if (val != null) {
if (append) {
uri.append("&");
}
uri.append(key).append("=").append(urlEncode(val));
uri.append(e.getKey()).append("=").append(urlEncode(val));
append = true;
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/org/hyperic/hq/hqapi1/ResourceApi.java
Expand Up @@ -153,10 +153,11 @@ public ResourceResponse createPlatform(Agent agent,
{
Resource platform = new Resource();
platform.setName(name);
for (String k : config.keySet()) {

for (Map.Entry<String,String> e : config.entrySet()) {
ResourceConfig c = new ResourceConfig();
c.setKey(k);
c.setValue(config.get(k));
c.setKey(e.getKey());
c.setValue(e.getValue());
platform.getResourceConfig().add(c);
}

Expand All @@ -179,10 +180,10 @@ private ResourceResponse createResource(ResourcePrototype type,
{
Resource resource = new Resource();
resource.setName(name);
for (String k : config.keySet()) {
for (Map.Entry<String,String> e : config.entrySet()) {
ResourceConfig c = new ResourceConfig();
c.setKey(k);
c.setValue(config.get(k));
c.setKey(e.getKey());
c.setValue(e.getValue());
resource.getResourceConfig().add(c);
}

Expand Down
Expand Up @@ -135,7 +135,7 @@ public Socket createSocket(String host, int port,
return createSocket(host, port, clientHost, clientPort);
}

class BogusTrustManager
static final class BogusTrustManager
implements X509TrustManager
{
public void checkClientTrusted(X509Certificate[] chain,
Expand Down
2 changes: 1 addition & 1 deletion src/org/hyperic/hq/hqapi1/test/GroupGet_test.java
Expand Up @@ -38,7 +38,7 @@

public class GroupGet_test extends GroupTestBase {

private final int SYNC_NUM = 3;
private static final int SYNC_NUM = 3;

public GroupGet_test(String name) {
super(name);
Expand Down
23 changes: 18 additions & 5 deletions src/org/hyperic/hq/hqapi1/tools/Command.java
Expand Up @@ -136,11 +136,21 @@ private Properties getClientProperties(String file) {
}

if (clientProperties.exists()) {
FileInputStream fis = null;
props = new Properties();
try {
props.load(new FileInputStream(clientProperties));
fis = new FileInputStream(clientProperties);
props.load(fis);
} catch (IOException e) {
return props;
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException ioe) {
// Ignore
}
}
}

Expand All @@ -153,15 +163,18 @@ private Properties getClientProperties(String file) {
return props;
}

protected InputStream getInputStream(OptionSet s) throws Exception {
/**
* TODO: This is not symmetrical
* @param s The OptionSet parsed from the command line arguments.
* @return A FileInputStream to the given file argument
* @throws IOException If the file does not exist.
*/
protected InputStream getInputStream(OptionSet s) throws IOException {
String file = (String)s.valueOf(OPT_FILE);
if (file == null) {
return System.in;
} else {
File f = new File(file);
if (!f.exists()) {
throw new Exception("Input file " + file + " does not exist.");
}
return new FileInputStream(f);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/org/hyperic/hq/hqapi1/tools/EventCommand.java
Expand Up @@ -55,13 +55,14 @@ private void list(String[] args) throws Exception {
EventApi eventApi = api.getEventApi();
ResourceApi resourceApi = api.getResourceApi();

long end = System.currentTimeMillis();
final long MS_IN_HOUR = 60l * 60l * 1000l;
final long end = System.currentTimeMillis();
long start;
if (options.has(OPT_HOURS)) {
Integer hours = (Integer)options.valueOf(OPT_HOURS);
start = end - (hours * 60 * 60 * 1000);
int hours = (Integer)options.valueOf(OPT_HOURS);
start = end - (hours * MS_IN_HOUR);
} else {
start = end - 8 * 60 * 60 * 1000;
start = end - (8 * MS_IN_HOUR);
}

EventsResponse response;
Expand Down
1 change: 0 additions & 1 deletion src/org/hyperic/hq/hqapi1/tools/GroupCommand.java
Expand Up @@ -167,7 +167,6 @@ private void syncViaCommandLineArgs(OptionSet s) throws Exception

// Optional
String regex = (String)s.valueOf(OPT_REGEX);
String description = (String)s.valueOf(OPT_DESC);
boolean deleteMissing = s.has(OPT_DELETEMISSING);
boolean compatible = s.has(OPT_COMPAT);

Expand Down
11 changes: 5 additions & 6 deletions src/org/hyperic/hq/hqapi1/tools/MaintenanceCommand.java
Expand Up @@ -55,8 +55,6 @@ public class MaintenanceCommand extends Command {
private static final String OPT_START = "start";
private static final String OPT_END = "end";

private static final DateFormat DF = SimpleDateFormat.getInstance();

private void printUsage() {
System.err.println("One of " + Arrays.toString(COMMANDS) + " required");
}
Expand Down Expand Up @@ -91,8 +89,9 @@ protected void handleCommand(String[] args) throws Exception {
* @return The equivenlent Date object, or null if the date could not be parsed.
*/
private Date parseDateString(String str) {
final DateFormat df = SimpleDateFormat.getInstance();
try {
return DF.parse(str);
return df.parse(str);
} catch (ParseException e) {
// Ignored
}
Expand Down Expand Up @@ -174,7 +173,7 @@ private void unschedule(String[] args) throws Exception {
}

private void get(String[] args) throws Exception {

final DateFormat df = SimpleDateFormat.getInstance();
OptionParser p = getOptionParser();

p.accepts(OPT_GROUPID, "The id of the group to query for maintenance").
Expand All @@ -195,8 +194,8 @@ private void get(String[] args) throws Exception {
response.getMaintenanceEvent().getEndTime() != 0) {
System.out.println("Maintenance scheudle for group " + groupId);
System.out.println("State: " + response.getMaintenanceEvent().getState().value());
System.out.println("Start Time: " + DF.format(response.getMaintenanceEvent().getStartTime()));
System.out.println("End Time: " + DF.format(response.getMaintenanceEvent().getEndTime()));
System.out.println("Start Time: " + df.format(response.getMaintenanceEvent().getStartTime()));
System.out.println("End Time: " + df.format(response.getMaintenanceEvent().getEndTime()));
} else {
System.out.println("No maintenance events found for group " + groupId);
}
Expand Down
9 changes: 5 additions & 4 deletions src/org/hyperic/hq/hqapi1/tools/MetricDataCommand.java
Expand Up @@ -91,13 +91,14 @@ private void list(String[] args) throws Exception {
MetricApi metricApi = api.getMetricApi();
MetricDataApi dataApi = api.getMetricDataApi();

long end = System.currentTimeMillis();
final long MS_IN_HOUR = 60l * 60l * 1000l;
final long end = System.currentTimeMillis();
long start;
if (options.has(OPT_HOURS)) {
Integer hours = (Integer)options.valueOf(OPT_HOURS);
start = end - (hours * 60 * 60 * 1000);
int hours = (Integer)options.valueOf(OPT_HOURS);
start = end - (hours * MS_IN_HOUR);
} else {
start = end - 8 * 60 * 60 * 1000;
start = end - (8 * MS_IN_HOUR);
}

if (options.has(OPT_METRIC_ID)) {
Expand Down

0 comments on commit e3df573

Please sign in to comment.