alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.core.perftool;

/** Class with several utility methods
 *
 */
public final class Util {

    /** flag */
    private static int run = -1;

    /** No instances */
    private Util() {
    }
    
    /** Utility method used to converting milliseconds and
     * bytes to seconds and mega bytes.
     * @param l a number
     * @param radix divider used for conversion from B to MB (1024 * 1024) or from ms to s (1000)
     * @param power number of figures after comma 3->10,283 2->10,28
     */
    public static String long2Print(long l, float radix, int power) {
        double tenpower = tenpower(power);
        double first = ((double) l) / radix;
        long sec = (long) (first * tenpower);
        first = ((double) sec) / tenpower;
        return String.valueOf(first);
    }
    
    /** 0->1, 1->10, 2->100, 3->1000, ... */
    static double tenpower(int power) {
        double ret = 1f;
        double iter = 0f;
        double npower = 10f;
        while (power > 0) {
            iter = (power % 2) * npower;
            if (iter > 0) {
                ret *= iter;
            }
            npower = Math.pow(npower, 2f);
            power /= 2;
        };
        return ret;
    }

    /** Waits for system threads - AWT, RequestProcessor */
    public static void waitForSystemThreads() {
        if (isRunning()) {
            Runnable run = new EmptyRunnable();
            org.openide.util.Task task = org.openide.util.RequestProcessor.postRequest(run);
            task.waitFinished();
            try {
                java.awt.EventQueue.invokeAndWait(run);
            } catch (Exception e) {
            }
        }
    }
    
    /** @return true if this PerformanceMeterImpl is
     * switched on.
     */
    public static boolean isRunning() {
        if (run == -1) {
            String prop = System.getProperty(PerformanceMeter.NAMING_NAME);
            run = (prop == null ? 0 : 1);
        }
        
        return (run == 1);
    }
    
    /** Empty implementation of Runnable */
    private static final class EmptyRunnable implements Runnable {
        EmptyRunnable() {}
        public void run() {
        }
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.