| 1 | package de.uka.ipd.sdq.simucomframework.variables.functions; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
| 5 | public class RoundFunction implements IFunction { |
| 6 | /** Name used in the stochastic expression for this function. */ |
| 7 | public static final String ROUND_FUNCTION_NAME = "Round"; |
| 8 | |
| 9 | public boolean checkParameters(List<Object> parameters) { |
| 10 | if (parameters.size() != 1) |
| 11 | return false; |
| 12 | if (!(parameters.get(0) instanceof Double) && !(parameters.get(0) instanceof Integer)) |
| 13 | return false; |
| 14 | return true; |
| 15 | } |
| 16 | |
| 17 | public Object evaluate(List<Object> parameters) { |
| 18 | if (parameters.get(0) instanceof Integer) |
| 19 | return parameters.get(0); |
| 20 | return (int)Math.round((Double)parameters.get(0)); |
| 21 | } |
| 22 | |
| 23 | } |