我需要使用binaryOperator来实现一个apply方法,以便在两个双精度上执行数学过程,但是无法找到方法。我的代码的目的是一次对两个数字应用apply-method,每个数字来自它的相应迭代器。
我的编程时间太长了,所以我的代码可能会有很多错误,但这就是我现在已经走了多远:
package interfaces;
import java.util.Arrays;
import java.util.Iterator;
import java.util.function.BinaryOperator;
public class BinaryComputingIterator implements Iterator<Double>,
BinaryOperator<Double>{
private BinaryOperator<Double> operator;
private Iterator<Double> iterator1;
private Iterator<Double> iterator2;
private Double default1;
private Double default2;
BinaryComputingIterator(Iterator<Double> iterator1,
Iterator<Double> iterator2, BinaryOperator<Double> operator){
this.iterator1 = iterator1;
this.iterator2 = iterator2;
this.operator = operator;
}
BinaryComputingIterator(Iterator<Double> iterator1,
Iterator<Double> iterator2, Double default1, Double default2,
BinaryOperator<Double> operator){
this.iterator1 = iterator1;
this.iterator2 = iterator2;
this.operator = operator;
this.default1 = default1;
this.default2 = default2;
}
@Override
public boolean hasNext() {
if (iterator1.hasNext() && iterator2.hasNext()){
return true;
}
return false;
}
@Override
public Double next() {
if (this.hasNext()){
return this.next();
}
return null;
}
@Override
public Double apply(Double t, Double u) {
return this.operator.apply(t, u);
}
}
答案 0 :(得分:0)
您的if (!IsPostBack)
{
foreach (string header in headers)
{
XMLHeaders.Visible = true;
rdHeaders.Items.Add(header);
}
}
应该不实施Iterator
。你的next()方法应该实现为
BinaryOperator
这几乎应该涵盖它。