public double scalar(Collection values) { CodeBlockTrace trace = new AbstractFunction.ScalarFunctionTrace(CODE, values).begin(); try { if (values == null || values.isEmpty()) return 0; // Return the number of distinct items in the collection. Set distincts = new HashSet(); Iterator it = values.iterator(); while (it.hasNext()) { Object o = it.next(); if (distincts.contains(o)) continue; distincts.add(o); } return distincts.size(); } finally { trace.end(); } } }
public double scalar(Collection values) { double ret; CodeBlockTrace trace = new ScalarFunctionTrace(CODE, values).begin(); try { if (values == null || values.isEmpty()) return 0; // Get the max. value from the collection. Number min = null; Iterator it = values.iterator(); while (it.hasNext()) { Number n = (Number) it.next(); if (n == null) continue; if (min == null || n.doubleValue() < min.doubleValue()) min = n; } // Adjust to the specified precision. if (min == null) return 0; ret = round(min.doubleValue(), precission); } finally { trace.end(); } return ret; } }
public double scalar(Collection values) { double ret; CodeBlockTrace trace = new ScalarFunctionTrace(CODE, values).begin(); try { if (values == null || values.isEmpty()) return 0; // Get the max. value from the collection. Number max = null; Iterator it = values.iterator(); while (it.hasNext()) { Number n = (Number) it.next(); if (n == null) continue; if (max == null || n.doubleValue() > max.doubleValue()) max = n; } // Adjust to the specified precission. if (max == null) return 0; ret = round(max.doubleValue(), precission); } finally { trace.end(); } return ret; } }
public double scalar(Collection values) { double ret; CodeBlockTrace trace = new ScalarFunctionTrace(CODE, values).begin(); try { if (values == null || values.isEmpty()) return 0; // Sum the collection. double sum = 0; Iterator it = values.iterator(); while (it.hasNext()) { Number n = (Number) it.next(); if (n == null) continue; sum += n.doubleValue(); } ret = round(sum, precission); } finally { trace.end(); } // Adjust to the specified precision. return ret; } }
public double scalar(Collection values) { double ret; CodeBlockTrace trace = new ScalarFunctionTrace(CODE, values).begin(); try { if (values == null || values.isEmpty()) return 0; double average = super.scalar(values) / values.size(); ret = round(average, precission); } finally { trace.end(); } // Adjust to the specified precission. return ret; }
public double scalar(Collection values) { CodeBlockTrace trace = new ScalarFunctionTrace(CODE, values).begin(); try { if (values == null || values.isEmpty()) return 0; return values.size(); } finally { trace.end(); } } }