Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.util.Log;

public class Main {
    private static final String TAG = "WareNinjaUtils";
    private static Integer mMaxInt = Integer.valueOf(Integer.MAX_VALUE);

    public static Integer stringToInteger(String str) {
        if (str == null) {
            return null;
        } else {
            try {
                return Integer.parseInt(str);
            } catch (NumberFormatException e) {
                try {
                    Double d = Double.valueOf(str);
                    if (d.doubleValue() > mMaxInt.doubleValue() + 1.0) {
                        Log.w(TAG, "Value " + d + " too large for integer");
                        return null;
                    }
                    return Integer.valueOf(d.intValue());
                } catch (NumberFormatException nfe2) {
                    Log.w(TAG,
                            "Unable to interpret value " + str + " in field being "
                                    + "converted to int, caught NumberFormatException <" + e.getMessage()
                                    + "> field discarded");
                    return null;
                }
            }
        }
    }
}