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()); }
/** * Called by subclasses to add the fields common to all subclasses to JSON serializations. * * @param root a JsonObject instance representing a serialization of this object. */ protected void addCommonFields(JsonObject root) { root.addProperty("fieldName", this.fieldName); root.addProperty("owner", Util.join(".", this.dataModelObject.getField(fieldName).getOwnerLineage())); root.addProperty("type", this.getType().toString()); } }
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; }
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; }
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; }
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.");