package cells;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import simulation_type.Rule;

public class CellGraph {

	private Map<Integer, Cell> all_cells;
	
	public CellGraph(Map<Integer, Cell> cells) {
		all_cells = cells;
	}
	
	public Map<Integer, List<Double>> getStates() {
		Map<Integer, List<Double>> states = new HashMap<Integer, List<Double>>();
		for (int id: all_cells.keySet()) {
			Cell c = all_cells.get(id);
			List<Double> s = c.getState();
			states.put(id, s);
		}
		return states;
	}
	
	public void updateCells(Rule r) {
		Map<Integer, List<Double>> current_states = new HashMap<Integer, List<Double>>();
		for (int id: all_cells.keySet()) {
			Cell c = all_cells.get(id);
			List<Double> s = c.getState();
			current_states.put(id, s);
		}
		Map<Integer, List<Double>> next_states = new HashMap<Integer, List<Double>>();
		// calculate updates
		for (int id: all_cells.keySet()) {
			Cell c = all_cells.get(id);
			List<Cell> connections = c.getConnections();
			List<List<Double>> neighboring_states = new ArrayList<List<Double>>();
			for (Cell connection: connections) {
				neighboring_states.add(connection.getState());
			}
			r.updateCell(id, c.getState(), neighboring_states,
					current_states, next_states);
		}
		Set<Integer> ids = all_cells.keySet();
		r.fillVoids(ids, next_states);
		// set updates
		for (int id: next_states.keySet()) {
			Map<String, Double> next_state = next_states.get(id);
			Cell c = all_cells.get(id);
			c.setState(next_state);
		}
	}
}

@@ -313,37 +313,44 @@
 ic Map%3CInteger, 
-List%3C
+Map%3CString, 
 Double%3E%3E getStat
@@ -363,37 +363,44 @@
 %0A%09%09Map%3CInteger, 
-List%3C
+Map%3CString, 
 Double%3E%3E states 
@@ -393,32 +393,37 @@
 uble%3E%3E states = 
+%0A%09%09%09%09
 new HashMap%3CInte
@@ -419,37 +419,44 @@
 ashMap%3CInteger, 
-List%3C
+Map%3CString, 
 Double%3E%3E();%0A%09%09fo
@@ -514,37 +514,44 @@
 lls.get(id);%0A%09%09%09
-List%3C
+Map%3CString, 
 Double%3E s = c.ge
@@ -650,37 +650,44 @@
 %0A%09%09Map%3CInteger, 
-List%3C
+Map%3CString, 
 Double%3E%3E current
@@ -688,32 +688,37 @@
 urrent_states = 
+%0A%09%09%09%09
 new HashMap%3CInte
@@ -714,37 +714,44 @@
 ashMap%3CInteger, 
-List%3C
+Map%3CString, 
 Double%3E%3E();%0A%09%09fo
@@ -817,21 +817,28 @@
 id);%0A%09%09%09
-List%3C
+Map%3CString, 
 Double%3E 
@@ -896,37 +896,44 @@
 %0A%09%09Map%3CInteger, 
-List%3C
+Map%3CString, 
 Double%3E%3E next_st
@@ -935,24 +935,29 @@
 xt_states = 
+%0A%09%09%09%09
 new HashMap%3C
@@ -965,21 +965,28 @@
 nteger, 
-List%3C
+Map%3CString, 
 Double%3E%3E
@@ -1132,29 +1132,36 @@
 ();%0A%09%09%09List%3C
-List%3C
+Map%3CString, 
 Double%3E%3E nei
@@ -1178,16 +1178,22 @@
 tates = 
+%0A%09%09%09%09%09
 new Arra
@@ -1198,21 +1198,28 @@
 rayList%3C
-List%3C
+Map%3CString, 
 Double%3E%3E

Modify CellGraph