001package systems.dmx.topicmaps; 002 003import org.codehaus.jettison.json.JSONArray; 004import org.codehaus.jettison.json.JSONObject; 005 006import java.util.ArrayList; 007import java.util.Iterator; 008import java.util.List; 009import java.util.logging.Logger; 010 011 012 013public class ClusterCoords implements Iterable<ClusterCoords.Entry> { 014 015 // ---------------------------------------------------------------------------------------------- Instance Variables 016 017 private List<Entry> entries = new ArrayList(); 018 019 private Logger logger = Logger.getLogger(getClass().getName()); 020 021 // ---------------------------------------------------------------------------------------------------- Constructors 022 023 public ClusterCoords(JSONArray entries) { 024 try { 025 for (int i = 0; i < entries.length(); i++) { 026 JSONObject entry = entries.getJSONObject(i); 027 this.entries.add(new Entry( 028 entry.getLong("topicId"), 029 entry.getInt("x"), 030 entry.getInt("y") 031 )); 032 } 033 } catch (Exception e) { 034 throw new RuntimeException("Parsing ClusterCoords failed (JSONArray=" + entries + ")", e); 035 } 036 } 037 038 // -------------------------------------------------------------------------------------------------- Public Methods 039 040 @Override 041 public Iterator<Entry> iterator() { 042 return entries.iterator(); 043 } 044 045 public class Entry { 046 047 public long topicId; 048 public int x; 049 public int y; 050 051 private Entry(long topicId, int x, int y) { 052 this.topicId = topicId; 053 this.x = x; 054 this.y = y; 055 } 056 } 057}