Here you can find the source of getProperUnitName(TimeUnit unit, long amount)
Parameter | Description |
---|---|
unit | The unit to beautify |
amount | The amount relevant to the measurement output |
public static String getProperUnitName(TimeUnit unit, long amount)
//package com.java2s; /*/* www . j a v a 2 s . c o m*/ * Copyright (C) 2015 Codelanx, All Rights Reserved * * This work is licensed under a Creative Commons * Attribution-NonCommercial-NoDerivs 3.0 Unported License. * * This program is protected software: You are free to distrubute your * own use of this software under the terms of the Creative Commons BY-NC-ND * license as published by Creative Commons in the year 2015 or as published * by a later date. You may not provide the source files or provide a means * of running the software outside of those licensed to use it. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the Creative Commons BY-NC-ND license * long with this program. If not, see <https://creativecommons.org/licenses/>. */ import java.util.concurrent.TimeUnit; public class Main { /** * Returns the appropriate spelling for a {@link TimeUnit} value based on * the value of the "amount" parameter. Values other than 1 will return a * plural measurement whereas 1 will return a singular measurement. * * @since 0.0.1 * @version 0.1.0 * * @param unit The unit to beautify * @param amount The amount relevant to the measurement output * @return A formatted word */ public static String getProperUnitName(TimeUnit unit, long amount) { String proper = unit.toString().substring(0, 1) + unit.toString().substring(1, unit.toString().length()).toLowerCase(); return amount != 1 ? proper : proper.substring(0, proper.length() - 1); } }