package com.onaro.util.jfc.tables.filter; import com.onaro.sanscreen.client.view.tabular.value.*; public class NumberColumnFilter extends NumberFilter { private String format; public NumberColumnFilter(){ this(null); } public NumberColumnFilter(final String format) { super(); this.format = format; } public boolean isAccepted(Object value) { if (value == null) return false; if (value instanceof Number) { Number number = (Number)value; return super.isAccepted(Double.valueOf(number.doubleValue())); } NumberValue numValue = (NumberValue) value; // Bug 12098 - Distribution and Utilization columns are not filtered correctly return super.isAccepted(figureOutFormat(numValue)); } /** * Returns the value that is going to be used for filtering purposes.

* * Based on "config.xml" property named "format", a Column may be set to display percentages. In this situation the
* value displayed is not the original raw numeric value.

* * When format="percent" a raw value is a decimal number usually between 0 and 1. On the other hand, a display value will represent a percentage number between 0 and 100 * plus a "%" symbol at the end

* * This method will check format in order to return the right value used during filtering. * * @param numValue original raw numeric value. * @return modified value affected by its format. */ private Double figureOutFormat(final NumberValue numValue) { // In case the format is "percent" if ("percent".equals(format)){ //$NON-NLS-1$ String cacheStringValue = numValue.toString(); int idx = cacheStringValue.indexOf("%"); //$NON-NLS-1$ if (idx != -1){ cacheStringValue = cacheStringValue.substring(0, idx); } return Double.valueOf(cacheStringValue); } // Default behaviour. return Double.valueOf(numValue.getNumber()); } }