Java Integer Create toInteger(Object value)

Here you can find the source of toInteger(Object value)

Description

to Integer

License

Open Source License

Declaration

public static Integer toInteger(Object value) 

Method Source Code

//package com.java2s;
/*//from w w w.j  a v a  2s . co m
 * This file is part of the Jose Project
 * see http://jose-chess.sourceforge.net/
 * (c) 2002-2006 Peter Sch?fer
 *
 * 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; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

public class Main {
    public static Integer toInteger(Object value) {
        if (value == null)
            return null; //   easy
        if (value instanceof Integer)
            return (Integer) value;
        if (value instanceof Number)
            return new Integer(((Number) value).intValue());

        String svalue = toString(value);
        if (svalue == null)
            return null;
        else
            return new Integer(svalue);
    }

    public static String toString(Object value) {
        if (value == null)
            return null; //   easy

        String svalue = value.toString();
        if (svalue == null)
            return null;
        svalue = svalue.trim();
        if (svalue.length() == 0)
            return null;
        return svalue;
    }
}

Related

  1. toInteger(Object str)
  2. toInteger(Object val)
  3. toInteger(Object val)
  4. toInteger(Object value)
  5. toInteger(Object value)
  6. toInteger(Object value)
  7. toInteger(Object value)
  8. toInteger(Object value)
  9. toInteger(Object value)