将列表迭代器转换为lambda

时间:2019-03-27 14:39:08

标签: lambda

我是lambda的新手,正在学习阶段。 我只想将现有代码的几行转换为lambda函数。

private List < ResourceSpecCharacteristic > getResourceSpecAttributes(ResourceSpecification resource) {

    List < ResourceSpecCharacteristic > resourceSpecCharacteristic = new ArrayList < ResourceSpecCharacteristic > ();

    Iterator itr = resource.getResourceSpecAttrs().iterator();

    while (itr.hasNext()) {
        ResourceSpecAttr resourceSpecAttr = (ResourceSpecAttr) itr.next();
        ResourceSpecCharacteristic resourceSpec = new ResourceSpecCharacteristic();
        resourceSpec.setName(resourceSpecAttr.getName());
        resourceSpec.setValueType(resourceSpecAttr.getValueType());
        resourceSpec.setMaxCardinality(resourceSpecAttr.getMaxCard());
        resourceSpec.setMinCardinality(resourceSpecAttr.getMinCard());
        resourceSpecCharacteristic.add(resourceSpec);
    }
    return resourceSpecCharacteristic;
}
}

0 个答案:

没有答案