1 9 package org.jscience.mathematics.functions; 10 11 import java.util.List ; 12 import java.util.SortedMap ; 13 import javolution.context.Realtime; 14 import javolution.util.FastList; 15 16 26 public final class DiscreteFunction<X, Y> extends Function<X, Y> { 27 28 31 private SortedMap <X, Y> _pointValues; 32 33 36 private FastList<Variable<X>> _variables = new FastList<Variable<X>>(); 37 38 41 private Interpolator<X, Y> _interpolator; 42 43 50 public DiscreteFunction(SortedMap <X, Y> pointValues, Interpolator<X, Y> interpolator, Variable<X> variable) { 51 _pointValues = pointValues; 52 _variables.add(variable); 53 _interpolator = interpolator; 54 } 55 56 61 public SortedMap <X, Y> getPointValues() { 62 return _pointValues; 63 } 64 65 70 public Interpolator<X, Y> getInterpolator() { 71 return _interpolator; 72 } 73 74 @Override 75 public Y evaluate() { 76 X point = _variables.get(0).get(); 77 if (point == null) { 78 throw new FunctionException("Variable " + _variables.get(0) + " not set"); 79 } 80 return _interpolator.interpolate(point, _pointValues); 81 } 82 83 @Override 84 public boolean move(ObjectSpace os) { 85 if (super.move(os)) { 86 _variables.move(os); 87 if (_pointValues instanceof Realtime) { 88 ((Realtime) _pointValues).move(os); 89 } 90 return true; 91 } 92 return false; 93 } 94 95 @Override 96 public List <Variable<X>> getVariables() { 97 return _variables; 98 } 99 100 private static final long serialVersionUID = 1L; 101 102 } | Popular Tags |