package com.drawbridge.vl; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import com.drawbridge.vl.blocks.Block; /** * Represents the Visual Language grid model used in DrawBridge * * @author Alistair Stead * */ public class Grid implements Iterable<LinkedList<Block>> { private List<LinkedList<Block>> backingGrid = new LinkedList<LinkedList<Block>>(); public Grid() { } public synchronized LinkedList<Block> get(int index) { return backingGrid.get(index); } public synchronized Block get(int i, int j) { return backingGrid.get(i).get(j); } public synchronized int size() { return backingGrid.size(); } public synchronized void add(LinkedList<Block> newLine) { backingGrid.add(newLine); } public synchronized Object[] toArray() { return backingGrid.toArray(); } public synchronized Iterator<LinkedList<Block>> iterator() { return backingGrid.iterator(); } public synchronized void clear() { backingGrid.clear(); } public synchronized void set(int index, LinkedList<Block> line) { backingGrid.set(index, line); } @Override public synchronized String toString() { String result = "Size:" + backingGrid.size() + "\n"; for (int i = 0; i < backingGrid.size(); i++) { result += "LineSize:" + backingGrid.get(i).size() + " "; for (int j = 0; j < backingGrid.get(i).size(); j++) { result += "[" + backingGrid.get(i).get(j).getClass().getSimpleName() + "] "; } result += "\n"; } return result; } }