record java_Java Record类代码示例

import org.zephyr.data.Record; //导入依赖的package包/类

/**

* This method takes in a List of orderedPairings (key:value pairs). It creates a new Record with a new UUID, then iterates over the list of Pair items.

*

* If the Pair item currently operated upon can be normalized and validated as per the Scheme for that pair.getKey() successfully, it is added to the Record

* and the pair.getKey() is added to the normalizedAndValidatedFields Set - this set keeps track of all the fields that have been successfully normalized, validated, mapped, and security labeled.

*

* After all Pairs have been mapped according to their scheme, we then check the normalizedAndValidatedFields Set against the requiredFields set - unless all requiredFields have been successfully operated over,

* we throw a SchemeException. If all have been operated over successfully, we return the Record.

*

* @param orderedPairings

* @return

* @throws SchemeException

*/

public ProcessingResult> map(List orderedPairings) {

Set normalizedAndValidatedFields = new TreeSet();

Record record = new Record();

record.setFeedName(getFeedName());

for (Pair pair : orderedPairings) {

try {

List> results = normalizeAndValidate(pair);

for (ProcessingResult result : results) {

if (result.wasProcessedSuccessfully()) {

normalizedAndValidatedFields.add(pair.getKey());

record.add(result.getProcessedData());

} else {

logger.debug("A SchemeException error occurred when processing: {}", pair, result.getError());

}

}

} catch (SchemeException e) {

logger.debug("A SchemeException error occurred when processing: {}", pair, e);

}

}

Set requiredFields = getRequiredFields();

if (requiredFields != null) {

if (normalizedAndValidatedFields.containsAll(requiredFields)) {

return new ProcessingResult>(record);

} else {

Set missingRequiredFields = new TreeSet(requiredFields);

missingRequiredFields.removeAll(normalizedAndValidatedFields);

StringBuilder builder = new StringBuilder();

for (String missing : missingRequiredFields) {

builder.append(missing);

builder.append(",");

}

String error = builder.substring(0, builder.length() - 1);

return new ProcessingResult>(orderedPairings, new SchemeException("Of the required fields for this Schema, the following were unsuccessfully normalized or validated: " + error));

}

} else {

return new ProcessingResult>(record);

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值