javaextensions/midprms_db/tsrc/rmsbenchmark/javasrc/Utils.java
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 import java.util.Random;
       
    18 
       
    19 public class Utils
       
    20 {
       
    21     public Utils()
       
    22     {
       
    23     }
       
    24 
       
    25     public static void initRandom()
       
    26     {
       
    27         rand = new Random();
       
    28     }
       
    29 
       
    30     public static int random(int int1, int int2)
       
    31     {
       
    32         if (int1 == int2)
       
    33             return int1;
       
    34         int min = Math.min(int1, int2);
       
    35         int max = Math.max(int1, int2);
       
    36         int i = rand.nextInt();
       
    37         if (i < 0)
       
    38             i = -i;
       
    39         return i % (max - min) + min;
       
    40     }
       
    41 
       
    42     public static void startTiming()
       
    43     {
       
    44         startTime = System.currentTimeMillis();
       
    45     }
       
    46 
       
    47     public static void stopTiming()
       
    48     {
       
    49         stopTime = System.currentTimeMillis();
       
    50     }
       
    51 
       
    52     public static String getTime()
       
    53     {
       
    54         return (new Long(stopTime - startTime)).toString();
       
    55     }
       
    56 
       
    57     public static long getDiff()
       
    58     {
       
    59         return stopTime - startTime;
       
    60     }
       
    61 
       
    62     public static String getTime(long aDiff)
       
    63     {
       
    64         return (new Long(aDiff)).toString();
       
    65     }
       
    66 
       
    67     private static long startTime;
       
    68     private static long stopTime;
       
    69     private static Random rand;
       
    70 }