Java Memory normalizeMemoryMeasure(String memory)

Here you can find the source of normalizeMemoryMeasure(String memory)

Description

Normalizes the string memory measurement to a MB integer value.

License

Open Source License

Parameter

Parameter Description
memory Manifest memory measurement.

Return

Normalized MB integer value.

Declaration

public static int normalizeMemoryMeasure(String memory) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 IBM Corporation and others 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * // w  w w . j a va 2s . c om
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Normalizes the string memory measurement to a MB integer value.
     * @param memory Manifest memory measurement.
     * @return Normalized MB integer value.
     */
    public static int normalizeMemoryMeasure(String memory) {

        if (memory.toLowerCase().endsWith("m")) //$NON-NLS-1$
            return Integer.parseInt(memory.substring(0, memory.length() - 1));

        if (memory.toLowerCase().endsWith("mb")) //$NON-NLS-1$
            return Integer.parseInt(memory.substring(0, memory.length() - 2));

        if (memory.toLowerCase().endsWith("g")) //$NON-NLS-1$
            return (1024 * Integer.parseInt(memory.substring(0, memory.length() - 1)));

        if (memory.toLowerCase().endsWith("gb")) //$NON-NLS-1$
            return (1024 * Integer.parseInt(memory.substring(0, memory.length() - 2)));

        /* return default memory value, i.e. 1024 MB */
        return 1024;
    }
}

Related

  1. memoryIsLow()
  2. memoryOccupied()
  3. memorySize(long bytesSize)
  4. memoryUtilization()
  5. memoryValue(long inBytes)
  6. percentMemoryFull()
  7. removeSliceFromMemory(String schemaName, String cubeName, String loadName)
  8. reportMemory()
  9. reportMemory(double val)