Java TimeUnit Calculate getProperUnitName(TimeUnit unit, long amount)

Here you can find the source of getProperUnitName(TimeUnit unit, long amount)

Description

Returns the appropriate spelling for a TimeUnit value based on the value of the "amount" parameter.

License

Open Source License

Parameter

Parameter Description
unit The unit to beautify
amount The amount relevant to the measurement output

Return

A formatted word

Declaration

public static String getProperUnitName(TimeUnit unit, long amount) 

Method Source Code


//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);
    }
}

Related

  1. getInterval(final Date startDate, final Date endDate, final TimeUnit timeUnit)
  2. getIntervalInfo(long intervalDuration, TimeUnit unit)
  3. getMilliseconds(int interval, TimeUnit unit)
  4. getNowTimeUnit(TimeUnit timeUnit)
  5. getParentUnit(TimeUnit unit)
  6. getRandomTimeRound(int _duration, TimeUnit _unit)
  7. getTimeBucket(TimeUnit unit, long timestamp, int bucketSizeInSeconds)
  8. getTimeInMillis(TimeUnit unit)
  9. getTimeString(long value, TimeUnit unit)