Here you can find the source of max(Object o1, Object o2)
public static Number max(Object o1, Object o2)
//package com.java2s; /*/* www.j a v a2 s . c o m*/ * Copyright 2011 Future Systems * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static Number max(Object o1, Object o2) { Number n1 = getValue(o1); Number n2 = getValue(o2); if (n1 == null) return n2; if (n2 == null) return n1; if (n1.doubleValue() > n2.doubleValue()) return n1; else return n2; } public static Number getValue(Object obj) { return getValue(obj, null); } public static Number getValue(Object obj, Number defaultValue) { if (obj == null) return defaultValue; try { return Long.parseLong(obj.toString()); } catch (NumberFormatException e) { } try { return Double.parseDouble(obj.toString()); } catch (NumberFormatException e) { } if (obj.toString().startsWith("0x")) { try { return Long.parseLong(obj.toString().substring(2), 16); } catch (NumberFormatException e) { } } return defaultValue; } }