Optimize MathFunction
This commit is contained in:
parent
e0681763ef
commit
6e58122380
1 changed files with 17 additions and 8 deletions
|
@ -35,20 +35,29 @@ public class MathFunction implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point evaluate(double time){
|
public Point evaluate(double time){
|
||||||
final Optional<Point> pointOptional = points.stream()
|
Point point = defaultValue;
|
||||||
.filter(point -> point.getTime() <= time)
|
|
||||||
.max(Comparator.comparingDouble(Point::getTime));
|
|
||||||
|
|
||||||
return pointOptional.orElse(defaultValue);
|
for(final Point currentPoint: points){
|
||||||
|
if(currentPoint.getTime() > time){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
point = currentPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point evaluatePrevious(double time){
|
public Point evaluatePrevious(double time){
|
||||||
final Optional<Point> pointOptional = points.stream()
|
Point point = defaultValue;
|
||||||
.filter(point -> point.getTime() < time)
|
|
||||||
.max(Comparator.comparingDouble(Point::getTime));
|
|
||||||
|
|
||||||
return pointOptional.orElse(defaultValue);
|
for(final Point currentPoint: points){
|
||||||
|
if(currentPoint.getTime() >= time){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
point = currentPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
return point;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue