-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduces support for columns of Java float type
- Loading branch information
1 parent
c4ce0ee
commit ffaf911
Showing
10 changed files
with
480 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/io/github/vmzakharov/ecdataframe/dataframe/DfFloatColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package io.github.vmzakharov.ecdataframe.dataframe; | ||
|
||
import io.github.vmzakharov.ecdataframe.dataframe.compare.DoubleComparisonResult; | ||
import io.github.vmzakharov.ecdataframe.dsl.value.ValueType; | ||
import org.eclipse.collections.api.list.primitive.ImmutableFloatList; | ||
import org.eclipse.collections.impl.factory.primitive.FloatLists; | ||
import org.eclipse.collections.impl.list.primitive.IntInterval; | ||
|
||
abstract public class DfFloatColumn | ||
extends DfColumnAbstract | ||
{ | ||
public DfFloatColumn(DataFrame newDataFrame, String newName) | ||
{ | ||
super(newDataFrame, newName); | ||
} | ||
|
||
abstract public float getFloat(int rowIndex); | ||
|
||
@Override | ||
public String getValueAsString(int rowIndex) | ||
{ | ||
return Float.toString(this.getFloat(rowIndex)); | ||
} | ||
|
||
public ImmutableFloatList toFloatList() | ||
{ | ||
int rowCount = this.getDataFrame().rowCount(); | ||
if (rowCount == 0) | ||
{ | ||
return FloatLists.immutable.empty(); | ||
} | ||
|
||
return IntInterval | ||
.zeroTo(rowCount - 1) | ||
.collectFloat(this::getFloat, FloatLists.mutable.withInitialCapacity(rowCount)) | ||
.toImmutable(); | ||
} | ||
|
||
public ValueType getType() | ||
{ | ||
return ValueType.FLOAT; | ||
} | ||
|
||
@Override | ||
public void addRowToColumn(int rowIndex, DfColumn target) | ||
{ | ||
if (this.isNull(rowIndex)) | ||
{ | ||
target.addEmptyValue(); | ||
} | ||
else | ||
{ | ||
((DfFloatColumnStored) target).addFloat(this.getFloat(rowIndex)); | ||
} | ||
} | ||
|
||
@Override | ||
public DfColumn mergeWithInto(DfColumn other, DataFrame target) | ||
{ | ||
DfFloatColumn mergedCol = (DfFloatColumn) this.validateAndCreateTargetColumn(other, target); | ||
|
||
mergedCol.addAllItemsFrom(this); | ||
mergedCol.addAllItemsFrom((DfFloatColumn) other); | ||
|
||
return mergedCol; | ||
} | ||
|
||
public DfColumn copyTo(DataFrame target) | ||
{ | ||
DfFloatColumn targetCol = (DfFloatColumn) this.copyColumnSchemaAndEnsureCapacity(target); | ||
|
||
targetCol.addAllItemsFrom(this); | ||
return targetCol; | ||
} | ||
|
||
protected abstract void addAllItemsFrom(DfFloatColumn items); | ||
|
||
@Override | ||
public DfCellComparator columnComparator(DfColumn otherColumn) | ||
{ | ||
DfFloatColumn otherFloatColumn = (DfFloatColumn) otherColumn; | ||
|
||
return (thisRowIndex, otherRowIndex) -> { | ||
int thisMappedIndex = this.dataFrameRowIndex(thisRowIndex); | ||
int otherMappedIndex = otherFloatColumn.dataFrameRowIndex(otherRowIndex); | ||
|
||
return new DoubleComparisonResult( | ||
() -> this.getFloat(thisMappedIndex), | ||
() -> otherFloatColumn.getFloat(otherMappedIndex), | ||
this.isNull(thisMappedIndex), | ||
otherFloatColumn.isNull(otherMappedIndex) | ||
); | ||
}; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/io/github/vmzakharov/ecdataframe/dataframe/DfFloatColumnComputed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.github.vmzakharov.ecdataframe.dataframe; | ||
|
||
import io.github.vmzakharov.ecdataframe.dsl.Expression; | ||
import io.github.vmzakharov.ecdataframe.dsl.value.FloatValue; | ||
import io.github.vmzakharov.ecdataframe.dsl.value.Value; | ||
import io.github.vmzakharov.ecdataframe.util.ExpressionParserHelper; | ||
|
||
public class DfFloatColumnComputed | ||
extends DfFloatColumn | ||
implements DfColumnComputed | ||
{ | ||
private final String expressionAsString; | ||
private final Expression expression; | ||
|
||
public DfFloatColumnComputed(DataFrame newDataFrame, String newName, String newExpressionAsString) | ||
{ | ||
super(newDataFrame, newName); | ||
this.expressionAsString = newExpressionAsString; | ||
|
||
this.expression = ExpressionParserHelper.DEFAULT.toExpressionOrScript(this.expressionAsString); | ||
} | ||
|
||
@Override | ||
public Object getObject(int rowIndex) | ||
{ | ||
Value result = this.getValue(rowIndex); | ||
|
||
return result.isVoid() ? null : ((FloatValue) result).floatValue(); | ||
} | ||
|
||
@Override | ||
public float getFloat(int rowIndex) | ||
{ | ||
Value result = this.getValue(rowIndex); | ||
|
||
if (result.isVoid()) | ||
{ | ||
throw new NullPointerException("Null value at " + this.getName() + "[" + rowIndex + "]"); | ||
} | ||
|
||
return ((FloatValue) result).floatValue(); | ||
} | ||
|
||
@Override | ||
protected void addAllItemsFrom(DfFloatColumn floatColumn) | ||
{ | ||
this.throwUnmodifiableColumnException(); | ||
} | ||
|
||
@Override | ||
public int getSize() | ||
{ | ||
return this.getDataFrame().rowCount(); | ||
} | ||
|
||
@Override | ||
public String getExpressionAsString() | ||
{ | ||
return this.expressionAsString; | ||
} | ||
|
||
@Override | ||
public Expression getExpression() | ||
{ | ||
return this.expression; | ||
} | ||
|
||
@Override | ||
public boolean isNull(int rowIndex) | ||
{ | ||
return this.getObject(rowIndex) == null; | ||
} | ||
} |
Oops, something went wrong.