Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 283   Methods: 10
NCLOC: 117   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DeweyDecimal.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.optional.extension;
 55   
 
 56   
 import java.util.StringTokenizer;
 57   
 
 58   
 /**
 59   
  * Utility class to contain version numbers in "Dewey Decimal"
 60   
  * syntax.  Numbers in the "Dewey Decimal" syntax consist of positive
 61   
  * decimal integers separated by periods ".".  For example, "2.0" or
 62   
  * "1.2.3.4.5.6.7".  This allows an extensible number to be used to
 63   
  * represent major, minor, micro, etc versions.  The version number
 64   
  * must begin with a number.
 65   
  *
 66   
  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
 67   
  *  This file is from excalibur.extension package. Dont edit this file
 68   
  * directly as there is no unit tests to make sure it is operational
 69   
  * in ant. Edit file in excalibur and run tests there before changing
 70   
  * ants file.
 71   
  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
 72   
  *
 73   
  * @author <a href="mailto:peter@apache.org">Peter Donald</a>
 74   
  * @version $Revision: 1.3 $ $Date: 2003/02/10 14:14:03 $
 75   
  */
 76   
 public final class DeweyDecimal
 77   
 {
 78   
     ///Array of components that make up DeweyDecimal
 79   
     private int[] m_components;
 80   
 
 81   
     /**
 82   
      * Construct a DeweyDecimal from an array of integer components.
 83   
      *
 84   
      * @param components an array of integer components.
 85   
      */
 86  0
     public DeweyDecimal( final int[] components )
 87   
     {
 88  0
         m_components = new int[ components.length ];
 89   
 
 90  0
         for( int i = 0; i < m_components.length; i++ )
 91   
         {
 92  0
             m_components[ i ] = components[ i ];
 93   
         }
 94   
     }
 95   
 
 96   
     /**
 97   
      * Construct a DeweyDecimal from string in DeweyDecimal format.
 98   
      *
 99   
      * @param string the string in dewey decimal format
 100   
      * @exception NumberFormatException if string is malformed
 101   
      */
 102  0
     public DeweyDecimal( final String string )
 103   
         throws NumberFormatException
 104   
     {
 105  0
         final StringTokenizer tokenizer = new StringTokenizer( string, ".", true );
 106  0
         final int size = tokenizer.countTokens();
 107   
 
 108  0
         m_components = new int[ ( size + 1 ) / 2 ];
 109   
 
 110  0
         for( int i = 0; i < m_components.length; i++ )
 111   
         {
 112  0
             final String component = tokenizer.nextToken();
 113  0
             if( component.equals( "" ) )
 114   
             {
 115  0
                 throw new NumberFormatException( "Empty component in string" );
 116   
             }
 117   
 
 118  0
             m_components[ i ] = Integer.parseInt( component );
 119   
 
 120   
             //Strip '.' token
 121  0
             if( tokenizer.hasMoreTokens() )
 122   
             {
 123  0
                 tokenizer.nextToken();
 124   
 
 125   
                 //If it ended in a dot, throw an exception
 126  0
                 if( !tokenizer.hasMoreTokens() )
 127   
                 {
 128  0
                     throw new NumberFormatException( "DeweyDecimal ended in a '.'" );
 129   
                 }
 130   
             }
 131   
         }
 132   
     }
 133   
 
 134   
     /**
 135   
      * Return number of components in <code>DeweyDecimal</code>.
 136   
      *
 137   
      * @return the number of components in dewey decimal
 138   
      */
 139  0
     public int getSize()
 140   
     {
 141  0
         return m_components.length;
 142   
     }
 143   
 
 144   
     /**
 145   
      * Return the component at specified index.
 146   
      *
 147   
      * @param index the index of components
 148   
      * @return the value of component at index
 149   
      */
 150  0
     public int get( final int index )
 151   
     {
 152  0
         return m_components[ index ];
 153   
     }
 154   
 
 155   
     /**
 156   
      * Return <code>true</code> if this <code>DeweyDecimal</code> is
 157   
      * equal to the other <code>DeweyDecimal</code>.
 158   
      *
 159   
      * @param other the other DeweyDecimal
 160   
      * @return true if equal to other DeweyDecimal, false otherwise
 161   
      */
 162  0
     public boolean isEqual( final DeweyDecimal other )
 163   
     {
 164  0
         final int max = Math.max( other.m_components.length, m_components.length );
 165   
 
 166  0
         for( int i = 0; i < max; i++ )
 167   
         {
 168  0
             final int component1 = ( i < m_components.length ) ? m_components[ i ] : 0;
 169  0
             final int component2 = ( i < other.m_components.length ) ? other.m_components[ i ] : 0;
 170   
 
 171  0
             if( component2 != component1 )
 172   
             {
 173  0
                 return false;
 174   
             }
 175   
         }
 176   
 
 177  0
         return true; // Exact match
 178   
     }
 179   
 
 180   
     /**
 181   
      * Return <code>true</code> if this <code>DeweyDecimal</code> is
 182   
      * less than the other <code>DeweyDecimal</code>.
 183   
      *
 184   
      * @param other the other DeweyDecimal
 185   
      * @return true if less than other DeweyDecimal, false otherwise
 186   
      */
 187  0
     public boolean isLessThan( final DeweyDecimal other )
 188   
     {
 189  0
         return !isGreaterThanOrEqual( other );
 190   
     }
 191   
 
 192   
     /**
 193   
      * Return <code>true</code> if this <code>DeweyDecimal</code> is
 194   
      * less than or equal to the other <code>DeweyDecimal</code>.
 195   
      *
 196   
      * @param other the other DeweyDecimal
 197   
      * @return true if less than or equal to other DeweyDecimal, false otherwise
 198   
      */
 199  0
     public boolean isLessThanOrEqual( final DeweyDecimal other )
 200   
     {
 201  0
         return !isGreaterThan( other );
 202   
     }
 203   
 
 204   
     /**
 205   
      * Return <code>true</code> if this <code>DeweyDecimal</code> is
 206   
      * greater than the other <code>DeweyDecimal</code>.
 207   
      *
 208   
      * @param other the other DeweyDecimal
 209   
      * @return true if greater than other DeweyDecimal, false otherwise
 210   
      */
 211  0
     public boolean isGreaterThan( final DeweyDecimal other )
 212   
     {
 213  0
         final int max = Math.max( other.m_components.length, m_components.length );
 214   
 
 215  0
         for( int i = 0; i < max; i++ )
 216   
         {
 217  0
             final int component1 = ( i < m_components.length ) ? m_components[ i ] : 0;
 218  0
             final int component2 = ( i < other.m_components.length ) ? other.m_components[ i ] : 0;
 219   
 
 220  0
             if( component2 > component1 )
 221   
             {
 222  0
                 return false;
 223   
             }
 224  0
             if( component2 < component1 )
 225   
             {
 226  0
                 return true;
 227   
             }
 228   
         }
 229   
 
 230  0
         return false; // Exact match
 231   
     }
 232   
 
 233   
     /**
 234   
      * Return <code>true</code> if this <code>DeweyDecimal</code> is
 235   
      * greater than or equal to the other <code>DeweyDecimal</code>.
 236   
      *
 237   
      * @param other the other DeweyDecimal
 238   
      * @return true if greater than or equal to other DeweyDecimal, false otherwise
 239   
      */
 240  0
     public boolean isGreaterThanOrEqual( final DeweyDecimal other )
 241   
     {
 242  0
         final int max = Math.max( other.m_components.length, m_components.length );
 243   
 
 244  0
         for( int i = 0; i < max; i++ )
 245   
         {
 246  0
             final int component1 = ( i < m_components.length ) ? m_components[ i ] : 0;
 247  0
             final int component2 = ( i < other.m_components.length ) ? other.m_components[ i ] : 0;
 248   
 
 249  0
             if( component2 > component1 )
 250   
             {
 251  0
                 return false;
 252   
             }
 253  0
             if( component2 < component1 )
 254   
             {
 255  0
                 return true;
 256   
             }
 257   
         }
 258   
 
 259  0
         return true; // Exact match
 260   
     }
 261   
 
 262   
     /**
 263   
      * Return string representation of <code>DeweyDecimal</code>.
 264   
      *
 265   
      * @return the string representation of DeweyDecimal.
 266   
      */
 267  0
     public String toString()
 268   
     {
 269  0
         final StringBuffer sb = new StringBuffer();
 270   
 
 271  0
         for( int i = 0; i < m_components.length; i++ )
 272   
         {
 273  0
             if( i != 0 )
 274   
             {
 275  0
                 sb.append( '.' );
 276   
             }
 277  0
             sb.append( m_components[ i ] );
 278   
         }
 279   
 
 280  0
         return sb.toString();
 281   
     }
 282   
 }
 283