Skip to content

Commit 1a8d2fa

Browse files
committed
bug fixing on Dict and List classes, add Iterable constructor
1 parent a4a362b commit 1a8d2fa

File tree

7 files changed

+37
-1
lines changed

7 files changed

+37
-1
lines changed

core/src/processing/data/FloatDict.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public FloatDict(String[] keys, float[] values) {
7070
this.keys = keys;
7171
this.values = values;
7272
count = keys.length;
73+
for (int i = 0; i < count; i++) {
74+
indices.put(keys[i], i);
75+
}
7376
}
7477

7578

@@ -81,6 +84,7 @@ public int size() {
8184
/** Remove all entries. */
8285
public void clear() {
8386
count = 0;
87+
indices = new HashMap<String, Integer>();
8488
}
8589

8690

core/src/processing/data/FloatList.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public FloatList(float[] list) {
2929
}
3030

3131

32+
public FloatList(Iterable<Float> iter) {
33+
this(10);
34+
for (float v : iter) {
35+
append(v);
36+
}
37+
}
38+
3239

3340
/**
3441
* Improve efficiency by removing allocated but unused entries from the

core/src/processing/data/IntDict.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public IntDict(String[] keys, int[] values) {
9393
this.keys = keys;
9494
this.values = values;
9595
count = keys.length;
96+
for (int i = 0; i < count; i++) {
97+
indices.put(keys[i], i);
98+
}
9699
}
97100

98101

@@ -104,6 +107,7 @@ public int size() {
104107
/** Remove all entries. */
105108
public void clear() {
106109
count = 0;
110+
indices = new HashMap<String, Integer>();
107111
}
108112

109113

core/src/processing/data/IntList.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public IntList(int[] source) {
3939
}
4040

4141

42+
public IntList(Iterable<Integer> iter) {
43+
this(10);
44+
for (int v : iter) {
45+
append(v);
46+
}
47+
}
48+
49+
4250
/**
4351
* Improve efficiency by removing allocated but unused entries from the
4452
* internal array used to store the data. Set to private, though it could

core/src/processing/data/StringDict.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public StringDict(String[] keys, String[] values) {
6868
this.keys = keys;
6969
this.values = values;
7070
count = keys.length;
71+
for (int i = 0; i < count; i++) {
72+
indices.put(keys[i], i);
73+
}
7174
}
7275

7376

@@ -79,6 +82,7 @@ public int size() {
7982
/** Remove all entries. */
8083
public void clear() {
8184
count = 0;
85+
indices = new HashMap<String, Integer>();
8286
}
8387

8488

core/src/processing/data/StringList.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ public StringList(String[] list) {
2929
}
3030

3131

32+
// Create from something iterable, for instance:
33+
// StringList list = new StringList(hashMap.keySet());
34+
public StringList(Iterable<String> iter) {
35+
this(10);
36+
for (String s : iter) {
37+
append(s);
38+
}
39+
}
40+
3241

3342
/**
3443
* Improve efficiency by removing allocated but unused entries from the

core/src/processing/data/Table.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3391,7 +3391,7 @@ public StringDict getStringDict(String keyColumnName, String valueColumnName) {
33913391

33923392
public StringDict getStringDict(int keyColumn, int valueColumn) {
33933393
return new StringDict(getStringColumn(keyColumn),
3394-
getStringColumn(valueColumn));
3394+
getStringColumn(valueColumn));
33953395
}
33963396

33973397

0 commit comments

Comments
 (0)