/* * Oneof.java * */ package test; import com.fiverworks.xone.XoneRuntimeException; public class Oneof implements com.fiverworks.xone.exp.func.IFunction { public Oneof() {} public Object evaluate(Object[] args) { // 引数の個数を調べる if (args.length < 2) throw new XoneRuntimeException("パラメータの数が違います"); // 最初の引数の型を調べる boolean isString; String str1 = null; double dbl1 = 0; if (args[0] instanceof String) { isString = true; str1 = (String)args[0]; } else if (args[0] instanceof Double) { isString = false; dbl1 = ((Double)args[0]).doubleValue(); } else { throw new XoneRuntimeException("パラメータの型が違います"); } // 2番目以降の引数の型を調べる for (int i = 1; i < args.length; i++) { if (isString) { if (!(args[i] instanceof String)) throw new XoneRuntimeException("パラメータの型が違います"); } else { if (!(args[i] instanceof Double)) throw new XoneRuntimeException("パラメータの型が違います"); } } // 処理 for (int i = 1; i < args.length; i++) { if (isString) { String str = (String)args[i]; if (str1.equals(str)) return new Boolean(true); } else { double dbl = ((Double)args[i]).doubleValue(); if (dbl1 == dbl) return new Boolean(true); } } // どれにも一致しない return new Boolean(false); } }