Fixed some issues with iteration, updated readme
This commit is contained in:
parent
bfafa4658e
commit
5a471d0f8c
|
@ -159,7 +159,7 @@ boolean has_key = list.contains("key1");
|
|||
String[] keys = list.getKeys();
|
||||
|
||||
// Iterate over the lists keys
|
||||
for(String key : list)
|
||||
for(String key : keys)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package bdf.types;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import bdf.data.BdfDatabase;
|
||||
import bdf.util.DataHelpers;
|
||||
|
||||
public class BdfArray implements IBdfType
|
||||
public class BdfArray implements IBdfType, Iterable<BdfObject>
|
||||
{
|
||||
protected ArrayList<BdfObject> elements = new ArrayList<BdfObject>();
|
||||
|
||||
|
@ -110,4 +111,36 @@ public class BdfArray implements IBdfType
|
|||
return elements.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<BdfObject> iterator()
|
||||
{
|
||||
return new Iterator<BdfObject>()
|
||||
{
|
||||
protected int i = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return elements.size() > i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BdfObject next()
|
||||
{
|
||||
BdfObject o = elements.get(i);
|
||||
|
||||
i++;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
i-=1;
|
||||
elements.remove(i);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -223,5 +223,4 @@ public class BdfNamedList implements IBdfType
|
|||
public int size() {
|
||||
return elements.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package tests;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import bdf.classes.BdfClassManager;
|
||||
import bdf.file.BdfFileManager;
|
||||
import bdf.types.BdfArray;
|
||||
import bdf.types.BdfNamedList;
|
||||
import bdf.types.BdfObject;
|
||||
|
||||
|
@ -35,6 +38,29 @@ public class Tests {
|
|||
bdf.saveDatabase();
|
||||
|
||||
System.out.println(bdf.serializeHumanReadable());
|
||||
|
||||
BdfArray a = new BdfArray();
|
||||
|
||||
a.add(BdfObject.withInteger(1));
|
||||
a.add(BdfObject.withInteger(534));
|
||||
a.add(BdfObject.withInteger(32));
|
||||
a.add(BdfObject.withInteger(22));
|
||||
a.add(BdfObject.withInteger(12));
|
||||
|
||||
Iterator<BdfObject> i = a.iterator();
|
||||
|
||||
while(i.hasNext())
|
||||
{
|
||||
System.out.println(i.next().getInteger());
|
||||
i.remove();
|
||||
}
|
||||
|
||||
Iterator<BdfObject> i2 = a.iterator();
|
||||
|
||||
while(i2.hasNext())
|
||||
{
|
||||
System.out.println(i2.next().getInteger());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue