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(s_functionName);
sb.append("(value, cell, cells, row, rowIndex):");
for (int i = 0; i < lines.length; i++) {
for (String line : lines) {
sb.append("\n ");
sb.append(lines[i]);
sb.append(line);
}
_engine.exec(sb.toString());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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