Lambda上的StackOverflow

时间:2015-10-24 16:46:25

标签: java lambda java-8 stack-overflow java-stream

我有以下lambda表达式:

public static ArrayList<Sample> getSamplesWithFeatureValueGT(List<Sample> samples, FeatureLabel feature, int value) {

    return samples.stream().filter(x -> x.features.get(feature).compareTo(new BigDecimal(Double.toString(value))) > 0).collect(Collectors.toCollection(ArrayList::new));

}

每个Sample对象包含HashMap<FeatureLabel, BigDecimal> feature字段,而FeatureLabel是枚举。

我正在尝试过滤样本集合,并仅获取某些FeatureLabel值小于一定数量的样本。

我正在使用包含297个示例对象的List进行测试,并且收到StackOverflow错误,如下所示:

Exception in thread "main" java.lang.StackOverflowError
    at java.util.stream.AbstractPipeline.wrapSink(AbstractPipeline.java:548)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
    at uk.ac.dariosdesk.simpledecisiontree.TreeUtils.getSamplesWithFeatureValueGT(TreeUtils.java:72)
    at uk.ac.dariosdesk.simpledecisiontree.ContinuousFeature.CalculateEntropySplittingOnFeature(ContinuousFeature.java:46)
    at uk.ac.dariosdesk.simpledecisiontree.ContinuousFeature.lambda$CalculateCutOffPoint$0(ContinuousFeature.java:38)
    at uk.ac.dariosdesk.simpledecisiontree.ContinuousFeature$$Lambda$9/1848402763.compare(Unknown Source)

然后在ContinuousFeature.java:46我有:

 List<Sample> samplesGreaterThanCutOff = TreeUtils.getSamplesWithFeatureValueGT(samples, super.featureName, cutOffPoint);

这是第38行调用的函数的一部分:

cutOffPoint = IntStream.range(minValue.intValue(), maxValue.intValue())
                .boxed()
                .min((o1, o2) -> Double.compare(CalculateEntropySplittingOnFeature(samples, o1), CalculateEntropySplittingOnFeature(samples, o2))).get();
    }

基本上,行CalculateEntropySplittingOnFeature会多次调用我的getSamplesWithFeatureValueGT(并且它的等效LT小于),以根据要素属性过滤样本列表。

有什么建议吗?

0 个答案:

没有答案