001    package org.hackystat.telemetry.analyzer.function.impl;
002    
003    import org.hackystat.telemetry.analyzer.function.TelemetryFunction;
004    import org.hackystat.telemetry.analyzer.function.TelemetryFunctionException;
005    
006    /**
007     * Accepts either a number or a telemetry stream and returns it. 
008     * 
009     * @author (Cedric) Qin ZHANG, Philip Johnson
010     */
011    public class IdempotentFunction extends TelemetryFunction {
012    
013      /**
014       * Constructs this instance.
015       */
016      public IdempotentFunction() {
017        super("idempotent");
018      }
019      
020     /**
021      * @param parameters An array of 1 object of type either <code>Number</code> 
022      *        or <code>TelemetryStreamCollection</code>. 
023      * 
024      * @return Either an instance of <code>Number</code> or <code>TelemetryStreamCollection</code>. 
025      * 
026      * @throws TelemetryFunctionException If anything is wrong.
027      */
028      @Override
029      public Object compute(Object[] parameters) throws TelemetryFunctionException {
030        if (parameters.length == 1) {
031          return parameters[0];
032        }
033        else {
034          throw new TelemetryFunctionException("Telemetry function " + this.getName()
035              + " takes 1 parameter.");
036        }
037      }
038    }