Make sure formatting is applied to std-bits projects (#3477)

@radeusgd discovered that no formatting was being applied to std-bits projects.
This was caused by the fact that `enso` project didn't aggregate them. Compilation and
packaging still worked because one relied on the output of some tasks but
```
sbt> javafmtAll
```
didn't apply it to `std-bits`.

# Important Notes
Apart from `build.sbt` no manual changes were made.
This commit is contained in:
Hubert Plociniczak 2022-05-25 11:26:50 +02:00 committed by GitHub
parent f5f6d264dd
commit 4918ccb5a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 171 additions and 160 deletions

View File

@ -273,7 +273,12 @@ lazy val enso = (project in file("."))
`library-manager-test`, `library-manager-test`,
`connected-lock-manager`, `connected-lock-manager`,
syntax.jvm, syntax.jvm,
testkit testkit,
`std-base`,
`std-database`,
`std-google-api`,
`std-image`,
`std-table`
) )
.settings(Global / concurrentRestrictions += Tags.exclusive(Exclusive)) .settings(Global / concurrentRestrictions += Tags.exclusive(Exclusive))
.settings( .settings(

View File

@ -78,7 +78,7 @@ public abstract class MethodDispatchLibrary extends Library {
throw new NoSuchMethodException(); throw new NoSuchMethodException();
} }
/* * Conversions */ /** Conversions */
/** An exception thrown when the library cannot lookup the conversion definition. */ /** An exception thrown when the library cannot lookup the conversion definition. */
public static class NoSuchConversionException extends Exception {} public static class NoSuchConversionException extends Exception {}

View File

@ -40,7 +40,7 @@ public @interface Builtin {
@interface WrapException { @interface WrapException {
/** @return Class of the potential exception to be caught during the execution of the method */ /** @return Class of the potential exception to be caught during the execution of the method */
Class<? extends Exception> from(); Class<? extends Exception> from();
/** @return Class of Enso's builtin (error) type * */ /** @return Class of Enso's builtin (error) type */
Class<?> to(); Class<?> to();
} }

View File

@ -9,13 +9,14 @@ import java.util.function.BiFunction;
public class ObjectComparator implements Comparator<Object> { public class ObjectComparator implements Comparator<Object> {
private static ObjectComparator INSTANCE; private static ObjectComparator INSTANCE;
/*** /**
* A singleton instance of an ObjectComparator * A singleton instance of an ObjectComparator
* @param fallbackComparator this MUST be the default .compare_to function for Enso. Needs to be passed to allow calling back from Java. *
* @param fallbackComparator this MUST be the default .compare_to function for Enso. Needs to be
* passed to allow calling back from Java.
* @return Comparator object * @return Comparator object
*/ */
public static ObjectComparator getInstance( public static ObjectComparator getInstance(BiFunction<Object, Object, Long> fallbackComparator) {
BiFunction<Object, Object, Long> fallbackComparator) {
if (INSTANCE == null) { if (INSTANCE == null) {
INSTANCE = new ObjectComparator((l, r) -> fallbackComparator.apply(l, r).intValue()); INSTANCE = new ObjectComparator((l, r) -> fallbackComparator.apply(l, r).intValue());
} }

View File

@ -59,8 +59,8 @@ public class Regex_Utils {
* *
* <p>This should behave exactly the same as `Regex.compile regex . find text` in Enso, it is here * <p>This should behave exactly the same as `Regex.compile regex . find text` in Enso, it is here
* only as a temporary workaround, because the Enso function gives wrong results on examples like * only as a temporary workaround, because the Enso function gives wrong results on examples like
* `Regex.compile "([0-9]+|[^0-9]+)" . find "1a2c"` where it returns `[1, a, 2]` instead of * `Regex.compile "([0-9]+|[^0-9]+)" . find "1a2c"` where it returns `[1, a, 2]` instead of `[1,
* `[1, a, 2, c]`. * a, 2, c]`.
*/ */
public static String[] find_all_matches(String regex, String text) { public static String[] find_all_matches(String regex, String text) {
var allMatches = new ArrayList<String>(); var allMatches = new ArrayList<String>();

View File

@ -49,10 +49,8 @@ public final class UrlencodedBodyBuilder {
} }
private String encodePart(String name, String value) { private String encodePart(String name, String value) {
return return URLEncoder.encode(name, StandardCharsets.UTF_8)
URLEncoder.encode(name, StandardCharsets.UTF_8) + "="
+ "=" + URLEncoder.encode(value, StandardCharsets.UTF_8);
+ URLEncoder.encode(value, StandardCharsets.UTF_8);
} }
} }

View File

@ -8,7 +8,7 @@ import java.util.stream.Stream;
public class CountMinMax { public class CountMinMax {
private static boolean isValid(Object v) { private static boolean isValid(Object v) {
return !(v == null || (v instanceof Double && Double.isNaN((Double)v))); return !(v == null || (v instanceof Double && Double.isNaN((Double) v)));
} }
public static Stream<Object> toObjectStream(Object[] array) { public static Stream<Object> toObjectStream(Object[] array) {
@ -34,8 +34,10 @@ public class CountMinMax {
if (!comparatorFailed) { if (!comparatorFailed) {
try { try {
minimum = minimum == null || objectComparator.compare(minimum, value) > 0 ? value : minimum; minimum =
maximum = maximum == null || objectComparator.compare(maximum, value) < 0 ? value : maximum; minimum == null || objectComparator.compare(minimum, value) > 0 ? value : minimum;
maximum =
maximum == null || objectComparator.compare(maximum, value) < 0 ? value : maximum;
} catch (ClassCastException e) { } catch (ClassCastException e) {
comparatorFailed = true; comparatorFailed = true;
} }

View File

@ -23,6 +23,7 @@ public class Kurtosis implements MomentStatistic {
double scale = n * (n + 1) / ((n - 1) * (n - 2) * (n - 3) * var * var); double scale = n * (n + 1) / ((n - 1) * (n - 2) * (n - 3) * var * var);
double shift = 3.0 * (n - 1.0) * (n - 1.0) / ((n - 2.0) * (n - 3.0)); double shift = 3.0 * (n - 1.0) * (n - 1.0) / ((n - 2.0) * (n - 3.0));
return (sums[3] - 4 * avg * sums[2] + 6 * avg * avg * sums[1] - 3 * avg * avg * avg * sums[0]) return (sums[3] - 4 * avg * sums[2] + 6 * avg * avg * sums[1] - 3 * avg * avg * avg * sums[0])
* scale - shift; * scale
- shift;
} }
} }

View File

@ -1,14 +1,16 @@
package org.enso.base.statistics; package org.enso.base.statistics;
public interface MomentStatistic { public interface MomentStatistic {
/*** /**
* Maximum order needed to compute the statistic * Maximum order needed to compute the statistic
*
* @return Max order needed. 0 if only need the count. * @return Max order needed. 0 if only need the count.
*/ */
int order(); int order();
/*** /**
* Compute the statistic * Compute the statistic
*
* @param n the count of valid values * @param n the count of valid values
* @param sums the totals of each order * @param sums the totals of each order
* @return computed statistic * @return computed statistic

View File

@ -2,9 +2,7 @@ package org.enso.base.statistics;
import java.util.Arrays; import java.util.Arrays;
/*** /** Set of descriptive statistics for numerical data sets */
* Set of descriptive statistics for numerical data sets
*/
public class Moments { public class Moments {
/** Statistic to compute the total of the values. */ /** Statistic to compute the total of the values. */

View File

@ -15,9 +15,11 @@ public class GraphemeSpan extends Utf16Span {
/** /**
* Constructs a span of characters (understood as extended grapheme clusters). * Constructs a span of characters (understood as extended grapheme clusters).
* @param grapheme_start index of the first extended grapheme cluster contained within the span (or *
* location of the span if it is empty) * @param grapheme_start index of the first extended grapheme cluster contained within the span
* @param grapheme_end index of the first extended grapheme cluster after start that is not contained * (or location of the span if it is empty)
* @param grapheme_end index of the first extended grapheme cluster after start that is not
* contained
* @param codeunit_start code unit index of {@code grapheme_start} * @param codeunit_start code unit index of {@code grapheme_start}
* @param codeunit_end code unit index of {@code grapheme_end} * @param codeunit_end code unit index of {@code grapheme_end}
*/ */

View File

@ -92,5 +92,4 @@ public class Codecs {
throw new WriteFailedException(path); throw new WriteFailedException(path);
} }
} }
} }

View File

@ -9,9 +9,7 @@ import org.opencv.imgproc.Imgproc;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /** A histogram calculated for a single channel of an image. */
* A histogram calculated for a single channel of an image.
*/
public class Histogram { public class Histogram {
private static final int BINS = 256; private static final int BINS = 256;
@ -45,12 +43,7 @@ public class Histogram {
Core.split(image, images); Core.split(image, images);
Imgproc.calcHist( Imgproc.calcHist(
images, images, new MatOfInt(channel), new Mat(), histogram, new MatOfInt(BINS), valuesRange);
new MatOfInt(channel),
new Mat(),
histogram,
new MatOfInt(BINS),
valuesRange);
Core.normalize(histogram, histogram, 0, MAX_VALUE, Core.NORM_MINMAX); Core.normalize(histogram, histogram, 0, MAX_VALUE, Core.NORM_MINMAX);
float[] histogramData = new float[(int) histogram.total() * histogram.channels()]; float[] histogramData = new float[(int) histogram.total() * histogram.channels()];

View File

@ -106,7 +106,7 @@ public class Matrix {
*/ */
public static double[] get(Mat mat, int row, int column) { public static double[] get(Mat mat, int row, int column) {
double[] data = new double[mat.channels()]; double[] data = new double[mat.channels()];
int[] idx = new int[] { row, column }; int[] idx = new int[] {row, column};
mat.get(idx, data); mat.get(idx, data);
return data; return data;
@ -147,6 +147,7 @@ public class Matrix {
/** /**
* Subtract the scalar from each element of the matrix. * Subtract the scalar from each element of the matrix.
*
* @param mat the matrix. * @param mat the matrix.
* @param scalar the scalar to subtract. * @param scalar the scalar to subtract.
* @param dst the matrix holding the result of the operation. * @param dst the matrix holding the result of the operation.
@ -168,6 +169,7 @@ public class Matrix {
/** /**
* Multiply the scalar with each element of the matrix. * Multiply the scalar with each element of the matrix.
*
* @param mat the matrix. * @param mat the matrix.
* @param scalar the scalar to multiply with. * @param scalar the scalar to multiply with.
* @param dst the matrix holding the result of the operation. * @param dst the matrix holding the result of the operation.

View File

@ -1,4 +1,5 @@
// Copied unmodified from https://github.com/openpnp/opencv/blob/v4.5.1-0/src/main/java/nu/pattern/OpenCV.java // Copied unmodified from
// https://github.com/openpnp/opencv/blob/v4.5.1-0/src/main/java/nu/pattern/OpenCV.java
// to allow library loading on GraalVM. // to allow library loading on GraalVM.
package org.enso.image.opencv; package org.enso.image.opencv;

View File

@ -7,9 +7,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/*** /** Interface used to define aggregate columns. */
* Interface used to define aggregate columns.
*/
public abstract class Aggregator { public abstract class Aggregator {
private final String name; private final String name;
private final int type; private final int type;
@ -21,14 +19,18 @@ public abstract class Aggregator {
this.problems = null; this.problems = null;
} }
/*** /**
* Return name of the new column
*
* @return Name of the new column. * @return Name of the new column.
*/ */
public final String getName() { public final String getName() {
return name; return name;
} }
/*** /**
* Return type of the column
*
* @return The type of the new column. * @return The type of the new column.
*/ */
public int getType() { public int getType() {
@ -39,8 +41,9 @@ public abstract class Aggregator {
return problems; return problems;
} }
/*** /**
* Compute the value for a set of rows * Compute the value for a set of rows
*
* @param indexes - indexes to the rows in the source table to aggregate on * @param indexes - indexes to the rows in the source table to aggregate on
* @return aggregated value * @return aggregated value
*/ */
@ -48,8 +51,9 @@ public abstract class Aggregator {
return this.aggregate(Arrays.stream(indexes).boxed().collect(Collectors.toList())); return this.aggregate(Arrays.stream(indexes).boxed().collect(Collectors.toList()));
} }
/*** /**
* Compute the value for a set of rows * Compute the value for a set of rows
*
* @param indexes - indexes to the rows in the source table to aggregate on * @param indexes - indexes to the rows in the source table to aggregate on
* @return aggregated value * @return aggregated value
*/ */
@ -64,17 +68,17 @@ public abstract class Aggregator {
protected static Long CastToLong(Object value) { protected static Long CastToLong(Object value) {
if (value instanceof Long) { if (value instanceof Long) {
return (Long)value; return (Long) value;
} else if (value instanceof Integer) { } else if (value instanceof Integer) {
return ((Integer)value).longValue(); return ((Integer) value).longValue();
} else if (value instanceof Byte) { } else if (value instanceof Byte) {
return ((Byte)value).longValue(); return ((Byte) value).longValue();
} else if (value instanceof Float && ((Float)value) % 1 == 0) { } else if (value instanceof Float && ((Float) value) % 1 == 0) {
// Only return if an integer stored as a float ( % 1 == 0) // Only return if an integer stored as a float ( % 1 == 0)
return ((Float)value).longValue(); return ((Float) value).longValue();
} else if (value instanceof Double && ((Double)value) % 1 == 0) { } else if (value instanceof Double && ((Double) value) % 1 == 0) {
// Only return if an integer stored as a double ( % 1 == 0) // Only return if an integer stored as a double ( % 1 == 0)
return ((Double)value).longValue(); return ((Double) value).longValue();
} }
return null; return null;
@ -82,15 +86,15 @@ public abstract class Aggregator {
protected static Double CastToDouble(Object value) { protected static Double CastToDouble(Object value) {
if (value instanceof Long) { if (value instanceof Long) {
return ((Long)value).doubleValue(); return ((Long) value).doubleValue();
} else if (value instanceof Integer) { } else if (value instanceof Integer) {
return ((Integer)value).doubleValue(); return ((Integer) value).doubleValue();
} else if (value instanceof Byte) { } else if (value instanceof Byte) {
return ((Byte)value).doubleValue(); return ((Byte) value).doubleValue();
} else if (value instanceof Float) { } else if (value instanceof Float) {
return ((Float)value).doubleValue(); return ((Float) value).doubleValue();
} else if (value instanceof Double) { } else if (value instanceof Double) {
return ((Double)value); return ((Double) value);
} }
return null; return null;

View File

@ -4,9 +4,7 @@ import org.enso.table.data.column.storage.Storage;
import java.util.List; import java.util.List;
/*** /** Aggregate Column counting the number of entries in a group. */
* Aggregate Column counting the number of entries in a group.
*/
public class Count extends Aggregator { public class Count extends Aggregator {
public Count(String name) { public Count(String name) {
super(name, Storage.Type.LONG); super(name, Storage.Type.LONG);

View File

@ -10,9 +10,9 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
/*** /**
* Aggregate Column counting the number of distinct items in a group. * Aggregate Column counting the number of distinct items in a group. If `ignoreAllNull` is true,
* If `ignoreAllNull` is true, does count when all items are null. * does count when all items are null.
*/ */
public class CountDistinct extends Aggregator { public class CountDistinct extends Aggregator {
private final Storage[] storage; private final Storage[] storage;
@ -20,6 +20,7 @@ public class CountDistinct extends Aggregator {
/** /**
* Constructs a CountDistinct Aggregator * Constructs a CountDistinct Aggregator
*
* @param name output column name * @param name output column name
* @param columns input columns * @param columns input columns
* @param ignoreAllNull if true ignore then all values are null * @param ignoreAllNull if true ignore then all values are null
@ -33,8 +34,9 @@ public class CountDistinct extends Aggregator {
@Override @Override
public Object aggregate(List<Integer> indexes) { public Object aggregate(List<Integer> indexes) {
Set<MultiValueKey> set = new HashSet<>(); Set<MultiValueKey> set = new HashSet<>();
for (int row: indexes) { for (int row : indexes) {
MultiValueKey key = new MultiValueKey(Arrays.stream(storage).map(s->s.getItemBoxed(row)).toArray()); MultiValueKey key =
new MultiValueKey(Arrays.stream(storage).map(s -> s.getItemBoxed(row)).toArray());
if (key.hasFloatValues()) { if (key.hasFloatValues()) {
this.addProblem(new FloatingPointGrouping(this.getName(), row)); this.addProblem(new FloatingPointGrouping(this.getName(), row));
} }

View File

@ -6,10 +6,9 @@ import org.enso.table.data.table.problems.InvalidAggregation;
import java.util.List; import java.util.List;
/*** /**
* Aggregate Column counting the number of (non-)empty entries in a group. * Aggregate Column counting the number of (non-)empty entries in a group. If `isEmpty` is true,
* If `isEmpty` is true, counts null or empty entries. * counts null or empty entries. If `isEmpty` is false, counts non-empty entries.
* If `isEmpty` is false, counts non-empty entries.
*/ */
public class CountEmpty extends Aggregator { public class CountEmpty extends Aggregator {
private final Storage storage; private final Storage storage;
@ -17,6 +16,7 @@ public class CountEmpty extends Aggregator {
/** /**
* Constructs a CountNothing Aggregator * Constructs a CountNothing Aggregator
*
* @param name output column name * @param name output column name
* @param column input column * @param column input column
* @param isEmpty true to count nulls or empty, false to count non-empty * @param isEmpty true to count nulls or empty, false to count non-empty

View File

@ -5,10 +5,9 @@ import org.enso.table.data.table.Column;
import java.util.List; import java.util.List;
/*** /**
* Aggregate Column counting the number of (not-)null entries in a group. * Aggregate Column counting the number of (not-)null entries in a group. If `isNothing` is true,
* If `isNothing` is true, counts null entries. * counts null entries. If `isNothing` is false, counts non-null entries.
* If `isNothing` is false, counts non-null entries.
*/ */
public class CountNothing extends Aggregator { public class CountNothing extends Aggregator {
private final Storage storage; private final Storage storage;
@ -16,6 +15,7 @@ public class CountNothing extends Aggregator {
/** /**
* Constructs a CountNothing Aggregator * Constructs a CountNothing Aggregator
*
* @param name output column name * @param name output column name
* @param column input column * @param column input column
* @param isNothing true to count nulls, false to count non-nulls * @param isNothing true to count nulls, false to count non-nulls
@ -29,7 +29,7 @@ public class CountNothing extends Aggregator {
@Override @Override
public Object aggregate(List<Integer> indexes) { public Object aggregate(List<Integer> indexes) {
long count = 0; long count = 0;
for (int row: indexes) { for (int row : indexes) {
count += ((storage.getItemBoxed(row) == null) == isNothing ? 1 : 0); count += ((storage.getItemBoxed(row) == null) == isNothing ? 1 : 0);
} }
return count; return count;

View File

@ -8,9 +8,7 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
/*** /** Aggregate Column finding the first value in a group. */
* Aggregate Column finding the first value in a group.
*/
public class First extends Aggregator { public class First extends Aggregator {
private final Storage storage; private final Storage storage;
private final Storage[] ordering; private final Storage[] ordering;

View File

@ -5,9 +5,7 @@ import org.enso.table.data.table.Column;
import java.util.List; import java.util.List;
/*** /** Aggregate Column getting the grouping key. */
* Aggregate Column getting the grouping key.
*/
public class GroupBy extends Aggregator { public class GroupBy extends Aggregator {
private final Storage storage; private final Storage storage;

View File

@ -6,9 +6,7 @@ import org.enso.table.data.table.problems.InvalidAggregation;
import java.util.List; import java.util.List;
/*** /** Aggregate Column computing the mean value in a group. */
* Aggregate Column computing the mean value in a group.
*/
public class Mean extends Aggregator { public class Mean extends Aggregator {
private static class Calculation { private static class Calculation {
public long count; public long count;
@ -30,12 +28,13 @@ public class Mean extends Aggregator {
@Override @Override
public Object aggregate(List<Integer> indexes) { public Object aggregate(List<Integer> indexes) {
Calculation current = null; Calculation current = null;
for (int row: indexes) { for (int row : indexes) {
Object value = storage.getItemBoxed(row); Object value = storage.getItemBoxed(row);
if (value != null) { if (value != null) {
Double dValue = CastToDouble(value); Double dValue = CastToDouble(value);
if (dValue == null) { if (dValue == null) {
this.addProblem(new InvalidAggregation(this.getName(), row, "Cannot convert to a number.")); this.addProblem(
new InvalidAggregation(this.getName(), row, "Cannot convert to a number."));
return null; return null;
} }

View File

@ -7,7 +7,7 @@ import org.enso.table.data.table.problems.InvalidAggregation;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
/*** /**
* Aggregate Column finding the minimum (minOrMax = -1) or maximum (minOrMax = 1) entry in a group. * Aggregate Column finding the minimum (minOrMax = -1) or maximum (minOrMax = 1) entry in a group.
*/ */
public class MinOrMax extends Aggregator { public class MinOrMax extends Aggregator {
@ -36,7 +36,8 @@ public class MinOrMax extends Aggregator {
Object value = storage.getItemBoxed(row); Object value = storage.getItemBoxed(row);
if (value != null) { if (value != null) {
try { try {
if (current == null || Integer.signum(objectComparator.compare(value, current)) == minOrMax) { if (current == null
|| Integer.signum(objectComparator.compare(value, current)) == minOrMax) {
current = value; current = value;
} }
} catch (ClassCastException e) { } catch (ClassCastException e) {

View File

@ -8,9 +8,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/*** /** Aggregate Column computing the most common value in a group (ignoring Nothing). */
* Aggregate Column computing the most common value in a group (ignoring Nothing).
*/
public class Mode extends Aggregator { public class Mode extends Aggregator {
private final Storage storage; private final Storage storage;
@ -24,7 +22,7 @@ public class Mode extends Aggregator {
Object current = null; Object current = null;
int count = 0; int count = 0;
Map<Object, Integer> currentMap = null; Map<Object, Integer> currentMap = null;
for (int row: indexes) { for (int row : indexes) {
Object value = storage.getItemBoxed(row); Object value = storage.getItemBoxed(row);
if (value != null) { if (value != null) {
// Merge all numbers onto a Long if possible or a Double if needed // Merge all numbers onto a Long if possible or a Double if needed

View File

@ -8,9 +8,7 @@ import org.enso.table.data.column.storage.Storage;
import org.enso.table.data.table.Column; import org.enso.table.data.table.Column;
import org.enso.table.data.table.problems.InvalidAggregation; import org.enso.table.data.table.problems.InvalidAggregation;
/*** /** Aggregate Column computing a percentile value in a group. */
* Aggregate Column computing a percentile value in a group.
*/
public class Percentile extends Aggregator { public class Percentile extends Aggregator {
private final Storage storage; private final Storage storage;
private final double percentile; private final double percentile;

View File

@ -7,9 +7,7 @@ import org.enso.table.data.table.problems.InvalidAggregation;
import java.util.List; import java.util.List;
/*** /** Aggregate Column finding the longest or shortest string in a group. */
* Aggregate Column finding the longest or shortest string in a group.
*/
public class ShortestOrLongest extends Aggregator { public class ShortestOrLongest extends Aggregator {
private final Storage storage; private final Storage storage;
private final int minOrMax; private final int minOrMax;
@ -25,7 +23,7 @@ public class ShortestOrLongest extends Aggregator {
long length = 0; long length = 0;
Object current = null; Object current = null;
for (int row: indexes) { for (int row : indexes) {
Object value = storage.getItemBoxed(row); Object value = storage.getItemBoxed(row);
if (value != null) { if (value != null) {
if (!(value instanceof String)) { if (!(value instanceof String)) {
@ -33,7 +31,7 @@ public class ShortestOrLongest extends Aggregator {
return null; return null;
} }
long valueLength = GraphemeLength((String)value); long valueLength = GraphemeLength((String) value);
if (current == null || Long.compare(valueLength, length) == minOrMax) { if (current == null || Long.compare(valueLength, length) == minOrMax) {
length = valueLength; length = valueLength;
current = value; current = value;

View File

@ -5,9 +5,7 @@ import org.enso.table.data.column.storage.Storage;
import org.enso.table.data.table.Column; import org.enso.table.data.table.Column;
import org.enso.table.data.table.problems.InvalidAggregation; import org.enso.table.data.table.problems.InvalidAggregation;
/*** /** Aggregate Column computing the standard deviation of a group. */
* Aggregate Column computing the standard deviation of a group.
*/
public class StandardDeviation extends Aggregator { public class StandardDeviation extends Aggregator {
private static class Calculation { private static class Calculation {
public long count; public long count;

View File

@ -6,9 +6,7 @@ import org.enso.table.data.table.problems.InvalidAggregation;
import java.util.List; import java.util.List;
/*** /** Aggregate Column computing the total value in a group. */
* Aggregate Column computing the total value in a group.
*/
public class Sum extends Aggregator { public class Sum extends Aggregator {
private final Storage storage; private final Storage storage;
@ -20,7 +18,7 @@ public class Sum extends Aggregator {
@Override @Override
public Object aggregate(List<Integer> indexes) { public Object aggregate(List<Integer> indexes) {
Object current = null; Object current = null;
for (int row: indexes) { for (int row : indexes) {
Object value = storage.getItemBoxed(row); Object value = storage.getItemBoxed(row);
if (value != null) { if (value != null) {
if (current == null) { if (current == null) {
@ -37,7 +35,8 @@ public class Sum extends Aggregator {
if (dCurrent != null && dValue != null) { if (dCurrent != null && dValue != null) {
current = dCurrent + dValue; current = dCurrent + dValue;
} else { } else {
this.addProblem(new InvalidAggregation(this.getName(), row, "Cannot convert to a number.")); this.addProblem(
new InvalidAggregation(this.getName(), row, "Cannot convert to a number."));
return null; return null;
} }
} }

View File

@ -6,9 +6,9 @@ import java.util.stream.IntStream;
/** /**
* Represents a fold-like operation on a storage. An aggregator is usually created for a given * Represents a fold-like operation on a storage. An aggregator is usually created for a given
* storage, then {@link #nextGroup(IntStream)} is repeatedly called and the aggregator is responsible for * storage, then {@link #nextGroup(IntStream)} is repeatedly called and the aggregator is
* collecting the results of such calls. After that, {@link #seal()} is called to obtain a storage * responsible for collecting the results of such calls. After that, {@link #seal()} is called to
* containing all the results. * obtain a storage containing all the results.
*/ */
public abstract class Aggregator { public abstract class Aggregator {
/** /**

View File

@ -32,9 +32,7 @@ public class StringStorage extends ObjectStorage {
return (String) super.getItem(idx); return (String) super.getItem(idx);
} }
/** /** @inheritDoc */
* @inheritDoc
*/
@Override @Override
public long getType() { public long getType() {
return Type.STRING; return Type.STRING;

View File

@ -31,7 +31,9 @@ public class MultiValueIndex {
int size = keyColumns[0].getSize(); int size = keyColumns[0].getSize();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
int finalI = i; int finalI = i;
MultiValueKey key = new MultiValueKey(Arrays.stream(keyColumns).map(c -> c.getStorage().getItemBoxed(finalI)).toArray()); MultiValueKey key =
new MultiValueKey(
Arrays.stream(keyColumns).map(c -> c.getStorage().getItemBoxed(finalI)).toArray());
if (key.hasFloatValues()) { if (key.hasFloatValues()) {
problems.add(new FloatingPointGrouping("GroupBy", i)); problems.add(new FloatingPointGrouping("GroupBy", i));
@ -41,7 +43,9 @@ public class MultiValueIndex {
ids.add(i); ids.add(i);
} }
} else { } else {
this.locs.put(new MultiValueKey(new Object[0]), IntStream.range(0, tableSize).boxed().collect(Collectors.toList())); this.locs.put(
new MultiValueKey(new Object[0]),
IntStream.range(0, tableSize).boxed().collect(Collectors.toList()));
} }
} }
@ -50,9 +54,10 @@ public class MultiValueIndex {
final int size = locs.size(); final int size = locs.size();
boolean emptyScenario = size == 0 & keyColumnsLength == 0; boolean emptyScenario = size == 0 & keyColumnsLength == 0;
Builder[] storage = Arrays.stream(columns) Builder[] storage =
.map(c -> getBuilderForType(c.getType(), emptyScenario ? 1 : size)) Arrays.stream(columns)
.toArray(Builder[]::new); .map(c -> getBuilderForType(c.getType(), emptyScenario ? 1 : size))
.toArray(Builder[]::new);
if (emptyScenario) { if (emptyScenario) {
// No grouping and no data // No grouping and no data
@ -72,7 +77,7 @@ public class MultiValueIndex {
// Merge Problems // Merge Problems
AggregatedProblems[] problems = new AggregatedProblems[1 + length]; AggregatedProblems[] problems = new AggregatedProblems[1 + length];
problems[0] = this.problems; problems[0] = this.problems;
IntStream.range(0, length).forEach(i -> problems[i+1] = columns[i].getProblems()); IntStream.range(0, length).forEach(i -> problems[i + 1] = columns[i].getProblems());
AggregatedProblems merged = AggregatedProblems.merge(problems); AggregatedProblems merged = AggregatedProblems.merge(problems);
return new Table( return new Table(
@ -84,11 +89,16 @@ public class MultiValueIndex {
private static Builder getBuilderForType(int type, int size) { private static Builder getBuilderForType(int type, int size) {
switch (type) { switch (type) {
case Storage.Type.BOOL: return new BoolBuilder(); case Storage.Type.BOOL:
case Storage.Type.DOUBLE: return NumericBuilder.createDoubleBuilder(size); return new BoolBuilder();
case Storage.Type.LONG: return NumericBuilder.createLongBuilder(size); case Storage.Type.DOUBLE:
case Storage.Type.STRING: return new StringBuilder(size); return NumericBuilder.createDoubleBuilder(size);
case Storage.Type.OBJECT: return new ObjectBuilder(size); case Storage.Type.LONG:
return NumericBuilder.createLongBuilder(size);
case Storage.Type.STRING:
return new StringBuilder(size);
case Storage.Type.OBJECT:
return new ObjectBuilder(size);
} }
return new InferredBuilder(size); return new InferredBuilder(size);
} }

View File

@ -14,7 +14,7 @@ public class MultiValueKey implements Comparable<MultiValueKey> {
this(values, null); this(values, null);
} }
public MultiValueKey(Object[] values, Comparator<Object> objectComparator){ public MultiValueKey(Object[] values, Comparator<Object> objectComparator) {
this.values = values; this.values = values;
this.objectComparator = objectComparator; this.objectComparator = objectComparator;
@ -23,7 +23,7 @@ public class MultiValueKey implements Comparable<MultiValueKey> {
// Precompute HashCode - using Apache.Commons.Collections.Map.MultiKeyMap.hash algorithm // Precompute HashCode - using Apache.Commons.Collections.Map.MultiKeyMap.hash algorithm
int h = 0; int h = 0;
for (Object value: this.values) { for (Object value : this.values) {
if (value != null) { if (value != null) {
Object folded = foldObject(value); Object folded = foldObject(value);
floatValue = floatValue || (folded instanceof Double); floatValue = floatValue || (folded instanceof Double);
@ -57,21 +57,23 @@ public class MultiValueKey implements Comparable<MultiValueKey> {
return allNull; return allNull;
} }
public boolean hasFloatValues() { return floatValue; } public boolean hasFloatValues() {
return floatValue;
}
protected static Object foldObject(Object value) { protected static Object foldObject(Object value) {
if (value instanceof Long) { if (value instanceof Long) {
return value; return value;
} else if (value instanceof Integer) { } else if (value instanceof Integer) {
return ((Integer)value).longValue(); return ((Integer) value).longValue();
} else if (value instanceof Byte) { } else if (value instanceof Byte) {
return ((Byte)value).longValue(); return ((Byte) value).longValue();
} else if (value instanceof Float && ((Float)value) % 1 == 0) { } else if (value instanceof Float && ((Float) value) % 1 == 0) {
return ((Float)value).longValue(); return ((Float) value).longValue();
} else if (value instanceof Double && ((Double)value) % 1 == 0) { } else if (value instanceof Double && ((Double) value) % 1 == 0) {
return ((Double)value).longValue(); return ((Double) value).longValue();
} else if (value instanceof Float) { } else if (value instanceof Float) {
return ((Float)value).doubleValue(); return ((Float) value).doubleValue();
} else if (value instanceof Double) { } else if (value instanceof Double) {
return value; return value;
} }

View File

@ -46,7 +46,11 @@ public class Table {
private Table(Column[] columns, Index index, AggregatedProblems problems) { private Table(Column[] columns, Index index, AggregatedProblems problems) {
this.columns = columns; this.columns = columns;
this.index = index == null ? (new DefaultIndex((columns == null || columns.length == 0) ? 0 : columns[0].getSize())) : index; this.index =
index == null
? (new DefaultIndex(
(columns == null || columns.length == 0) ? 0 : columns[0].getSize()))
: index;
this.problems = problems; this.problems = problems;
} }
@ -64,9 +68,7 @@ public class Table {
return columns; return columns;
} }
/** /** @return Attached set of any problems from the Java side */
* @return Attached set of any problems from the Java side
*/
public AggregatedProblems getProblems() { public AggregatedProblems getProblems() {
return problems; return problems;
} }

View File

@ -39,8 +39,8 @@ public class AggregatedProblems {
public void add(Problem problem) { public void add(Problem problem) {
if (problem instanceof ColumnAggregatedProblems) { if (problem instanceof ColumnAggregatedProblems) {
for (Problem p : problems) { for (Problem p : problems) {
if (p instanceof ColumnAggregatedProblems && if (p instanceof ColumnAggregatedProblems
((ColumnAggregatedProblems) p).merge((ColumnAggregatedProblems)problem)) { && ((ColumnAggregatedProblems) p).merge((ColumnAggregatedProblems) problem)) {
return; return;
} }
} }

View File

@ -21,7 +21,9 @@ public abstract class ColumnAggregatedProblems implements Problem {
return rows.stream().mapToInt(Integer::intValue).toArray(); return rows.stream().mapToInt(Integer::intValue).toArray();
} }
public int count() { return rows.size(); } public int count() {
return rows.size();
}
public abstract boolean merge(ColumnAggregatedProblems another); public abstract boolean merge(ColumnAggregatedProblems another);

View File

@ -12,8 +12,8 @@ public class FloatingPointGrouping extends ColumnAggregatedProblems {
@Override @Override
public boolean merge(ColumnAggregatedProblems another) { public boolean merge(ColumnAggregatedProblems another) {
if (another instanceof FloatingPointGrouping && if (another instanceof FloatingPointGrouping
this.getColumnName().equals(another.getColumnName())) { && this.getColumnName().equals(another.getColumnName())) {
this.rows.addAll(another.rows); this.rows.addAll(another.rows);
return true; return true;
} }

View File

@ -9,13 +9,15 @@ public class InvalidAggregation extends ColumnAggregatedProblems {
} }
@Override @Override
public String getMessage() { return message; } public String getMessage() {
return message;
}
@Override @Override
public boolean merge(ColumnAggregatedProblems another) { public boolean merge(ColumnAggregatedProblems another) {
if (another instanceof InvalidAggregation && if (another instanceof InvalidAggregation
this.getColumnName().equals(another.getColumnName()) && && this.getColumnName().equals(another.getColumnName())
this.message.equals(((InvalidAggregation) another).message)) { && this.message.equals(((InvalidAggregation) another).message)) {
this.rows.addAll(another.rows); this.rows.addAll(another.rows);
return true; return true;
} }

View File

@ -3,6 +3,5 @@ package org.enso.table.data.table.problems;
import java.util.List; import java.util.List;
public interface Problem { public interface Problem {
String getMessage(); String getMessage();
} }

View File

@ -9,13 +9,15 @@ public class UnquotedDelimiter extends ColumnAggregatedProblems {
} }
@Override @Override
public String getMessage() { return message; } public String getMessage() {
return message;
}
@Override @Override
public boolean merge(ColumnAggregatedProblems another) { public boolean merge(ColumnAggregatedProblems another) {
if (another instanceof UnquotedDelimiter && if (another instanceof UnquotedDelimiter
this.getColumnName().equals(another.getColumnName()) && && this.getColumnName().equals(another.getColumnName())
this.message.equals(((UnquotedDelimiter) another).message)) { && this.message.equals(((UnquotedDelimiter) another).message)) {
this.rows.addAll(another.rows); this.rows.addAll(another.rows);
return true; return true;
} }

View File

@ -44,7 +44,10 @@ public class Range {
private static int[] parseRange(String range) throws IllegalArgumentException { private static int[] parseRange(String range) throws IllegalArgumentException {
for (Pattern pattern : new Pattern[] {RANGE_A1, RANGE_COL, RANGE_ROW, RANGE_RC}) { for (Pattern pattern : new Pattern[] {RANGE_A1, RANGE_COL, RANGE_ROW, RANGE_RC}) {
Optional<int[]> parsed = Optional<int[]> parsed =
parseRange(range, pattern, pattern == RANGE_RC ? Range::parseR1C1StyleAddress : Range::parseA1StyleAddress); parseRange(
range,
pattern,
pattern == RANGE_RC ? Range::parseR1C1StyleAddress : Range::parseA1StyleAddress);
if (parsed.isPresent()) { if (parsed.isPresent()) {
return parsed.get(); return parsed.get();
@ -142,13 +145,9 @@ public class Range {
} }
private static class ParsedInteger { private static class ParsedInteger {
/** /** Index to the next character after the parsed value */
* Index to the next character after the parsed value
*/
public final int index; public final int index;
/** /** Parsed integer value or 0 if not valid */
* Parsed integer value or 0 if not valid
*/
public final int value; public final int value;
public ParsedInteger(int index, int value) { public ParsedInteger(int index, int value) {