Skip to content

Commit

Permalink
removed unnecessary boxing, cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
doneill committed Nov 3, 2015
1 parent 5c5102f commit 257ae60
Showing 1 changed file with 4 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,12 @@ public static boolean setAttribute(Map<String, Object> attrs,

// if its a string, and it has changed from the oldGraphic value
if (FieldType.determineFieldType(field) == FieldType.STRING) {

if (!value.equals(oldGraphic.getAttributeValue(field.getName()))) {

// set the value as it is
attrs.put(field.getName(), value);
hasValueChanged = true;

}
} else if (FieldType.determineFieldType(field) == FieldType.NUMBER) {

// if its an empty string, its a 0 number value (nulls not
// supported), check this is a
// change before making it a 0
Expand All @@ -100,21 +96,16 @@ public static boolean setAttribute(Map<String, Object> attrs,
// set a null value on the new graphic
attrs.put(field.getName(), 0);
hasValueChanged = true;

} else {

// parse as an int and check this is a change
int intValue = Integer.parseInt(value);
if (intValue != Integer.parseInt(oldGraphic.getAttributeValue(
field.getName()).toString())) {

attrs.put(field.getName(), Integer.valueOf(intValue));
attrs.put(field.getName(), intValue);
hasValueChanged = true;

}
}
} else if (FieldType.determineFieldType(field) == FieldType.DECIMAL) {

// if its an empty string, its a 0 double value (nulls not
// supported), check this is a
// change before making it a 0
Expand All @@ -131,38 +122,30 @@ public static boolean setAttribute(Map<String, Object> attrs,
double dValue = Double.parseDouble(value);
if (dValue != Double.parseDouble(oldGraphic.getAttributeValue(
field.getName()).toString())) {

attrs.put(field.getName(), Double.valueOf(dValue));
attrs.put(field.getName(), dValue);
hasValueChanged = true;

}
}
} else if (FieldType.determineFieldType(field) == FieldType.DATE) {

// if its a date, get the milliseconds value
Calendar c = Calendar.getInstance();
long dateInMillis = 0;

try {

// parse to a double and check this is a change
c.setTime(formatter.parse(value));
dateInMillis = c.getTimeInMillis();

if (dateInMillis != Long.parseLong(oldGraphic
.getAttributeValue(field.getName()).toString())) {

attrs.put(field.getName(), Long.valueOf(dateInMillis));
attrs.put(field.getName(), dateInMillis);
hasValueChanged = true;
}
} catch (ParseException e) {
// do nothing
}
}
// }

return hasValueChanged;

}

/**
Expand Down Expand Up @@ -192,19 +175,15 @@ public static int[] createArrayOfFieldIndexes(Field[] fields) {
for (int i = 0; i < fields.length; i++) {

if (isFieldValidForEditing(fields[i])) {

list.add(Integer.valueOf(i));
list.add(i);
fieldCount++;

}
}

int[] editableFieldIndexes = new int[fieldCount];

for (int x = 0; x < list.size(); x++) {

editableFieldIndexes[x] = list.get(x).intValue();

}

return editableFieldIndexes;
Expand Down

0 comments on commit 257ae60

Please sign in to comment.