Skip to content

Commit

Permalink
Java doc2 (#1018)
Browse files Browse the repository at this point in the history
* Added asSet() to Column API, with documentation

* Some tests for asSet()

* documentation and cleanup for numeric columns

* Completes JavaDoc for NumericColumn

* Completed JavaDoc for NumberColumn

* Completes JavaDoc for Stats class

* Complete JavaDoc for DoubleColumnType

* Complete JavaDoc for NumberInterpolator

* Update JavaDoc for ColumnType

* Complete JavaDoc for AbstractColumnType

* Complete JavaDoc for DoubleColumnType

* Complete JavaDoc for FloatColumnType and IntColumnType

* additional javadoc for Int and Long columns
  • Loading branch information
lwhite1 authored Oct 23, 2021
1 parent ec2db08 commit cd67ab7
Show file tree
Hide file tree
Showing 21 changed files with 288 additions and 38 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/tech/tablesaw/api/ColumnType.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ static ColumnType valueOf(String name) {
/** Returns a printer-friendly version of this ColumnType's name */
String getPrinterFriendlyName();

/** TODO: Research this method to provide a good comment */
AbstractColumnParser<?> customParser(ReadOptions options);

/** TODO: Research this method to provide a good comment */
default boolean compare(int rowNumber, Column<?> temp, Column<?> original) {
Object o1 = original.get(rowNumber);
Object o2 = temp.get(temp.size() - 1);
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/tech/tablesaw/api/DoubleColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.function.DoubleConsumer;
import java.util.function.DoublePredicate;
import java.util.function.DoubleSupplier;
Expand Down Expand Up @@ -382,6 +384,12 @@ public byte[] asBytes(int rowNumber) {
.array();
}

/** {@inheritDoc} */
@Override
public Set<Double> asSet() {
return new HashSet<>(unique().asList());
}

@Override
public int countUnique() {
DoubleSet uniqueElements = new DoubleOpenHashSet();
Expand Down
40 changes: 40 additions & 0 deletions core/src/main/java/tech/tablesaw/api/FloatColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.floats.*;
import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.stream.Stream;
import tech.tablesaw.columns.AbstractColumnParser;
import tech.tablesaw.columns.Column;
Expand Down Expand Up @@ -63,11 +65,13 @@ public FloatColumn createCol(String name, int initialSize) {
return create(name, initialSize);
}

/** {@inheritDoc} */
@Override
public FloatColumn createCol(String name) {
return create(name);
}

/** {@inheritDoc} */
@Override
public Float get(int index) {
float result = getFloat(index);
Expand All @@ -78,6 +82,7 @@ public static boolean valueIsMissing(float value) {
return FloatColumnType.valueIsMissing(value);
}

/** {@inheritDoc} */
@Override
public FloatColumn subset(int[] rows) {
final FloatColumn c = this.emptyCopy();
Expand Down Expand Up @@ -105,16 +110,19 @@ public Selection isIn(final float... numbers) {
return results;
}

/** {@inheritDoc} */
@Override
public int size() {
return data.size();
}

/** {@inheritDoc} */
@Override
public void clear() {
data.clear();
}

/** {@inheritDoc} */
@Override
public FloatColumn unique() {
final FloatSet values = new FloatOpenHashSet();
Expand All @@ -128,6 +136,7 @@ public FloatColumn unique() {
return column;
}

/** {@inheritDoc} */
@Override
public FloatColumn top(int n) {
FloatArrayList top = new FloatArrayList();
Expand All @@ -139,6 +148,7 @@ public FloatColumn top(int n) {
return new FloatColumn(name() + "[Top " + n + "]", top);
}

/** {@inheritDoc} */
@Override
public FloatColumn bottom(final int n) {
FloatArrayList bottom = new FloatArrayList();
Expand All @@ -150,6 +160,7 @@ public FloatColumn bottom(final int n) {
return new FloatColumn(name() + "[Bottoms " + n + "]", bottom);
}

/** {@inheritDoc} */
@Override
public FloatColumn lag(int n) {
final int srcPos = n >= 0 ? 0 : 0 - n;
Expand All @@ -167,6 +178,7 @@ public FloatColumn lag(int n) {
return new FloatColumn(name() + " lag(" + n + ")", new FloatArrayList(dest));
}

/** {@inheritDoc} */
@Override
public FloatColumn removeMissing() {
FloatColumn result = copy();
Expand All @@ -186,6 +198,7 @@ public FloatColumn append(float i) {
return this;
}

/** {@inheritDoc} */
@Override
public FloatColumn append(Float val) {
if (val == null) {
Expand All @@ -196,11 +209,13 @@ public FloatColumn append(Float val) {
return this;
}

/** {@inheritDoc} */
@Override
public FloatColumn copy() {
return new FloatColumn(name(), data.clone());
}

/** {@inheritDoc} */
@Override
public Iterator<Float> iterator() {
return data.iterator();
Expand All @@ -210,6 +225,7 @@ public float[] asFloatArray() {
return data.toFloatArray();
}

/** {@inheritDoc} */
@Override
public Float[] asObjectArray() {
final Float[] output = new Float[size()];
Expand All @@ -223,11 +239,13 @@ public Float[] asObjectArray() {
return output;
}

/** {@inheritDoc} */
@Override
public int compare(Float o1, Float o2) {
return Float.compare(o1, o2);
}

/** {@inheritDoc} */
@Override
public FloatColumn set(int i, Float val) {
return val == null ? setMissing(i) : set(i, (float) val);
Expand All @@ -238,11 +256,13 @@ public FloatColumn set(int i, float val) {
return this;
}

/** {@inheritDoc} */
@Override
public Column<Float> set(int row, String stringValue, AbstractColumnParser<?> parser) {
return set(row, parser.parseFloat(stringValue));
}

/** {@inheritDoc} */
@Override
public FloatColumn append(final Column<Float> column) {
Preconditions.checkArgument(column.type() == this.type());
Expand All @@ -254,25 +274,29 @@ public FloatColumn append(final Column<Float> column) {
return this;
}

/** {@inheritDoc} */
@Override
public FloatColumn append(Column<Float> column, int row) {
Preconditions.checkArgument(column.type() == this.type());
return append(((FloatColumn) column).getFloat(row));
}

/** {@inheritDoc} */
@Override
public FloatColumn set(int row, Column<Float> column, int sourceRow) {
Preconditions.checkArgument(column.type() == this.type());
return set(row, ((FloatColumn) column).getFloat(sourceRow));
}

/** {@inheritDoc} */
@Override
public byte[] asBytes(int rowNumber) {
return ByteBuffer.allocate(FloatColumnType.instance().byteSize())
.putFloat(getFloat(rowNumber))
.array();
}

/** {@inheritDoc} */
@Override
public int countUnique() {
FloatSet uniqueElements = new FloatOpenHashSet();
Expand All @@ -282,6 +306,7 @@ public int countUnique() {
return uniqueElements.size();
}

/** {@inheritDoc} */
@Override
public double getDouble(int row) {
float value = data.getFloat(row);
Expand All @@ -305,31 +330,37 @@ public boolean isMissingValue(float value) {
return FloatColumnType.valueIsMissing(value);
}

/** {@inheritDoc} */
@Override
public boolean isMissing(int rowNumber) {
return isMissingValue(getFloat(rowNumber));
}

/** {@inheritDoc} */
@Override
public FloatColumn setMissing(int i) {
return set(i, FloatColumnType.missingValueIndicator());
}

/** {@inheritDoc} */
@Override
public void sortAscending() {
data.sort(FloatComparators.NATURAL_COMPARATOR);
}

/** {@inheritDoc} */
@Override
public void sortDescending() {
data.sort(FloatComparators.OPPOSITE_COMPARATOR);
}

/** {@inheritDoc} */
@Override
public FloatColumn appendMissing() {
return append(FloatColumnType.missingValueIndicator());
}

/** {@inheritDoc} */
@Override
public FloatColumn appendObj(Object obj) {
if (obj == null) {
Expand All @@ -341,6 +372,7 @@ public FloatColumn appendObj(Object obj) {
throw new IllegalArgumentException("Could not append " + obj.getClass());
}

/** {@inheritDoc} */
@Override
public FloatColumn appendCell(final String value) {
try {
Expand All @@ -351,6 +383,7 @@ public FloatColumn appendCell(final String value) {
}
}

/** {@inheritDoc} */
@Override
public FloatColumn appendCell(final String value, AbstractColumnParser<?> parser) {
try {
Expand All @@ -361,6 +394,7 @@ public FloatColumn appendCell(final String value, AbstractColumnParser<?> parser
}
}

/** {@inheritDoc} */
@Override
public String getUnformattedString(final int row) {
final float value = getFloat(row);
Expand Down Expand Up @@ -479,4 +513,10 @@ public DoubleColumn asDoubleColumn() {
}
return result;
}

/** {@inheritDoc} */
@Override
public Set<Float> asSet() {
return new HashSet<>(unique().asList());
}
}
2 changes: 2 additions & 0 deletions core/src/main/java/tech/tablesaw/api/InstantColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,8 @@ public LongIterator longIterator() {
return data.iterator();
}

/** {@inheritDoc} */
@Override
public Set<Instant> asSet() {
Set<Instant> times = new HashSet<>();
InstantColumn unique = unique();
Expand Down
Loading

0 comments on commit cd67ab7

Please sign in to comment.