risdenk commented on a change in pull request #163: KNOX-2052 - KnoxShellTable
mean, median, and mode methods
URL: https://github.com/apache/knox/pull/163#discussion_r333239968
##########
File path:
gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTable.java
##########
@@ -86,6 +96,117 @@ public KnoxShellTable value(Comparable<? extends Object>
value) {
return col;
}
+ public Conversions getConversion(Comparable<? extends Object> colIndex) {
+ Conversions type = null;
+
+ if (colIndex instanceof Double) {
+ type = Conversions.DOUBLE;
+ }
+ else if (colIndex instanceof Integer) {
+ type = Conversions.INTEGER;
+ }
+ else if (colIndex instanceof Float) {
+ type = Conversions.FLOAT;
+ }
+ else if (colIndex instanceof Byte) {
+ type = Conversions.BYTE;
+ }
+ else if (colIndex instanceof Short) {
+ type = Conversions.SHORT;
+ }
+ else if (colIndex instanceof Long) {
+ type = Conversions.LONG;
+ }
+ return type;
+ }
+
+ public double[] toDoubleArray(String colName) throws
IllegalArgumentException {
+ List<Comparable<? extends Object>> col = values(colName);
+ double[] colArray = new double[col.size()];
+ Conversions conversionMethod = null;
+ for (int i = 0; i < col.size(); i++) {
+ if (i == 0) {
+ conversionMethod = getConversion(col.get(i));
+ }
+
+ switch (conversionMethod) {
+ case DOUBLE:
Review comment:
nit: Above you use `Conversions.DOUBLE` but here you use just the enum
`DOUBLE` - it would be better to be consistent. I personally prefer
`Conversions.DOUBLE` so it doesn't look like its a built in constant.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services