NumberColumn extends AbstractColumn<C, T> implements NumericColumn<T> { public NumberColumn<C, T> set(DoublePredicate condition, NumberColumn<C, T> other) { for (int row = 0; row < size(); row++) { if (condition.test(getDouble(row))) { set(row, other.get(row)); } } return this; } protected  NumberColumn(final ColumnType type, final String name); NumberColumn<C, T> set(DoublePredicate condition, NumberColumn<C, T> other); NumberColumn<C, T> set(DoublePredicate condition, T newValue); void setPrintFormatter(final NumberFormat format, final String missingValueString); void setPrintFormatter(final NumberColumnFormatter formatter); abstract NumericColumn<T> top(final int n); abstract NumericColumn<T> bottom(final int n); @Override String getString(final int row); @Override C emptyCopy(); @Override C emptyCopy(final int rowSize); abstract C copy(); @Override IntComparator rowComparator(); @Override int byteSize(); @Override abstract byte[] asBytes(final int rowNumber); @Override abstract C appendMissing(); @Override int countMissing();  }
@Test public void testIsLessThan() { int size = 1_000_000; Table table = Table.create("t"); DoubleColumn numberColumn = DoubleColumn.create("test", size); table.addColumns(numberColumn); for (int i = 0; i < size; i++) { numberColumn.set(i, Math.random()); } Selection results = numberColumn.isLessThan(.5f); int count = 0; for (int i = 0; i < size; i++) { if (results.contains(i)) { count++; } } assertTrue(count < 575_000); assertTrue(count > 425_000); }
@Test public void testIsGreaterThan() { int size = 1_000_000; Table table = Table.create("t"); DoubleColumn numberColumn = DoubleColumn.create("test", size); table.addColumns(numberColumn); for (int i = 0; i < size; i++) { numberColumn.set(i, Math.random()); } Selection results = numberColumn.isGreaterThan(.5f); int count = 0; for (int i = 0; i < size; i++) { if (results.contains(i)) { count++; } } assertTrue(count < 575_000); assertTrue(count > 425_000); }
@Test public void testSort() { int records = 1_000_000; DoubleColumn numberColumn = DoubleColumn.create("test", records); for (int i = 0; i < records; i++) { numberColumn.set(i, Math.random()); } numberColumn.sortAscending(); double last = Double.NEGATIVE_INFINITY; for (double n : numberColumn) { assertTrue(n >= last); last = n; } numberColumn.sortDescending(); last = Double.POSITIVE_INFINITY; for (double n : numberColumn) { assertTrue(n <= last); last = n; } records = 10; numberColumn = DoubleColumn.create("test", records); for (int i = 0; i < records; i++) { numberColumn.set(i, Math.random()); } numberColumn.sortDescending(); last = Double.POSITIVE_INFINITY; for (double n : numberColumn) { assertTrue(n <= last); last = n; } }
@Test public void testClear() { DoubleColumn doubles = DoubleColumn.create("doubles", 100); for (int i = 0; i < 100; i++) { doubles.set(i, RandomUtils.nextDouble(0, 10_000)); } assertFalse(doubles.isEmpty()); doubles.clear(); assertTrue(doubles.isEmpty()); }
@Test public void testIsMissingAndIsNotMissing() { DoubleColumn doubles = DoubleColumn.create("doubles", 10); for (int i = 0; i < 10; i++) { doubles.set(i, RandomUtils.nextDouble(0, 1_000)); } assertEquals(0, doubles.isMissing().size()); assertEquals(10, doubles.isNotMissing().size()); doubles.clear(); for (int i = 0; i < 10; i++) { doubles.append(MISSING); } assertEquals(10, doubles.isMissing().size()); assertEquals(0, doubles.isNotMissing().size()); }
@Test public void fillMissing_defaultValue() { DoubleColumn col1 = DoubleColumn.create( "col1", new double[] { 0.0, 1.0, DoubleColumnType.missingValueIndicator(), 2.0, DoubleColumnType.missingValueIndicator() }); DoubleColumn expected = DoubleColumn.create("expected", new double[] {0.0, 1.0, 7.0, 2.0, 7.0}); assertArrayEquals(expected.asDoubleArray(), col1.set(isMissing, 7.0).asDoubleArray(), 0.0001); }
@Test public void fillMissing_columnArg() { DoubleColumn col1 = DoubleColumn.create( "col1", new double[] { 0.0, 1.0, DoubleColumnType.missingValueIndicator(), 2.0, DoubleColumnType.missingValueIndicator() }); DoubleColumn col2 = DoubleColumn.create("col1", new double[] {7.0, 7.0, 3.0, 7.0, 4.0}); DoubleColumn expected = DoubleColumn.create("expected", new double[] {0.0, 1.0, 3.0, 2.0, 4.0}); assertArrayEquals(expected.asDoubleArray(), col1.set(isMissing, col2).asDoubleArray(), 0.0001); }