Here you can find the source of convertSizeG1DetailsToSizeG1(final String size, final char units)
Parameter | Description |
---|---|
size | The size (e.g. '128.0'). |
units | The units (e.g. 'G'). |
public static String convertSizeG1DetailsToSizeG1(final String size, final char units)
//package com.java2s; /********************************************************************************************************************** * garbagecat * * * * Copyright (c) 2008-2016 Red Hat, Inc. * * * * 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. * * * * Contributors: * * Red Hat, Inc. - initial API and implementation * *********************************************************************************************************************/ import java.math.BigDecimal; import java.math.RoundingMode; public class Main { /**// w w w .j av a 2 s .com * Convert SIZE_G1_DETAILS to SIZE_G1. * * @param size * The size (e.g. '128.0'). * @param units * The units (e.g. 'G'). * @return The size block in G1 format (e.g. '131072M'). */ public static String convertSizeG1DetailsToSizeG1(final String size, final char units) { BigDecimal sizeG1 = new BigDecimal(size); char unitsG1; switch (units) { case 'B': // Convert to K sizeG1 = sizeG1.divide(new BigDecimal("1024")); unitsG1 = 'K'; break; case 'K': unitsG1 = 'K'; break; case 'M': unitsG1 = 'M'; break; case 'G': // Convert to M sizeG1 = sizeG1.multiply(new BigDecimal("1024")); unitsG1 = 'M'; break; default: throw new AssertionError("Unexpected units value: " + units); } sizeG1 = sizeG1.setScale(0, RoundingMode.HALF_EVEN); return Integer.toString(sizeG1.intValue()) + unitsG1; } }