add suport for iterating over dictionary entries, cleaning up todo list

This commit is contained in:
Ben Fry
2016-11-14 21:27:21 -05:00
parent 4af8d568b5
commit 09950036c0
4 changed files with 150 additions and 8 deletions

View File

@@ -129,6 +129,55 @@ public class StringDict {
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public class Entry {
public String key;
public String value;
Entry(String key, String value) {
this.key = key;
this.value = value;
}
}
public Iterable<Entry> entries() {
return new Iterable<Entry>() {
public Iterator<Entry> iterator() {
return entryIterator();
}
};
}
public Iterator<Entry> entryIterator() {
return new Iterator<Entry>() {
int index = -1;
public void remove() {
removeIndex(index);
index--;
}
public Entry next() {
Entry e = new Entry(keys[index], values[index]);
index++;
return e;
}
public boolean hasNext() {
return index+1 < size();
}
};
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
public String key(int index) {
return keys[index];
}