@@ -30,7 +30,7 @@ public class PivotSpecification {
3030 private DataModelObject dataModelObject ;
3131 String namespace = null ;
3232
33- List <PivotColumn > columns = new ArrayList <PivotColumn >();
33+ List <PivotColumnSplit > columns = new ArrayList <PivotColumnSplit >();
3434 List <PivotFilter > filters = new ArrayList <PivotFilter >();
3535 List <PivotCell > cells = new ArrayList <PivotCell >();
3636 List <PivotRowSplit > rows = new ArrayList <PivotRowSplit >();
@@ -153,13 +153,16 @@ public PivotSpecification addFilter(String field, String sortAttribute,
153153 */
154154 public PivotSpecification addRowSplit (String field , String label ) {
155155 FieldType t = this .dataModelObject .getField (field ).getType ();
156- if (t != FieldType .NUMBER ) {
157- throw new IllegalArgumentException ("Expected a field of type number; found type " + t .toString ());
156+ PivotRowSplit split ;
157+ if (t == FieldType .NUMBER ) {
158+ split = new NumberPivotRowSplit (this .dataModelObject , field , label );
159+ } else if (t == FieldType .STRING ) {
160+ split = new StringPivotRowSplit (this .dataModelObject , field , label );
161+ } else {
162+ throw new IllegalArgumentException ("Expected a field of type number or string; found type " + t .toString ());
158163 }
159164
160- PivotRowSplit split = new NumberPivotRowSplit (this .dataModelObject , field , label );
161165 rows .add (split );
162-
163166 return this ;
164167 }
165168
@@ -212,6 +215,61 @@ public PivotSpecification addRowSplit(String field, String label, TimestampBinni
212215 return this ;
213216 }
214217
218+ public PivotSpecification addColumnSplit (String field ) {
219+ FieldType t = this .dataModelObject .getField (field ).getType ();
220+ PivotColumnSplit split ;
221+
222+ if (t == FieldType .NUMBER ) {
223+ split = new NumericPivotColumnSplit (this .dataModelObject , field );
224+ } else if (t == FieldType .STRING ) {
225+ split = new StringPivotColumnSplit (this .dataModelObject , field );
226+ } else {
227+ throw new IllegalArgumentException ("Expected a field of type number or string; found type " + t .toString ());
228+ }
229+
230+ columns .add (split );
231+ return this ;
232+ }
233+
234+ public PivotSpecification addColumnSplit (String field , int start , int end , int step , int limit ) {
235+ FieldType t = this .dataModelObject .getField (field ).getType ();
236+
237+ if (t != FieldType .NUMBER ) {
238+ throw new IllegalArgumentException ("Expected a field of type number; found type " + t .toString ());
239+ }
240+
241+ PivotColumnSplit split = new RangePivotColumnSplit (this .dataModelObject , field , start , end , step , limit );
242+
243+ columns .add (split );
244+ return this ;
245+ }
246+
247+ public PivotSpecification addColumnSplit (String field , String trueDisplayValue , String falseDisplayValue ) {
248+ FieldType t = this .dataModelObject .getField (field ).getType ();
249+
250+ if (t != FieldType .BOOLEAN ) {
251+ throw new IllegalArgumentException ("Expected a field of type boolean; found type " + t .toString ());
252+ }
253+
254+ PivotColumnSplit split = new BooleanPivotColumnSplit (this .dataModelObject , field ,
255+ trueDisplayValue , falseDisplayValue );
256+
257+ columns .add (split );
258+ return this ;
259+ }
260+
261+ public PivotSpecification addColumnSplit (String field , TimestampBinning binning ) {
262+ FieldType t = this .dataModelObject .getField (field ).getType ();
263+
264+ if (t != FieldType .TIMESTAMP ) {
265+ throw new IllegalArgumentException ("Expected a field of type timestamp; found type " + t .toString ());
266+ }
267+
268+ PivotColumnSplit split = new TimestampPivotColumnSplit (this .dataModelObject , field , binning );
269+
270+ columns .add (split );
271+ return this ;
272+ }
215273
216274 public JsonElement getDescription () {
217275 JsonObject root = new JsonObject ();
@@ -230,5 +288,6 @@ public JsonElement getDescription() {
230288
231289 public Collection <PivotFilter > getFilters () { return this .filters ; }
232290 public Collection <PivotRowSplit > getRowSplits () { return this .rows ; }
291+ public Collection <PivotColumnSplit > getColumnSplits () { return this .columns ; }
233292
234293}
0 commit comments