Java TimeUnit Convert convertReportingPeriod(long profilePeriod, TimeUnit profileTimeUnit, long reportingPeriod, TimeUnit reportingTimeUnit)

Here you can find the source of convertReportingPeriod(long profilePeriod, TimeUnit profileTimeUnit, long reportingPeriod, TimeUnit reportingTimeUnit)

Description

Convert a reporting period into the time scale of a profiling period

License

Open Source License

Parameter

Parameter Description
profilePeriod The profiling period
profileTimeUnit The TimeUnit for the profiling period
reportingPeriod The reporting period
reportingTimeUnit The TimeUnit for the reporting period

Return

The reporting period scaled to the profiling period (i.e. suitable for use like x % convertReportingPeriod(...) == 0)

Declaration

public static long convertReportingPeriod(long profilePeriod, TimeUnit profileTimeUnit, long reportingPeriod,
        TimeUnit reportingTimeUnit) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.TimeUnit;

public class Main {
    /**//from  w w  w.j  av a  2 s  .  c  om
     * Convert a reporting period into the time scale of a profiling period
     *
     * @param profilePeriod The profiling period
     * @param profileTimeUnit The TimeUnit for the profiling period
     * @param reportingPeriod The reporting period
     * @param reportingTimeUnit The TimeUnit for the reporting period
     * @return The reporting period scaled to the profiling period (i.e. suitable for use like x % convertReportingPeriod(...) == 0)
     */
    public static long convertReportingPeriod(long profilePeriod, TimeUnit profileTimeUnit, long reportingPeriod,
            TimeUnit reportingTimeUnit) {
        long convertedReportingPeriod = profileTimeUnit.convert(reportingPeriod, reportingTimeUnit);

        // If we profile less frequently than we want report, returning 1 would indicate we should always report
        if (convertedReportingPeriod <= profilePeriod) {
            return 1;
        }

        return convertedReportingPeriod / profilePeriod;
    }
}

Related

  1. convert(double t, TimeUnit sourceUnit, TimeUnit destinationUnit)
  2. convert(long time, TimeUnit src, TimeUnit dst)
  3. convert(long time, TimeUnit unitIn, TimeUnit unitOut)
  4. convert(TimeUnit unitTo, TimeUnit unitFrom, long cnt)
  5. convertTo(long a, TimeUnit from, TimeUnit to)
  6. convertToDouble(long fromTime, TimeUnit fromTimeUnit, TimeUnit toTimeUnit)
  7. convertToMillis(long waitTime, TimeUnit timeUnit)
  8. convertToMilliseconds(TimeUnit timeUnit, long seed)