summaryrefslogtreecommitdiffstats
path: root/simple/simple-http/src/test/java/org/simpleframework/http/socket/table/WebSocketTableRow.java
diff options
context:
space:
mode:
authormikaelpeltier <mikaelpeltier@google.com>2015-06-24 14:31:11 +0200
committerMikael Peltier <mikaelpeltier@google.com>2015-06-24 14:59:36 +0000
commit04563874ddaac702d6c715eaa89c29b253f4c54e (patch)
treec305fa98670c3e80be494cc054a8e31b51bfe7f2 /simple/simple-http/src/test/java/org/simpleframework/http/socket/table/WebSocketTableRow.java
parentf1828481ebcfee3bddc323fca178a4502a60ceef (diff)
downloadtoolchain_jack-04563874ddaac702d6c715eaa89c29b253f4c54e.zip
toolchain_jack-04563874ddaac702d6c715eaa89c29b253f4c54e.tar.gz
toolchain_jack-04563874ddaac702d6c715eaa89c29b253f4c54e.tar.bz2
Add simpleframework source files
Change-Id: I18d01df16de2868ca5458f79a88e6070b75db2c3 (cherry picked from commit 3e9f84cf7b22f6970eb8041ca38d12d75c6bb270)
Diffstat (limited to 'simple/simple-http/src/test/java/org/simpleframework/http/socket/table/WebSocketTableRow.java')
-rw-r--r--simple/simple-http/src/test/java/org/simpleframework/http/socket/table/WebSocketTableRow.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/simple/simple-http/src/test/java/org/simpleframework/http/socket/table/WebSocketTableRow.java b/simple/simple-http/src/test/java/org/simpleframework/http/socket/table/WebSocketTableRow.java
new file mode 100644
index 0000000..bb8a6db
--- /dev/null
+++ b/simple/simple-http/src/test/java/org/simpleframework/http/socket/table/WebSocketTableRow.java
@@ -0,0 +1,84 @@
+package org.simpleframework.http.socket.table;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class WebSocketTableRow {
+
+ private final Map<String, WebSocketTableCell> cells;
+ private final WebSocketValueEncoder encoder;
+ private final WebSocketTableSchema schema;
+ private final int index;
+
+ public WebSocketTableRow(WebSocketTableSchema schema, int index) {
+ this.cells = new ConcurrentHashMap<String, WebSocketTableCell>();
+ this.encoder = new WebSocketValueEncoder();
+ this.index = index;
+ this.schema = schema;
+ }
+
+ public int getIndex(){
+ return index;
+ }
+
+ public void setValue(String column, String value){
+ WebSocketTableCell cell = getValue(column);
+
+ if(cell == null) {
+ WebSocketTableCell newCell = new WebSocketTableCell(column, value);
+ List<String> columns = schema.columnNames();
+ boolean match = false;
+ for(String name : columns) {
+ if(name.equals(column)) {
+ match = true;
+ }
+ }
+ if(!match) {
+ throw new IllegalStateException("Could not find " + column + " in schema");
+ }
+ cells.put(column, newCell);
+ } else {
+ String previous = cell.getValue();
+
+ if(previous != null && !previous.equals(value)) {
+ WebSocketTableCell replaceCell = new WebSocketTableCell(column, value);
+ cells.put(column, replaceCell);
+ }
+ }
+ }
+
+ public WebSocketTableCell getValue(String column) {
+ return cells.get(column);
+ }
+
+ public String calculateChange(long lastUpdateDone) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(index);
+ builder.append(":");
+ String delim = "";
+ int count = 0;
+ List<String> columns = schema.columnNames();
+ for(int i = 0; i < columns.size(); i++){
+ String column = columns.get(i);
+ WebSocketTableCell cell = cells.get(column);
+ if(cell != null) {
+ long cellChanged = cell.getTimeStamp();
+ long difference = cellChanged - lastUpdateDone;
+
+ if(difference > 0) { // positive means change happened later than update
+ builder.append(delim);
+ builder.append(i);
+ builder.append("=");
+ builder.append(cell.getValue());
+ count++;
+ delim = ",";
+ }
+ }
+ }
+ if(count <= 0) {
+ return "";
+ }
+ return builder.toString();
+ }
+}