//recordFromJListPrimitive recordDict inputList.
//we iterate in FieldName order over the field names so that the function is well-defined in the presence of side effects.
//If f is the nth field in the recordDictionary, then recordDictionary.f is the dictionary for use when calling the
//class method Prelude.input on the nth element of the input list.
final RTRecordValue recordDict = (RTRecordValue)recordDictionary;
final int nOrdinalFields = recordDict.getNOrdinalFields();
final int nTextualFields = recordDict.getNTextualFields();
final int nFields = nOrdinalFields + nTextualFields;
//check that the number of fields in the inputList is the same as the number of fields in the record.
//without this check it is possible that inputList could have more elements than the size of the record and still succeed.
//This would still "work" but this check is useful to alert clients to potential bugs in their code.
if (nFields != inputList.size()) {
throw new IllegalArgumentException("A Java list of size " + inputList.size() + " cannot be input to a record with " + nFields + " fields.");
}
if (nOrdinalFields > 0) {
//we use an iterator since inputList may be a non-random access list such as a java.util.LinkedList.
Iterator<?> inputListIterator = inputList.iterator();
RTValue[] ordinalValues = new RTValue[nOrdinalFields];
for (int i = 0; i < nOrdinalFields; ++i) {
RTValue fieldDict = recordDict.getNthOrdinalValue(i);
RTValue listElement = RTData.CAL_Opaque.make(inputListIterator.next());
//compute "Prelude.input fieldDict listElement"
//this is just (after inlining Prelude.input d = d)
//fieldDict listElement
ordinalValues[i] = fieldDict.apply(listElement);
}
if (nTextualFields > 0) {
RTValue [] textualValues = new RTValue[nTextualFields];
for (int i = 0; i < nTextualFields; ++i) {
RTValue fieldDict = recordDict.getNthTextualValue(i);
RTValue listElement = RTData.CAL_Opaque.make(inputListIterator.next());
textualValues[i] = fieldDict.apply(listElement);
}
return recordDict.makeFromValues(ordinalValues, textualValues);
}
return recordDict.makeFromValues(ordinalValues, null);
}
if (nTextualFields > 0) {
//we use an iterator since inputList may be a non-random access list such as a java.util.LinkedList.
Iterator<?> inputListIterator = inputList.iterator();
RTValue [] textualValues = new RTValue[nTextualFields];
for (int i = 0; i < nTextualFields; ++i) {
RTValue fieldDict = recordDict.getNthTextualValue(i);
RTValue listElement = RTData.CAL_Opaque.make(inputListIterator.next());
textualValues[i] = fieldDict.apply(listElement);
}
return recordDict.makeFromValues(null, textualValues);
}
//empty record
return RTRecordValue.EMPTY_RECORD;
}