Simplify some for loops using new Java 5 syntax

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2181 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2011-08-02 21:17:41 +00:00
parent 97a0f2a33e
commit 539fea6eb3
9 changed files with 22 additions and 30 deletions

View File

@ -101,9 +101,9 @@ public class JythonEvaluable implements Evaluable {
sb.append("def "); sb.append("def ");
sb.append(s_functionName); sb.append(s_functionName);
sb.append("(value, cell, cells, row, rowIndex):"); sb.append("(value, cell, cells, row, rowIndex):");
for (int i = 0; i < lines.length; i++) { for (String line : lines) {
sb.append("\n "); sb.append("\n ");
sb.append(lines[i]); sb.append(line);
} }
_engine.exec(sb.toString()); _engine.exec(sb.toString());

View File

@ -213,8 +213,8 @@ public class ExpressionNominalValueGrouper implements RowVisitor, RecordVisitor
Object[] choiceValues = (Object[]) value; Object[] choiceValues = (Object[]) value;
List<Integer> counts = new ArrayList<Integer>(choiceValues.length); List<Integer> counts = new ArrayList<Integer>(choiceValues.length);
for (int i = 0; i < choiceValues.length; i++) { for (Object choiceValue : choiceValues) {
counts.add(getChoiceValueCount(choiceValues[i])); counts.add(getChoiceValueCount(choiceValue));
} }
return counts; return counts;
} else if (value instanceof Collection<?>) { } else if (value instanceof Collection<?>) {

View File

@ -110,8 +110,8 @@ abstract public class TimeBinIndex {
long diff = _max - _min; long diff = _max - _min;
for (int i = 0; i < steps.length; i++) { for (long step : steps) {
_step = steps[i]; _step = step;
if (diff / _step <= 100) break; if (diff / _step <= 100) break;
} }

View File

@ -65,8 +65,8 @@ public class FingerprintKeyer extends Keyer {
protected String asciify(String s) { protected String asciify(String s) {
char[] c = s.toCharArray(); char[] c = s.toCharArray();
StringBuffer b = new StringBuffer(); StringBuffer b = new StringBuffer();
for (int i = 0; i < c.length; i++) { for (char element : c) {
b.append(translate(c[i])); b.append(translate(element));
} }
return b.toString(); return b.toString();
} }

View File

@ -72,8 +72,8 @@ public class Uniques implements Function {
Object[] a = (Object[]) v; Object[] a = (Object[]) v;
set = new HashSet<Object>(a.length); set = new HashSet<Object>(a.length);
for (int i = 0; i < a.length; i++) { for (Object element : a) {
set.add(a[i]); set.add(element);
} }
} else { } else {
set = new HashSet<Object>(ExpressionUtils.toObjectList(v)); set = new HashSet<Object>(ExpressionUtils.toObjectList(v));

View File

@ -742,9 +742,9 @@ public class CalendarParser {
} }
String lstr = str.toLowerCase(); String lstr = str.toLowerCase();
for (int i = 0; i < WEEKDAY_NAMES.length; i++) { for (String element : WEEKDAY_NAMES) {
if (lstr.startsWith(WEEKDAY_NAMES[i]) if (lstr.startsWith(element)
|| WEEKDAY_NAMES[i].toLowerCase().startsWith(lstr)) { || element.toLowerCase().startsWith(lstr)) {
return true; return true;
} }
} }
@ -1037,8 +1037,8 @@ public class CalendarParser {
return; return;
} else if (zoneNames != null) { } else if (zoneNames != null) {
// maybe it's a time zone name // maybe it's a time zone name
for (int z = 0; z < zoneNames.length; z++) { for (String zoneName : zoneNames) {
if (token.equalsIgnoreCase(zoneNames[z])) { if (token.equalsIgnoreCase(zoneName)) {
TimeZone tz = TimeZone.getTimeZone(token); TimeZone tz = TimeZone.getTimeZone(token);
if (tz.getRawOffset() != 0 || lToken.equals("gmt")) { if (tz.getRawOffset() != 0 || lToken.equals("gmt")) {
state.setTimeZone(tz); state.setTimeZone(tz);
@ -1679,9 +1679,7 @@ public class CalendarParser {
} }
String[] tList = tmpTime.split("[:\\.]"); String[] tList = tmpTime.split("[:\\.]");
for (int i = 0; i < tList.length; i++) { for (String token : tList) {
String token = tList[i];
if (DEBUG) { if (DEBUG) {
System.err.println("HOUR " System.err.println("HOUR "
+ (state.isHourSet() ? Integer + (state.isHourSet() ? Integer
@ -1790,9 +1788,7 @@ public class CalendarParser {
int minute = UNSET; int minute = UNSET;
String[] tList = zoneStr.substring(1).split(":"); String[] tList = zoneStr.substring(1).split(":");
for (int i = 0; i < tList.length; i++) { for (String token : tList) {
String token = tList[i];
if (DEBUG) { if (DEBUG) {
System.err System.err
.println("TZ_HOUR " .println("TZ_HOUR "

View File

@ -51,8 +51,8 @@ public class ChangeSequence implements Change {
@Override @Override
public void apply(Project project) { public void apply(Project project) {
synchronized (project) { synchronized (project) {
for (int i = 0; i < _changes.length; i++) { for (Change _change : _changes) {
_changes[i].apply(project); _change.apply(project);
} }
} }
} }
@ -69,9 +69,7 @@ public class ChangeSequence implements Change {
@Override @Override
public void save(Writer writer, Properties options) throws IOException { public void save(Writer writer, Properties options) throws IOException {
writer.write("count="); writer.write(Integer.toString(_changes.length)); writer.write('\n'); writer.write("count="); writer.write(Integer.toString(_changes.length)); writer.write('\n');
for (int i = 0; i < _changes.length; i++) { for (Change change : _changes) {
Change change = _changes[i];
writer.write(change.getClass().getName()); writer.write('\n'); writer.write(change.getClass().getName()); writer.write('\n');
change.save(writer, options); change.save(writer, options);

View File

@ -195,9 +195,8 @@ public class ColumnSplitOperation extends EngineDependentOperation {
List<Serializable> results = new ArrayList<Serializable>(_fieldLengths.length + 1); List<Serializable> results = new ArrayList<Serializable>(_fieldLengths.length + 1);
int lastIndex = 0; int lastIndex = 0;
for (int i = 0; i < _fieldLengths.length; i++) { for (int length : _fieldLengths) {
int from = lastIndex; int from = lastIndex;
int length = _fieldLengths[i];
int to = Math.min(from + length, s.length()); int to = Math.min(from + length, s.length());
results.add(stringToValue(s.substring(from, to))); results.add(stringToValue(s.substring(from, to)));

View File

@ -88,8 +88,7 @@ public void write(JSONWriter writer, Properties options)
if (rd.cellDependencies != null) { if (rd.cellDependencies != null) {
newRow = oldRow.dup(); newRow = oldRow.dup();
for (int c = 0; c < rd.cellDependencies.length; c++) { for (CellDependency cd : rd.cellDependencies) {
CellDependency cd = rd.cellDependencies[c];
if (cd != null) { if (cd != null) {
int contextRowIndex = cd.rowIndex; int contextRowIndex = cd.rowIndex;
int contextCellIndex = cd.cellIndex; int contextCellIndex = cd.cellIndex;