Skip to content

Commit

Permalink
Updating faststruct factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Dec 10, 2022
1 parent 4fdf835 commit 7c4f33f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions java/tech/v3/datatype/FastStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import clojure.lang.IReduceInit;
import java.util.NoSuchElementException;
import java.util.List;
import java.util.RandomAccess;
import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -246,7 +247,7 @@ public Object reduce(IFn rfn, Object init) {
* Create a factory that will create map implementations based on a single list of values.
* Values have to be in the same order as column names.
*/
public static Function<List,Map> createFactory(List colnames) {
public static IFn createFactory(List colnames) {
int nEntries = colnames.size();
if( nEntries == 0 ) {
throw new RuntimeException("No column names provided");
Expand All @@ -259,8 +260,10 @@ public static Function<List,Map> createFactory(List colnames) {
if( colnames.size() != slots.size() ) {
throw new RuntimeException("Duplicate colname name: " + String.valueOf(slots));
}
return new Function<List,Map>() {
public Map apply(List valList) {
return new IFnDef.OO() {
public Object invoke(Object values) {
if(!(values instanceof RandomAccess)) throw new RuntimeException("Values must be a random access list.");
final List valList = (List)values;
if( slots.size() != valList.size() ) {
throw new RuntimeException("Number of values: " + String.valueOf(valList.size()) +
" doesn't equal the number of keys: " + String.valueOf(slots.size()));
Expand All @@ -271,6 +274,6 @@ public Map apply(List valList) {
}

public static FastStruct createFromColumnNames(List colnames, List vals) {
return (FastStruct)createFactory(colnames).apply(vals);
return (FastStruct)createFactory(colnames).invoke(vals);
}
}

0 comments on commit 7c4f33f

Please sign in to comment.