de.deepamehta.topicmaps.ClusterCoords Maven / Gradle / Ivy
The newest version!
package de.deepamehta.topicmaps;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
public class ClusterCoords implements Iterable {
// ---------------------------------------------------------------------------------------------- Instance Variables
private List entries = new ArrayList();
private Logger logger = Logger.getLogger(getClass().getName());
// ---------------------------------------------------------------------------------------------------- Constructors
public ClusterCoords(JSONArray entries) {
try {
for (int i = 0; i < entries.length(); i++) {
JSONObject entry = entries.getJSONObject(i);
this.entries.add(new Entry(
entry.getLong("topic_id"),
entry.getInt("x"),
entry.getInt("y")
));
}
} catch (Exception e) {
throw new RuntimeException("Parsing ClusterCoords failed (JSONArray=" + entries + ")", e);
}
}
// -------------------------------------------------------------------------------------------------- Public Methods
@Override
public Iterator iterator() {
return entries.iterator();
}
public class Entry {
public long topicId;
public int x;
public int y;
private Entry(long topicId, int x, int y) {
this.topicId = topicId;
this.x = x;
this.y = y;
}
}
}