Coverage Report - jaggregate.internal.number.OperableNumberFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
OperableNumberFactory
100%
20/20
100%
8/8
0
 
 1  
 /*
 2  
  Copyright 2004-2008 Paul R. Holser, Jr.  All rights reserved.
 3  
  Licensed under the Academic Free License version 3.0
 4  
  */
 5  
 
 6  
 package jaggregate.internal.number;
 7  
 
 8  
 import java.math.BigDecimal;
 9  
 import java.math.BigInteger;
 10  
 
 11  
 /**
 12  
  * Makes different kinds of {@link OperableNumber}s.
 13  
  *
 14  
  * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
 15  
  * @version $Id: OperableNumberFactory.java,v 1.2 2008/03/30 03:07:11 pholser Exp $
 16  
  */
 17  
 public class OperableNumberFactory {
 18  
     /**
 19  
      * Discourages instantiation.
 20  
      *
 21  
      * @throws UnsupportedOperationException always
 22  
      */
 23  1
     protected OperableNumberFactory() {
 24  1
         throw new UnsupportedOperationException();
 25  
     }
 26  
 
 27  
     /**
 28  
      * Wraps a number.
 29  
      *
 30  
      * @param <E> type of the wrapped number
 31  
      * @param wrapped number to wrap
 32  
      * @return wrapped version of {@code wrapped}
 33  
      */
 34  
     public static <E extends Number> OperableNumber<?> wrap( E wrapped ) {
 35  17597
         Class<?> wrappedClass = wrapped.getClass();
 36  
 
 37  17597
         if ( Integer.class.equals( wrappedClass ) )
 38  2350
             return new OperableInteger( Integer.class.cast( wrapped ) );
 39  
 
 40  15247
         if ( Float.class.equals( wrappedClass ) )
 41  2178
             return new OperableFloat( Float.class.cast( wrapped ) );
 42  
 
 43  13069
         if ( Double.class.equals( wrappedClass ) )
 44  2178
             return new OperableDouble( Double.class.cast( wrapped ) );
 45  
 
 46  10891
         if ( Long.class.equals( wrappedClass ) )
 47  2178
             return new OperableLong( Long.class.cast( wrapped ) );
 48  
 
 49  8713
         if ( Short.class.equals( wrappedClass ) )
 50  2178
             return new OperableShort( Short.class.cast( wrapped ) );
 51  
 
 52  6535
         if ( Byte.class.equals( wrappedClass ) )
 53  2178
             return new OperableByte( Byte.class.cast( wrapped ) );
 54  
 
 55  4357
         if ( BigInteger.class.equals( wrappedClass ) )
 56  2178
             return new OperableBigInteger( BigInteger.class.cast( wrapped ) );
 57  
 
 58  2179
         if ( BigDecimal.class.equals( wrappedClass ) )
 59  2178
             return new OperableBigDecimal( BigDecimal.class.cast( wrapped ) );
 60  
 
 61  1
         throw new AssertionError( "cannot wrap a " + wrappedClass.getName() );
 62  
     }
 63  
 }