Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cell.above to refer to previous row value (#295)
- Loading branch information
1 parent
2cbe09e
commit 1a94257
Showing
12 changed files
with
318 additions
and
17 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
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
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
23 changes: 23 additions & 0 deletions
23
...c/main/java/com/twosigma/webtau/data/table/autogen/TableDataCellValueGenFullFunction.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,23 @@ | ||
/* | ||
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.twosigma.webtau.data.table.autogen; | ||
|
||
import com.twosigma.webtau.data.table.Record; | ||
|
||
public interface TableDataCellValueGenFullFunction<R> { | ||
R apply(Record row, Record prev, int rowIdx, int colIdx, String columnName); | ||
} |
42 changes: 42 additions & 0 deletions
42
.../src/main/java/com/twosigma/webtau/data/table/autogen/TableDataCellValueGenFunctions.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,42 @@ | ||
/* | ||
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.twosigma.webtau.data.table.autogen; | ||
|
||
import com.twosigma.webtau.data.table.Record; | ||
|
||
/** | ||
* @see com.twosigma.webtau.Ddjt#cell | ||
*/ | ||
public class TableDataCellValueGenFunctions { | ||
public final TableDataCellValueGenerator<?> above = new TableDataCellValueGenerator<>(this::previousColumnValue); | ||
|
||
public static <R> TableDataCellValueGenerator<R> value(TableDataCellValueGenFullFunction<R> genFunction) { | ||
return new TableDataCellValueGenerator<>(genFunction); | ||
} | ||
|
||
public static <R> TableDataCellValueGenerator<R> value(TableDataCellValueGenOnlyRecordFunction<R> genFunction) { | ||
return new TableDataCellValueGenerator<>(genFunction); | ||
} | ||
|
||
private <R> R previousColumnValue(Record row, Record prev, int rowIdx, int colIdx, String columnName) { | ||
if (prev == null) { | ||
return null; | ||
} | ||
|
||
return prev.get(columnName); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../java/com/twosigma/webtau/data/table/autogen/TableDataCellValueGenOnlyRecordFunction.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,23 @@ | ||
/* | ||
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.twosigma.webtau.data.table.autogen; | ||
|
||
import com.twosigma.webtau.data.table.Record; | ||
|
||
public interface TableDataCellValueGenOnlyRecordFunction<R> { | ||
R apply(Record row); | ||
} |
64 changes: 64 additions & 0 deletions
64
...ore/src/main/java/com/twosigma/webtau/data/table/autogen/TableDataCellValueGenerator.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,64 @@ | ||
/* | ||
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.twosigma.webtau.data.table.autogen; | ||
|
||
import com.twosigma.webtau.data.table.Record; | ||
|
||
public class TableDataCellValueGenerator<R> { | ||
private TableDataCellValueGenFullFunction<R> genFunction; | ||
private TableDataCellValueGenOnlyRecordFunction<R> genOnlyRecordFunction; | ||
|
||
public TableDataCellValueGenerator(TableDataCellValueGenFullFunction<R> genFunction) { | ||
this.genFunction = genFunction; | ||
} | ||
|
||
public TableDataCellValueGenerator(TableDataCellValueGenOnlyRecordFunction<R> genOnlyRecordFunction) { | ||
this.genOnlyRecordFunction = genOnlyRecordFunction; | ||
} | ||
|
||
public Object generate(Record row, Record prev, int rowIdx, int colIdx, String columnName) { | ||
if (genOnlyRecordFunction != null) { | ||
return genOnlyRecordFunction.apply(row); | ||
} else { | ||
return genFunction.apply(row, prev, rowIdx, colIdx, columnName); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <N extends Number> TableDataCellValueGenerator<N> plus(Number v) { | ||
return new TableDataCellValueGenerator<N>(((row, prev, rowIdx, colIdx, columnName) -> { | ||
R calculated = genFunction.apply(row, prev, rowIdx, colIdx, columnName); | ||
return (N) addTwoNumbers((Number) calculated, v); | ||
})); | ||
} | ||
|
||
private static Number addTwoNumbers(Number a, Number b) { | ||
if (b instanceof Double) { | ||
return a.doubleValue() + b.doubleValue(); | ||
} | ||
|
||
if (a instanceof Long || b instanceof Long) { | ||
return a.longValue() + b.longValue(); | ||
} | ||
|
||
if (b instanceof Integer) { | ||
return a.intValue() + b.intValue(); | ||
} | ||
|
||
throw new UnsupportedOperationException(a.getClass() + " + " + b.getClass() + " is not supported"); | ||
} | ||
} |
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
Oops, something went wrong.