/** * @return the type of the field we are filtering on. */ public FieldType getType() { return this.dataModelObject.getField(fieldName).getType(); }
StringPivotFilter(DataModelObject dataModelObject, String fieldName, StringComparison comparison, String comparisonValue) { super(dataModelObject, fieldName); if (dataModelObject.getField(fieldName).getType() != FieldType.STRING) { throw new IllegalArgumentException("Field " + fieldName + " on the data model object was of type " + dataModelObject.getField(fieldName).getType().toString() + ", expected string."); } this.comparison = comparison; this.comparisonValue = comparisonValue; }
NumberPivotFilter(DataModelObject dataModelObject, String field, NumberComparison comparison, double comparisonValue) { super(dataModelObject, field); if (dataModelObject.getField(field).getType() != FieldType.NUMBER) { throw new IllegalArgumentException("Field " + field + " on the data model object was of type " + dataModelObject.getField(field).getType().toString() + ", expected number."); } this.comparison = comparison; this.comparisonValue = comparisonValue; }
BooleanPivotFilter(DataModelObject dataModelObject, String fieldName, BooleanComparison comparison, boolean comparisonValue) { super(dataModelObject, fieldName); if (dataModelObject.getField(fieldName).getType() != FieldType.BOOLEAN) { throw new IllegalArgumentException("Field " + fieldName + " on the data model object was of type " + dataModelObject.getField(fieldName).getType().toString() + ", expected boolean."); } this.comparison = comparison; this.comparisonValue = comparisonValue; }
IPv4PivotFilter(DataModelObject dataModelObject, String field, IPv4Comparison comparison, String comparisonValue) { super(dataModelObject, field); if (dataModelObject.getField(field).getType() != FieldType.IPV4) { throw new IllegalArgumentException("Field " + field + " on the data model object was of type " + dataModelObject.getField(field).getType().toString() + ", expected ipv4."); } this.comparison = comparison; this.comparisonValue = comparisonValue; }
private void assertCorrectlyTypedField(String fieldName, FieldType[] acceptableTypes) { DataModelField field = this.dataModelObject.getField(fieldName); if (field == null) { throw new IllegalArgumentException("No such field named " + fieldName); } else if (!Arrays.asList(acceptableTypes).contains(field.getType())) { StringBuilder errorMessage = new StringBuilder(); errorMessage.append("Expected a field of one of the following types: "); boolean first = true; for (FieldType t : acceptableTypes) { if (!first) errorMessage.append(", "); errorMessage.append(t.toString()); first = false; } errorMessage.append("; found type " + field.getType().toString()); throw new IllegalArgumentException(errorMessage.toString()); } }
/** * Add keys common to all row splits to a JSON serialization. * * @param obj JSON serialization to modify. */ protected void addCommonFields(JsonObject obj) { DataModelField field = this.dataModelObject.getField(this.fieldName); obj.addProperty("fieldName", this.fieldName); obj.addProperty("owner", Util.join(".", field.getOwnerLineage())); obj.addProperty("type", field.getType().toString()); obj.addProperty("label", this.label); }
/** * @return a JSON serialization of this object. */ JsonObject toJson() { JsonObject root = new JsonObject(); DataModelField f = this.dataModelObject.getField(fieldName); root.addProperty("fieldName", this.fieldName); root.addProperty("owner", Util.join(".", f.getOwnerLineage())); root.addProperty("type", f.getType().toString()); root.addProperty("label", this.label); root.addProperty("sparkline", false); // Not properly implemented in core yet. root.addProperty("value", this.statsFunction.toString()); return root; } }
protected void addCommonFields(JsonObject obj) { DataModelField field = this.owner.getField(this.fieldName); obj.addProperty("fieldName", this.fieldName); obj.addProperty("owner", Util.join(".", field.getOwnerLineage())); obj.addProperty("type", field.getType().toString()); }
/** * Add a row split on a numeric or string valued field, splitting on each distinct value of the field. * * @param field name of the field to split on * @param label a human readable name for this set of rows * @return The PivotSpecification you are modifying. */ public PivotSpecification addRowSplit(String field, String label) { assertCorrectlyTypedField(field, new FieldType[] { FieldType.NUMBER, FieldType.STRING }); FieldType t = this.dataModelObject.getField(field).getType(); if (t == FieldType.NUMBER) { rows.add(new NumberPivotRowSplit(this.dataModelObject, field, label)); } else if (t == FieldType.STRING) { rows.add(new StringPivotRowSplit(this.dataModelObject, field, label)); } else { throw new IllegalArgumentException("Field not of type number or string despite precondition asserting so."); } return this; }
/** * Add a column split on a string or number valued field, producing a column for * each distinct value of the field. * * @param field the field to split on. * @return The PivotSpecification you are modifying. */ public PivotSpecification addColumnSplit(String field) { assertCorrectlyTypedField(field, new FieldType[] { FieldType.NUMBER, FieldType.STRING }); FieldType t = this.dataModelObject.getField(field).getType(); if (t == FieldType.NUMBER) { columns.add(new NumericPivotColumnSplit(this.dataModelObject, field)); } else if (t == FieldType.STRING) { columns.add(new StringPivotColumnSplit(this.dataModelObject, field)); } return this; }
StatsFunction statsFunction) { super(dataModelObject, fieldName); FieldType type = dataModelObject.getField(fieldName).getType(); if (type != FieldType.NUMBER && type != FieldType.STRING && type != FieldType.OBJECTCOUNT) { throw new IllegalArgumentException("Field " + fieldName + " on the data model object was of type " + dataModelObject.getField(fieldName).getType().toString() + ", expected number, string, " + "or object count.");
FieldType t = dataModelObject.getField(fieldName).getType();