Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 *   Copyright (c) 2014-2015 Luis M. Gallardo D.
 *   All rights reserved. This program and the accompanying materials
 *   are made available under the terms of the GNU Lesser General Public License v3.0
 *   which accompanies this distribution, and is available at
 *   http://www.gnu.org/licenses/lgpl.html
 *
 */

public class Main {
    public static double humanSizeToBytes(String value) {
        String scalar;
        int unit = 1024;
        int exp;
        char c;
        double returnValue = 0;

        String[] words = value.split("\\s+");

        //        Log.d("Debug", "words length:" + words.length);

        if (words.length == 2) {

            //            Log.d("Debug", "words[0]:" + words[0]);
            //            Log.d("Debug", "words[1]:" + words[1]);

            try {
                scalar = words[0].replace(",", ".");

                //                Log.d("Debug", "scalar:" + scalar);

                exp = "BKMGTPE".indexOf((words[1]).toCharArray()[0]);

                //                Log.d("Debug", "exp:" + exp);

                returnValue = Double.parseDouble(scalar) * Math.pow(unit, exp);

            } catch (Exception e) {
            }

        }

        return returnValue;
    }
}