Coverage Report - org.apache.commons.jjar.Version
 
Classes in this File Line Coverage Branch Coverage Complexity
Version
0%
0/39
0%
0/12
1.4
 
 1  
 /*
 2  
  * Copyright 2001,2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.jjar;
 18  
 
 19  
 /**
 20  
  *  simple class to handle JJAR version information
 21  
  *
 22  
  *  should be of format 
 23  
  *     <major>.<minor>-<modifier>
 24  
  *
 25  
  *  @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
 26  
  *  @version $Id: Version.java 155454 2005-02-26 13:23:34Z dirkv $
 27  
  */
 28  
 public class Version
 29  
 {
 30  0
         private static String VER_SEP = ".";
 31  0
         private static String MOD_SEP = "-";
 32  
         
 33  0
         private boolean proper = false;
 34  
         private String version;
 35  0
         private int major = -1;
 36  0
         private int minor = -1;
 37  0
         private String modifier = "";
 38  
 
 39  
         public Version( String version )
 40  0
         {
 41  0
                 this.version = version;
 42  0
                 parse();
 43  0
         }
 44  
 
 45  
         public boolean isProper()
 46  
         {
 47  0
         return proper;
 48  
         }
 49  
 
 50  
     public String toString()
 51  
     {
 52  0
         return version;
 53  
     }
 54  
 
 55  
     public int getMajor()
 56  
     {
 57  0
         return this.major;
 58  
     }
 59  
 
 60  
     public int getMinor()
 61  
     {
 62  0
         return this.minor;
 63  
     }
 64  
 
 65  
     public String getModifier()
 66  
     {
 67  0
         return this.modifier;
 68  
     }
 69  
 
 70  
     public boolean equals( String version )
 71  
     {
 72  0
         Version v = new Version( version );
 73  
 
 74  0
         return equals( v );
 75  
     }
 76  
 
 77  
     public boolean equals( Version v )
 78  
     {
 79  0
         return (v.getMajor() == major  && v.getMinor() == minor && v.getModifier().equals( modifier));
 80  
     }
 81  
           
 82  
         private void parse()
 83  
         {
 84  
                 /*
 85  
                  *  first, look for the separators
 86  
                  */
 87  
 
 88  0
                 int wherever = version.indexOf( VER_SEP );
 89  0
                 int wheremod = version.indexOf( MOD_SEP );
 90  
 
 91  
                 /*
 92  
                  *  we must have the VER_SEP or it's not 
 93  
                  *  properly formatted
 94  
                  */
 95  
 
 96  0
                 if (wherever != -1 )
 97  
                 {
 98  
                         /*
 99  
                          *  major : get the 'left' of VER_SEP
 100  
                          */
 101  
                         
 102  0
                         String maj = version.substring( 0,wherever);
 103  
                         
 104  
                         try
 105  
                         {
 106  0
                                 major = Integer.parseInt( maj );
 107  0
                                 proper = true;
 108  
                         }
 109  0
                         catch( Exception e )
 110  0
                         {}
 111  
 
 112  
             /*
 113  
              *  minor :
 114  
              */
 115  
 
 116  0
                         String min = version.substring( wherever + 1, 
 117  
                                                                                         (wheremod == -1 ? version.length() :  wheremod ) );
 118  
 
 119  
             try
 120  
                         {
 121  0
                                 minor = Integer.parseInt( min );
 122  0
                                 proper = true;
 123  
                         }
 124  0
                         catch( Exception e )
 125  0
                         {}
 126  
                 }
 127  
 
 128  0
         if ( wheremod != -1 )
 129  
         {
 130  
             /*
 131  
              *  now the modifier
 132  
              */
 133  
 
 134  0
             modifier = version.substring( wheremod + 1 );
 135  
         }
 136  
                 
 137  0
         }
 138  
 
 139  
     public static void main( String args[])
 140  
     {
 141  0
         Version jv = new Version( "1.1");
 142  0
         System.out.println( jv.getMajor() + " : " + jv.getMinor() + " : " + jv.getModifier());
 143  
 
 144  0
         jv = new Version( "2.1-rc1");
 145  0
         System.out.println( jv.getMajor() + " : " + jv.getMinor() + " : " + jv.getModifier());
 146  0
     }
 147  
 
 148  
 }
 149  
 
 150  
 
 151