Add number, date and boolean counts to List facet
This commit is contained in:
parent
55e3914c8d
commit
2a034b65e9
@ -74,6 +74,9 @@ public class ListFacet implements Facet {
|
|||||||
public boolean omitError;
|
public boolean omitError;
|
||||||
|
|
||||||
public List<DecoratedValue> selection = new LinkedList<>();
|
public List<DecoratedValue> selection = new LinkedList<>();
|
||||||
|
public boolean selectNumber;
|
||||||
|
public boolean selectDateTime;
|
||||||
|
public boolean selectBoolean;
|
||||||
public boolean selectBlank;
|
public boolean selectBlank;
|
||||||
public boolean selectError;
|
public boolean selectError;
|
||||||
|
|
||||||
@ -94,6 +97,9 @@ public class ListFacet implements Facet {
|
|||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
writer.endArray();
|
writer.endArray();
|
||||||
|
writer.key("selectNumber"); writer.value(selectNumber);
|
||||||
|
writer.key("selectDateTime"); writer.value(selectDateTime);
|
||||||
|
writer.key("selectBoolean"); writer.value(selectBoolean);
|
||||||
writer.key("omitBlank"); writer.value(omitBlank);
|
writer.key("omitBlank"); writer.value(omitBlank);
|
||||||
writer.key("selectBlank"); writer.value(selectBlank);
|
writer.key("selectBlank"); writer.value(selectBlank);
|
||||||
writer.key("omitError"); writer.value(omitError);
|
writer.key("omitError"); writer.value(omitError);
|
||||||
@ -124,6 +130,9 @@ public class ListFacet implements Facet {
|
|||||||
omitBlank = JSONUtilities.getBoolean(o, "omitBlank", false);
|
omitBlank = JSONUtilities.getBoolean(o, "omitBlank", false);
|
||||||
omitError = JSONUtilities.getBoolean(o, "omitError", false);
|
omitError = JSONUtilities.getBoolean(o, "omitError", false);
|
||||||
|
|
||||||
|
selectNumber = JSONUtilities.getBoolean(o, "selectNumber", false);
|
||||||
|
selectDateTime = JSONUtilities.getBoolean(o, "selectDateTime", false);
|
||||||
|
selectBoolean = JSONUtilities.getBoolean(o, "selectBoolean", false);
|
||||||
selectBlank = JSONUtilities.getBoolean(o, "selectBlank", false);
|
selectBlank = JSONUtilities.getBoolean(o, "selectBlank", false);
|
||||||
selectError = JSONUtilities.getBoolean(o, "selectError", false);
|
selectError = JSONUtilities.getBoolean(o, "selectError", false);
|
||||||
}
|
}
|
||||||
@ -149,6 +158,9 @@ public class ListFacet implements Facet {
|
|||||||
* Computed results
|
* Computed results
|
||||||
*/
|
*/
|
||||||
protected List<NominalFacetChoice> _choices = new LinkedList<NominalFacetChoice>();
|
protected List<NominalFacetChoice> _choices = new LinkedList<NominalFacetChoice>();
|
||||||
|
protected int _numberCount;
|
||||||
|
protected int _datetimeCount;
|
||||||
|
protected int _booleanCount;
|
||||||
protected int _blankCount;
|
protected int _blankCount;
|
||||||
protected int _errorCount;
|
protected int _errorCount;
|
||||||
|
|
||||||
@ -176,7 +188,27 @@ public class ListFacet implements Facet {
|
|||||||
choice.write(writer, options);
|
choice.write(writer, options);
|
||||||
}
|
}
|
||||||
writer.endArray();
|
writer.endArray();
|
||||||
|
if (_config.selectNumber || _numberCount > 0) {
|
||||||
|
writer.key("numberChoice");
|
||||||
|
writer.object();
|
||||||
|
writer.key("s"); writer.value(_config.selectNumber);
|
||||||
|
writer.key("c"); writer.value(_numberCount);
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
if (_config.selectDateTime || _datetimeCount > 0) {
|
||||||
|
writer.key("datetimeChoice");
|
||||||
|
writer.object();
|
||||||
|
writer.key("s"); writer.value(_config.selectDateTime);
|
||||||
|
writer.key("c"); writer.value(_datetimeCount);
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
|
if (_config.selectBoolean || _booleanCount > 0) {
|
||||||
|
writer.key("booleanChoice");
|
||||||
|
writer.object();
|
||||||
|
writer.key("s"); writer.value(_configselectBoolean);
|
||||||
|
writer.key("c"); writer.value(_booleanCount);
|
||||||
|
writer.endObject();
|
||||||
|
}
|
||||||
if (!_config.omitBlank && (_config.selectBlank || _blankCount > 0)) {
|
if (!_config.omitBlank && (_config.selectBlank || _blankCount > 0)) {
|
||||||
writer.key("blankChoice");
|
writer.key("blankChoice");
|
||||||
writer.object();
|
writer.object();
|
||||||
@ -245,6 +277,9 @@ public class ListFacet implements Facet {
|
|||||||
_config.columnName,
|
_config.columnName,
|
||||||
_cellIndex,
|
_cellIndex,
|
||||||
createMatches(),
|
createMatches(),
|
||||||
|
_config.selectNumber,
|
||||||
|
_config.selectDateTime,
|
||||||
|
_config.selectBoolean,
|
||||||
_config.selectBlank,
|
_config.selectBlank,
|
||||||
_config.selectError,
|
_config.selectError,
|
||||||
_config.invert);
|
_config.invert);
|
||||||
@ -310,6 +345,9 @@ public class ListFacet implements Facet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_numberCount = grouper.numberCount;
|
||||||
|
_datetimeCount = grouper.datetimeCount;
|
||||||
|
_booleanCount = grouper.booleanCount;
|
||||||
_blankCount = grouper.blankCount;
|
_blankCount = grouper.blankCount;
|
||||||
_errorCount = grouper.errorCount;
|
_errorCount = grouper.errorCount;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
package com.google.refine.browsing.filters;
|
package com.google.refine.browsing.filters;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -58,8 +60,10 @@ public class ExpressionEqualRowFilter implements RowFilter {
|
|||||||
final protected int _cellIndex; // the expression is based on this column;
|
final protected int _cellIndex; // the expression is based on this column;
|
||||||
// -1 if based on no column in particular,
|
// -1 if based on no column in particular,
|
||||||
// for expression such as "row.starred".
|
// for expression such as "row.starred".
|
||||||
|
|
||||||
final protected Object[] _matches;
|
final protected Object[] _matches;
|
||||||
|
final protected boolean _selectNumber;
|
||||||
|
final protected boolean _selectDateTime;
|
||||||
|
final protected boolean _selectBoolean;
|
||||||
final protected boolean _selectBlank;
|
final protected boolean _selectBlank;
|
||||||
final protected boolean _selectError;
|
final protected boolean _selectError;
|
||||||
final protected boolean _invert;
|
final protected boolean _invert;
|
||||||
@ -69,6 +73,9 @@ public class ExpressionEqualRowFilter implements RowFilter {
|
|||||||
String columnName,
|
String columnName,
|
||||||
int cellIndex,
|
int cellIndex,
|
||||||
Object[] matches,
|
Object[] matches,
|
||||||
|
boolean selectNumber,
|
||||||
|
boolean selectDateTime,
|
||||||
|
boolean selectBoolean,
|
||||||
boolean selectBlank,
|
boolean selectBlank,
|
||||||
boolean selectError,
|
boolean selectError,
|
||||||
boolean invert
|
boolean invert
|
||||||
@ -77,6 +84,9 @@ public class ExpressionEqualRowFilter implements RowFilter {
|
|||||||
_columnName = columnName;
|
_columnName = columnName;
|
||||||
_cellIndex = cellIndex;
|
_cellIndex = cellIndex;
|
||||||
_matches = matches;
|
_matches = matches;
|
||||||
|
_selectNumber = selectNumber;
|
||||||
|
_selectDateTime = selectDateTime;
|
||||||
|
_selectBoolean = selectBoolean;
|
||||||
_selectBlank = selectBlank;
|
_selectBlank = selectBlank;
|
||||||
_selectError = selectError;
|
_selectError = selectError;
|
||||||
_invert = invert;
|
_invert = invert;
|
||||||
@ -178,6 +188,12 @@ public class ExpressionEqualRowFilter implements RowFilter {
|
|||||||
protected boolean testValue(Object v) {
|
protected boolean testValue(Object v) {
|
||||||
if (ExpressionUtils.isError(v)) {
|
if (ExpressionUtils.isError(v)) {
|
||||||
return _selectError;
|
return _selectError;
|
||||||
|
} else if (v instanceof Number) {
|
||||||
|
return _selectNumber;
|
||||||
|
} else if (v instanceof OffsetDateTime) {
|
||||||
|
return _selectDateTime;
|
||||||
|
} else if (v instanceof Boolean) {
|
||||||
|
return _selectBoolean;
|
||||||
} else if (ExpressionUtils.isNonBlankData(v)) {
|
} else if (ExpressionUtils.isNonBlankData(v)) {
|
||||||
for (Object match : _matches) {
|
for (Object match : _matches) {
|
||||||
if (testValue(v, match)) {
|
if (testValue(v, match)) {
|
||||||
|
@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
package com.google.refine.browsing.util;
|
package com.google.refine.browsing.util;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -103,11 +103,19 @@ public class ExpressionUtils {
|
|||||||
static public boolean isError(Object o) {
|
static public boolean isError(Object o) {
|
||||||
return o instanceof EvalError;
|
return o instanceof EvalError;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
static public boolean isBlank(Object o) {
|
static public boolean isNumber(Object v) {
|
||||||
return o == null || (o instanceof String && ((String) o).length() == 0);
|
return v != null && (v instanceof Number);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
static public boolean isBoolean(Object v) {
|
||||||
|
return v != null && v instanceof Boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public boolean isDateTime(Object v) {
|
||||||
|
return v != null && v instanceof OffsetDateTime;
|
||||||
|
}
|
||||||
|
|
||||||
static public boolean isNonBlankData(Object o) {
|
static public boolean isNonBlankData(Object o) {
|
||||||
return
|
return
|
||||||
o != null &&
|
o != null &&
|
||||||
|
Loading…
Reference in New Issue
Block a user