diff --git a/src/main/java/com/metaweb/gridworks/model/Cell.java b/src/main/java/com/metaweb/gridworks/model/Cell.java index 982bf473c..3d27d4d43 100644 --- a/src/main/java/com/metaweb/gridworks/model/Cell.java +++ b/src/main/java/com/metaweb/gridworks/model/Cell.java @@ -4,6 +4,7 @@ import java.io.Serializable; import java.io.Writer; import java.util.Calendar; import java.util.Date; +import java.util.Map; import java.util.Properties; import org.json.JSONException; @@ -76,11 +77,11 @@ public class Cell implements HasFields, Jsonizable { } } - static public Cell load(String s) throws Exception { - return s.length() == 0 ? null : load(ParsingUtilities.evaluateJsonStringToObject(s)); + static public Cell load(String s, Map reconCache) throws Exception { + return s.length() == 0 ? null : load(ParsingUtilities.evaluateJsonStringToObject(s), reconCache); } - static public Cell load(JSONObject obj) throws Exception { + static public Cell load(JSONObject obj, Map reconCache) throws Exception { Serializable value = null; Recon recon = null; @@ -97,7 +98,7 @@ public class Cell implements HasFields, Jsonizable { } if (obj.has("r") && !obj.isNull("r")) { - recon = Recon.load(obj.getJSONObject("r")); + recon = Recon.load(obj.getJSONObject("r"), reconCache); } return new Cell(value, recon); diff --git a/src/main/java/com/metaweb/gridworks/model/Project.java b/src/main/java/com/metaweb/gridworks/model/Project.java index adefcf401..24ad7facd 100644 --- a/src/main/java/com/metaweb/gridworks/model/Project.java +++ b/src/main/java/com/metaweb/gridworks/model/Project.java @@ -12,7 +12,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -195,10 +197,11 @@ public class Project { } else if ("rowCount".equals(field)) { int count = Integer.parseInt(value); + Map reconCache = new HashMap(); for (int i = 0; i < count; i++) { line = reader.readLine(); if (line != null) { - Row row = Row.load(line); + Row row = Row.load(line, reconCache); project.rows.add(row); maxCellCount = Math.max(maxCellCount, row.cells.size()); } diff --git a/src/main/java/com/metaweb/gridworks/model/Recon.java b/src/main/java/com/metaweb/gridworks/model/Recon.java index b0ea56ecb..bd8007ecb 100644 --- a/src/main/java/com/metaweb/gridworks/model/Recon.java +++ b/src/main/java/com/metaweb/gridworks/model/Recon.java @@ -193,12 +193,17 @@ public class Recon implements HasFields, Jsonizable { writer.endObject(); } - static public Recon load(JSONObject obj) throws Exception { + static public Recon load(JSONObject obj, Map reconCache) throws Exception { if (obj == null) { return null; } - Recon recon = new Recon(obj.getLong("id")); + long id = obj.getLong("id"); + if (reconCache.containsKey(id)) { + return reconCache.get(id); + } + + Recon recon = new Recon(id); if (obj.has("j")) { recon.judgment = stringToJudgment(obj.getString("j")); @@ -225,6 +230,8 @@ public class Recon implements HasFields, Jsonizable { } } + reconCache.put(id, recon); + return recon; } diff --git a/src/main/java/com/metaweb/gridworks/model/Row.java b/src/main/java/com/metaweb/gridworks/model/Row.java index 821f89fc3..8a98ce995 100644 --- a/src/main/java/com/metaweb/gridworks/model/Row.java +++ b/src/main/java/com/metaweb/gridworks/model/Row.java @@ -3,6 +3,7 @@ package com.metaweb.gridworks.model; import java.io.Writer; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Map.Entry; @@ -152,11 +153,11 @@ public class Row implements HasFields, Jsonizable { } } - static public Row load(String s) throws Exception { - return s.length() == 0 ? null : load(ParsingUtilities.evaluateJsonStringToObject(s)); + static public Row load(String s, Map reconCache) throws Exception { + return s.length() == 0 ? null : load(ParsingUtilities.evaluateJsonStringToObject(s), reconCache); } - static public Row load(JSONObject obj) throws Exception { + static public Row load(JSONObject obj, Map reconCache) throws Exception { JSONArray a = obj.getJSONArray("cells"); int count = a.length(); @@ -165,7 +166,7 @@ public class Row implements HasFields, Jsonizable { if (!a.isNull(i)) { JSONObject o = a.getJSONObject(i); - row.setCell(i, Cell.load(o)); + row.setCell(i, Cell.load(o, reconCache)); } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/CellAtRow.java b/src/main/java/com/metaweb/gridworks/model/changes/CellAtRow.java index f0e65666c..fa42b01ae 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/CellAtRow.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/CellAtRow.java @@ -2,9 +2,11 @@ package com.metaweb.gridworks.model.changes; import java.io.IOException; import java.io.Writer; +import java.util.Map; import java.util.Properties; import com.metaweb.gridworks.model.Cell; +import com.metaweb.gridworks.model.Recon; public class CellAtRow { @@ -24,10 +26,10 @@ public class CellAtRow { } } - static public CellAtRow load(String s) throws Exception { + static public CellAtRow load(String s, Map reconCache) throws Exception { int semicolon = s.indexOf(';'); int row = Integer.parseInt(s.substring(0, semicolon)); - Cell cell = semicolon < s.length() - 1 ? Cell.load(s.substring(semicolon + 1)) : null; + Cell cell = semicolon < s.length() - 1 ? Cell.load(s.substring(semicolon + 1), reconCache) : null; return new CellAtRow(row, cell); } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/CellChange.java b/src/main/java/com/metaweb/gridworks/model/changes/CellChange.java index 4a4ffcad1..307879e0c 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/CellChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/CellChange.java @@ -3,11 +3,13 @@ package com.metaweb.gridworks.model.changes; import java.io.IOException; import java.io.LineNumberReader; import java.io.Writer; +import java.util.Map; import java.util.Properties; import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Recon; public class CellChange implements Change { final public int row; @@ -53,7 +55,7 @@ public class CellChange implements Change { writer.write("/ec/\n"); // end of change marker } - static public CellChange load(LineNumberReader reader) throws Exception { + static public CellChange load(LineNumberReader reader, Map reconCache) throws Exception { int row = -1; int cellIndex = -1; Cell oldCell = null; @@ -70,9 +72,9 @@ public class CellChange implements Change { } else if ("cell".equals(field)) { cellIndex = Integer.parseInt(value); } else if ("new".equals(field) && value.length() > 0) { - newCell = Cell.load(value); + newCell = Cell.load(value, reconCache); } else if ("old".equals(field) && value.length() > 0) { - oldCell = Cell.load(value); + oldCell = Cell.load(value, reconCache); } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/ColumnAdditionChange.java b/src/main/java/com/metaweb/gridworks/model/changes/ColumnAdditionChange.java index ea3db0d4b..5142d5f81 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/ColumnAdditionChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/ColumnAdditionChange.java @@ -4,12 +4,15 @@ import java.io.IOException; import java.io.LineNumberReader; import java.io.Writer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Recon; import com.metaweb.gridworks.model.Row; public class ColumnAdditionChange extends ColumnChange { @@ -92,11 +95,13 @@ public class ColumnAdditionChange extends ColumnChange { } else if ("newCellCount".equals(field)) { int newCellCount = Integer.parseInt(line.substring(equal + 1)); + Map reconCache = new HashMap(); + newCells = new ArrayList(newCellCount); for (int i = 0; i < newCellCount; i++) { line = reader.readLine(); if (line != null) { - newCells.add(CellAtRow.load(line)); + newCells.add(CellAtRow.load(line, reconCache)); } } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/ColumnRemovalChange.java b/src/main/java/com/metaweb/gridworks/model/changes/ColumnRemovalChange.java index fe293c652..eff748d3a 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/ColumnRemovalChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/ColumnRemovalChange.java @@ -3,12 +3,15 @@ package com.metaweb.gridworks.model.changes; import java.io.IOException; import java.io.LineNumberReader; import java.io.Writer; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Recon; import com.metaweb.gridworks.model.Row; public class ColumnRemovalChange extends ColumnChange { @@ -85,11 +88,13 @@ public class ColumnRemovalChange extends ColumnChange { } else if ("oldCellCount".equals(field)) { int oldCellCount = Integer.parseInt(line.substring(equal + 1)); + Map reconCache = new HashMap(); + oldCells = new CellAtRow[oldCellCount]; for (int i = 0; i < oldCellCount; i++) { line = reader.readLine(); if (line != null) { - oldCells[i] = CellAtRow.load(line); + oldCells[i] = CellAtRow.load(line, reconCache); } } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/DataExtensionChange.java b/src/main/java/com/metaweb/gridworks/model/changes/DataExtensionChange.java index 218fb1d9d..cd1e5c361 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/DataExtensionChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/DataExtensionChange.java @@ -5,7 +5,9 @@ import java.io.LineNumberReader; import java.io.Serializable; import java.io.Writer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import org.json.JSONException; @@ -284,6 +286,8 @@ public class DataExtensionChange implements Change { int firstNewCellIndex = -1; + Map reconCache = new HashMap(); + String line; while ((line = reader.readLine()) != null && !"/ec/".equals(line)) { int equal = line.indexOf('='); @@ -365,7 +369,7 @@ public class DataExtensionChange implements Change { for (int i = 0; i < count; i++) { line = reader.readLine(); if (line != null) { - oldRows.add(Row.load(line)); + oldRows.add(Row.load(line, reconCache)); } } } else if ("newRowCount".equals(field)) { @@ -375,7 +379,7 @@ public class DataExtensionChange implements Change { for (int i = 0; i < count; i++) { line = reader.readLine(); if (line != null) { - newRows.add(Row.load(line)); + newRows.add(Row.load(line, reconCache)); } } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/MassCellChange.java b/src/main/java/com/metaweb/gridworks/model/changes/MassCellChange.java index 780842fdd..6160661ac 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/MassCellChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/MassCellChange.java @@ -3,12 +3,15 @@ package com.metaweb.gridworks.model.changes; import java.io.IOException; import java.io.LineNumberReader; import java.io.Writer; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Recon; import com.metaweb.gridworks.model.Row; public class MassCellChange implements Change { @@ -112,9 +115,11 @@ public class MassCellChange implements Change { } else if ("cellChangeCount".equals(field)) { int cellChangeCount = Integer.parseInt(line.substring(equal + 1)); + Map reconCache = new HashMap(); + cellChanges = new CellChange[cellChangeCount]; for (int i = 0; i < cellChangeCount; i++) { - cellChanges[i] = CellChange.load(reader); + cellChanges[i] = CellChange.load(reader, reconCache); } } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/MassRowChange.java b/src/main/java/com/metaweb/gridworks/model/changes/MassRowChange.java index 0257769fb..8b96694cf 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/MassRowChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/MassRowChange.java @@ -4,11 +4,14 @@ import java.io.IOException; import java.io.LineNumberReader; import java.io.Writer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Recon; import com.metaweb.gridworks.model.Row; public class MassRowChange implements Change { @@ -56,6 +59,8 @@ public class MassRowChange implements Change { List oldRows = null; List newRows = null; + Map reconCache = new HashMap(); + String line; while ((line = reader.readLine()) != null && !"/ec/".equals(line)) { int equal = line.indexOf('='); @@ -68,7 +73,7 @@ public class MassRowChange implements Change { for (int i = 0; i < count; i++) { line = reader.readLine(); if (line != null) { - oldRows.add(Row.load(line)); + oldRows.add(Row.load(line, reconCache)); } } } else if ("newRowCount".equals(field)) { @@ -78,7 +83,7 @@ public class MassRowChange implements Change { for (int i = 0; i < count; i++) { line = reader.readLine(); if (line != null) { - newRows.add(Row.load(line)); + newRows.add(Row.load(line, reconCache)); } } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/ReconChange.java b/src/main/java/com/metaweb/gridworks/model/changes/ReconChange.java index 207f64d7f..680b74512 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/ReconChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/ReconChange.java @@ -6,12 +6,15 @@ package com.metaweb.gridworks.model.changes; import java.io.IOException; import java.io.LineNumberReader; import java.io.Writer; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Recon; import com.metaweb.gridworks.model.ReconStats; import com.metaweb.gridworks.model.recon.ReconConfig; import com.metaweb.gridworks.util.ParsingUtilities; @@ -155,9 +158,11 @@ public class ReconChange extends MassCellChange { } else if ("cellChangeCount".equals(field)) { int cellChangeCount = Integer.parseInt(value); + Map reconCache = new HashMap(); + cellChanges = new CellChange[cellChangeCount]; for (int i = 0; i < cellChangeCount; i++) { - cellChanges[i] = CellChange.load(reader); + cellChanges[i] = CellChange.load(reader, reconCache); } } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/RowRemovalChange.java b/src/main/java/com/metaweb/gridworks/model/changes/RowRemovalChange.java index d27efc371..23702ce84 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/RowRemovalChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/RowRemovalChange.java @@ -4,11 +4,14 @@ import java.io.IOException; import java.io.LineNumberReader; import java.io.Writer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Recon; import com.metaweb.gridworks.model.Row; public class RowRemovalChange implements Change { @@ -90,11 +93,13 @@ public class RowRemovalChange implements Change { } else if ("rowCount".equals(field)) { int count = Integer.parseInt(line.substring(equal + 1)); + Map reconCache = new HashMap(); + rows = new ArrayList(count); for (int i = 0; i < count; i++) { line = reader.readLine(); if (line != null) { - rows.add(Row.load(line)); + rows.add(Row.load(line, reconCache)); } } }