@Override protected void doExecute(ExecutionContext ctx) { String input = String.valueOf(ctx.getValue()); Array<StringFieldValue> output = new Array<>(DataType.getArray(DataType.STRING)); if (!input.isEmpty()) { String[] splits = splitPattern.split(input); for (String split : splits) { output.add(new StringFieldValue(split)); } } ctx.setValue(output); }
public <T extends FieldValue> void read(FieldBase field, Array<T> value) { try { while (reader.hasNext()) { int type = reader.next(); if (type == XMLStreamReader.START_ELEMENT) { if ("item".equals(reader.getName().toString())) { FieldValue fv = (value.getDataType()).getNestedType().createFieldValue(); deserializeFieldValue(field, fv); // noinspection unchecked value.add((T)fv); skipToEnd("item"); } } else if (type == XMLStreamReader.END_ELEMENT) { return; } } } catch (XMLStreamException e) { throw newException(field, e); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void doExecute(ExecutionContext ctx) { FieldValue input = ctx.getValue(); DataType inputType = input.getDataType(); ArrayDataType outputType = DataType.getArray(inputType); Array output = outputType.createFieldValue(); output.add(input); ctx.setValue(output); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private FieldValue convertArray(Array val) { List<FieldValue> next = new LinkedList<FieldValue>(); DataType nextType = null; for (Iterator<FieldValue> it = val.fieldValueIterator(); it.hasNext();) { FieldValue prevVal = it.next(); FieldValue nextVal = convert(prevVal); if (nextVal == null) { continue; } if (nextType == null) { nextType = nextVal.getDataType(); } else if (!nextType.isValueCompatible(nextVal)) { throw new IllegalArgumentException("Expected " + nextType.getName() + ", got " + nextVal.getDataType().getName() + "."); } next.add(nextVal); } if (nextType == null) { return null; } Array ret = DataType.getArray(nextType).createFieldValue(); for (FieldValue nextVal : next) { ret.add(nextVal); } return ret; }
} else if (upd instanceof AddValueUpdate) { if (val instanceof Array) { ((Array)val).add(upd.getValue()); } else if (val instanceof WeightedSet) { ((WeightedSet)val).put(upd.getValue(), ((AddValueUpdate)upd).getWeight()); } else if (upd instanceof RemoveValueUpdate) { if (val instanceof Array) { ((Array)val).add(upd.getValue()); } else if (val instanceof WeightedSet) { ((WeightedSet)val).put(upd.getValue(), 1);
@Override public Progress process(Processing processing) { if ( ! doProcessOuterDocument(processing.getVariable(contextFieldName), documentTypeName)) { return Progress.DONE; } DocumentPut outerDoc = (DocumentPut)processing.getVariable(contextFieldName); @SuppressWarnings("unchecked") Array<Document> innerDocuments = (Array<Document>) outerDoc.getDocument().getFieldValue(arrayFieldName); if (innerDocuments == null) { @SuppressWarnings("unchecked") Array<Document> empty = (Array<Document>) outerDoc.getDocument().getDataType().getField(arrayFieldName).getDataType().createFieldValue(); innerDocuments = empty; } for (DocumentOperation op : processing.getDocumentOperations()) { if (op instanceof DocumentPut) { innerDocuments.add(((DocumentPut)op).getDocument()); } else { log.log(LogLevel.DEBUG, "Skipping: " + op); } } processing.getDocumentOperations().clear(); processing.getDocumentOperations().add(outerDoc); processing.removeVariable(contextFieldName); return Progress.DONE; }