2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

Clover coverage report - Cactus 1.8dev for J2EE API 1.3
Coverage timestamp: Sun Mar 26 2006 18:50:18 BRT
file stats: LOC: 110   Methods: 3
NCLOC: 46   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
UniqueGenerator.java - 0% 0% 0%
coverage
 1   
 /* 
 2   
  * ========================================================================
 3   
  * 
 4   
  * Copyright 2001-2003 The Apache Software Foundation.
 5   
  *
 6   
  * Licensed under the Apache License, Version 2.0 (the "License");
 7   
  * you may not use this file except in compliance with the License.
 8   
  * You may obtain a copy of the License at
 9   
  * 
 10   
  *   http://www.apache.org/licenses/LICENSE-2.0
 11   
  * 
 12   
  * Unless required by applicable law or agreed to in writing, software
 13   
  * distributed under the License is distributed on an "AS IS" BASIS,
 14   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15   
  * See the License for the specific language governing permissions and
 16   
  * limitations under the License.
 17   
  * 
 18   
  * ========================================================================
 19   
  */
 20   
 package org.apache.cactus.internal.util;
 21   
 
 22   
 import java.net.InetAddress;
 23   
 import java.net.UnknownHostException;
 24   
 
 25   
 import junit.framework.TestCase;
 26   
 
 27   
 /**
 28   
  * Generates a quasi-unique id for a test case.
 29   
  *
 30   
  * @version $Id: UniqueGenerator.java 238991 2004-05-22 11:34:50Z vmassol $
 31   
  */
 32   
 public class UniqueGenerator
 33   
 {
 34   
     /**
 35   
      * Counter with synchronized access to prevent possibly
 36   
      * identical ids from two threads requesting an id in the
 37   
      * same millisecond.
 38   
      */
 39   
     private static byte count = 0;
 40   
     
 41   
     /**
 42   
      * Lock for count.
 43   
      */
 44   
     private static Object lock = new Object();
 45   
 
 46   
     /**
 47   
      * The local IP address in hexadecimal format.
 48   
      */
 49   
     private static String ipAddress;
 50   
     static
 51   
     {
 52  0
         try
 53   
         {
 54  0
             byte ip[] = InetAddress.getLocalHost().getAddress();
 55  0
             ipAddress = toHex(((ip[0] & 0xff) << 24)
 56   
                 | ((ip[1] & 0xff) << 16) | ((ip[2] & 0xff) << 8)
 57   
                 | (ip[3] & 0xff));
 58   
         }
 59   
         catch (UnknownHostException e)
 60   
         {
 61  0
             ipAddress = "";
 62   
         }
 63   
     }
 64   
 
 65   
     /**
 66   
      * Generates a unique identifier for a Cactus test.
 67   
      * 
 68   
      * @param theTestCase The Test to generate a unique ID for
 69   
      * @return The generated ID
 70   
      */
 71  0
     public static String generate(TestCase theTestCase)
 72   
     {
 73  0
         long time = System.currentTimeMillis();
 74  0
         synchronized (lock)
 75   
         {
 76  0
             time += count++;
 77   
         }
 78  0
         return generate(theTestCase, time);
 79   
     }
 80   
 
 81   
     /**
 82   
      * Generates a unique identifier for a Cactus test.
 83   
      * 
 84   
      * @param theTestCase The Test to generate a unique ID for
 85   
      * @param theTime The time component to include in the generated ID
 86   
      * @return The generated ID
 87   
      */
 88  0
     public static String generate(TestCase theTestCase,
 89   
         long theTime)
 90   
     {
 91  0
         String id = ipAddress;
 92  0
         id += "-" + toHex(theTime);
 93  0
         id += "-" + toHex(System.identityHashCode(theTestCase));
 94  0
         id += toHex(theTestCase.getName().hashCode());
 95  0
         return id;
 96   
     }
 97   
 
 98   
     /**
 99   
      * Returns the hexadecimal representation of an integer as string.
 100   
      * 
 101   
      * @param theValue The integer value
 102   
      * @return The integer value as string of hexadecimal digits
 103   
      */
 104  0
     private static String toHex(long theValue)
 105   
     {
 106  0
         return Long.toString(theValue, 16).toUpperCase();
 107   
     }
 108   
 
 109   
 }
 110