Coverage Report - org.apache.maven.plugin.ear.util.JavaEEVersion
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaEEVersion
0%
0/28
0%
0/26
1.8
 
 1  
 package org.apache.maven.plugin.ear.util;
 2  
 
 3  
 import java.util.HashMap;
 4  
 import java.util.Map;
 5  
 
 6  
 /**
 7  
  * Represents the supported JavaEE version.
 8  
  *
 9  
  * @author Stephane Nicoll
 10  
  */
 11  
 public class JavaEEVersion
 12  
     implements Comparable
 13  
 {
 14  
 
 15  
     private static final String VERSION_1_3 = "1.3";
 16  
 
 17  
     private static final String VERSION_1_4 = "1.4";
 18  
 
 19  
     private static final String VERSION_5 = "5";
 20  
 
 21  
     private static final String VERSION_6 = "6";
 22  
 
 23  0
     private static final Map versionsMap = new HashMap();
 24  
 
 25  
 
 26  
     /**
 27  
      * Represents the J2EE 1.3 version.
 28  
      */
 29  0
     public static final JavaEEVersion OneDotThree = new JavaEEVersion( new Integer( 0 ), VERSION_1_3 );
 30  
 
 31  
     /**
 32  
      * Represents the J2EE 1.4 version.
 33  
      */
 34  0
     public static final JavaEEVersion OneDotFour = new JavaEEVersion( new Integer( 1 ), VERSION_1_4 );
 35  
 
 36  
     /**
 37  
      * Represents the JavaEE 5 version.
 38  
      */
 39  0
     public static final JavaEEVersion Five = new JavaEEVersion( new Integer( 2 ), VERSION_5 );
 40  
 
 41  
     /**
 42  
      * Represents the JavaEE 7 version.
 43  
      */
 44  0
     public static final JavaEEVersion Six = new JavaEEVersion( new Integer( 3 ), VERSION_6 );
 45  
 
 46  
 
 47  
     private final Integer index;
 48  
 
 49  
     private final String version;
 50  
 
 51  
     private JavaEEVersion( Integer index, String version )
 52  0
     {
 53  0
         this.index = index;
 54  0
         this.version = version;
 55  0
         versionsMap.put( version, this );
 56  0
     }
 57  
 
 58  
     public static JavaEEVersion getJavaEEVersion( String version )
 59  
         throws InvalidJavaEEVersion
 60  
     {
 61  0
         if ( !isValid( version ) )
 62  
         {
 63  0
             throw new InvalidJavaEEVersion( "Invalid version [" + version + "]", version );
 64  
         }
 65  0
         return (JavaEEVersion) versionsMap.get( version );
 66  
     }
 67  
 
 68  
     /**
 69  
      * Returns the version as a string.
 70  
      *
 71  
      * @return the version string
 72  
      */
 73  
     public String getVersion()
 74  
     {
 75  0
         return version;
 76  
     }
 77  
 
 78  
     /**
 79  
      * Specifies if this version is greater or equal to the specified version.
 80  
      *
 81  
      * @param version the version to check
 82  
      * @return true if this version is greater or equal to <tt>version</tt>
 83  
      */
 84  
     public boolean ge( JavaEEVersion version )
 85  
     {
 86  0
         return this.compareTo( version ) >= 0;
 87  
     }
 88  
 
 89  
     /**
 90  
      * Specifies if this version is greater than the specified version.
 91  
      *
 92  
      * @param version the version to check
 93  
      * @return true if this version is greater to <tt>version</tt>
 94  
      */
 95  
     public boolean gt( JavaEEVersion version )
 96  
     {
 97  0
         return this.compareTo( version ) > 0;
 98  
     }
 99  
 
 100  
     /**
 101  
      * Specifies if this version is equal to the specified version.
 102  
      *
 103  
      * @param version the version to check
 104  
      * @return true if this version is equal to <tt>version</tt>
 105  
      */
 106  
     public boolean eq( JavaEEVersion version )
 107  
     {
 108  0
         return this.compareTo( version ) == 0;
 109  
     }
 110  
 
 111  
     /**
 112  
      * Specifies if this version is less or equal to the specified version.
 113  
      *
 114  
      * @param version the version to check
 115  
      * @return true if this version is less or equal to <tt>version</tt>
 116  
      */
 117  
     public boolean le( JavaEEVersion version )
 118  
     {
 119  0
         return this.compareTo( version ) <= 0;
 120  
     }
 121  
 
 122  
 
 123  
     /**
 124  
      * Specifies if this version is less than the specified version.
 125  
      *
 126  
      * @param version the version to check
 127  
      * @return true if this version is less or equal to <tt>version</tt>
 128  
      */
 129  
     public boolean lt( JavaEEVersion version )
 130  
     {
 131  0
         return this.compareTo( version ) < 0;
 132  
     }
 133  
 
 134  
     /**
 135  
      * Checks if the specified version string is valid.
 136  
      *
 137  
      * @param version the version string to check
 138  
      * @return <tt>true</tt> if the version is valid
 139  
      */
 140  
     private static boolean isValid( String version )
 141  
     {
 142  0
         if ( version == null )
 143  
         {
 144  0
             throw new IllegalArgumentException( "version could not be null." );
 145  
         }
 146  0
         return VERSION_1_3.equals( version ) || VERSION_1_4.equals( version ) || VERSION_5.equals( version ) ||
 147  
             VERSION_6.equals( version );
 148  
     }
 149  
 
 150  
     public int compareTo( Object other )
 151  
     {
 152  0
         if ( other == null )
 153  
         {
 154  0
             throw new IllegalArgumentException( "other object to compare to could not be null." );
 155  
         }
 156  0
         if ( !( other instanceof JavaEEVersion ) )
 157  
         {
 158  0
             throw new IllegalArgumentException(
 159  
                 "other object to compare must be a JavaEEVersion but was [" + other.getClass().getName() + "]" );
 160  
         }
 161  0
         final JavaEEVersion otherVersion = (JavaEEVersion) other;
 162  0
         return index.compareTo( otherVersion.index );
 163  
     }
 164  
 }