Here you can find the source of compareValues(String value, String type, Object obj)
public static boolean compareValues(String value, String type, Object obj)
//package com.java2s; /*//from w w w. j ava 2 s. com * RHQ Management Platform * Copyright (C) 2005-2013 Red Hat, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ import java.math.BigDecimal; public class Main { public static boolean compareValues(String value, String type, Object obj) { if (value == null && obj == null) return true; if (type.equals("int")) { Integer val = Integer.valueOf(Double.valueOf(value).intValue()); return obj.equals(val); } if (type.equals("double")) { Double val = Double.valueOf(value); Double orig = (Double) obj; orig = round(orig, 1); return obj.equals(val); } if (type.equals("long")) { Long val = Long.valueOf(Double.valueOf(value).longValue()); return obj.equals(val); } String val2 = obj.toString(); if (value.length() != val2.length()) { val2 = val2.substring(0, value.length()); } return value.equals(val2); } private static double round(double d, int decimalPlace) { BigDecimal bd = new BigDecimal(Double.toString(d)); bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } }