name:
src/main/java/io/protobase/f7/models/Cell.java
-rw-r--r--
3195
1package io.protobase.f7.models;
2
3import com.google.common.base.MoreObjects;
4
5/**
6 * A cell is a stored value in a sheet or grid. It contains a raw value, and a computed value. The computed value will
7 * only be set if the raw value is evaluated as a formula, or otherwise forced/coerced into bing a typed object. In the
8 * event that we are creating a cell that has a value set by projection (which means that another cell before it is
9 * returning a grid that pushes a value into this cell) the computed value will be set, but not the raw value.
10 */
11public class Cell extends BaseObject {
12 /**
13 * The raw value that is possibly F7 code.
14 */
15 private String rawValue;
16 /**
17 * The computed value from F7 code, or an interpreted value.
18 */
19 private Object computedValue = null;
20 /**
21 * Is this computed?
22 */
23 private boolean isComputed = false;
24
25 /**
26 * If a cell is blank, it can be populated with a value from a previous (above, or to the left) cell that returns a
27 * grid of cells. This is called projection.
28 */
29 private ColumnRowKey projectionOriginKey = null;
30
31 /**
32 * Create a new cell with a raw and computed value.
33 *
34 * @param rawValue - unchanged raw value.
35 * @param computedValue - computed value from the raw value.
36 */
37 public Cell(String rawValue, Object computedValue) {
38 this.rawValue = rawValue;
39 this.computedValue = computedValue;
40 this.isComputed = true;
41 }
42
43 /**
44 * Create an un-computed cell.
45 *
46 * @param rawValue - unchanged raw value.
47 */
48 public Cell(String rawValue) {
49 this.rawValue = rawValue;
50 }
51
52 /**
53 * Create a cell that has a computed value, but no raw value because it is being created via a projection.
54 *
55 * @param computedValue - value computed from the origin.
56 * @param projectionOriginKey - the origin key.
57 */
58 public Cell(Object computedValue, ColumnRowKey projectionOriginKey) {
59 this.rawValue = null;
60 this.computedValue = computedValue;
61 this.projectionOriginKey = projectionOriginKey;
62 this.isComputed = true;
63 }
64
65 /**
66 * Get the raw value.
67 *
68 * @return - string.
69 */
70 public String getRawValue() {
71 return rawValue;
72 }
73
74 public void setRawValue(String rawValue) {
75 this.rawValue = rawValue;
76 }
77
78 /**
79 * Get the computed value.
80 *
81 * @return - any object, but probably String, Boolean, Error, Double, or List.
82 */
83 public Object getComputedValue() {
84 return computedValue;
85 }
86
87 public void setComputedValue(Object computedValue) {
88 this.computedValue = computedValue;
89 }
90
91 /**
92 * Have we computed this yet or are we still holding the raw value?
93 *
94 * @return - true or false.
95 */
96 public boolean isComputed() {
97 return isComputed;
98 }
99
100 public void setComputed(boolean computed) {
101 isComputed = computed;
102 }
103
104 @Override
105 public String toString() {
106 return MoreObjects.toStringHelper(this)
107 .add("rawValue", rawValue)
108 .add("computedValue", computedValue)
109 .add("isComputed", isComputed)
110 .toString();
111 }
112
113 @Override
114 public Object[] significantAttributes() {
115 return new Object[]{
116 rawValue,
117 computedValue,
118 isComputed
119 };
120 }
121}