Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 172   Methods: 13
NCLOC: 132   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
Version.java 36.7% 52.3% 46.2% 47.2%
coverage coverage
 1    package org.jboss.cache;
 2   
 3    import java.util.StringTokenizer;
 4   
 5    /**
 6    * Contains version information about this release of JBoss Cache.
 7    *
 8    * @author Bela Ban
 9    * @version $Id: Version.java,v 1.33 2007/06/12 07:41:03 msurtani Exp $
 10    */
 11    public class Version
 12    {
 13    public static final String version = "2.0.0.CR3";
 14    public static final String codename = "Habanero";
 15    public static byte[] version_id = {'0', '2', '0', '0', 'c'};
 16    public static final String cvs = "$Id: Version.java,v 1.33 2007/06/12 07:41:03 msurtani Exp $";
 17   
 18    private static final int MAJOR_SHIFT = 11;
 19    private static final int MINOR_SHIFT = 6;
 20    private static final int MAJOR_MASK = 0x00f800;
 21    private static final int MINOR_MASK = 0x0007c0;
 22    private static final int PATCH_MASK = 0x00003f;
 23   
 24    private static final short SHORT_1_2_3 = encodeVersion(1, 2, 3);
 25    private static final short SHORT_1_2_4_SP2 = encodeVersion(1, 2, 4);
 26   
 27    /**
 28    * Prints version information.
 29    */
 30  0 public static void main(String[] args)
 31    {
 32  0 System.out.println("\nVersion: \t" + version);
 33  0 System.out.println("Codename: \t" + codename);
 34  0 System.out.println("CVS: \t" + cvs);
 35  0 System.out.println("History: \t(see http://jira.jboss.com/jira/browse/JBCACHE for details)\n");
 36    }
 37   
 38    /**
 39    * Returns version information as a string.
 40    */
 41  3752 public static String printVersion()
 42    {
 43  3752 return "JBossCache '" + codename + "' " + version + "[ " + cvs + "]";
 44    }
 45   
 46  0 public static String printVersionId(byte[] v, int len)
 47    {
 48  0 StringBuffer sb = new StringBuffer();
 49  0 if (v != null)
 50    {
 51  0 if (len <= 0)
 52  0 len = v.length;
 53  0 for (int i = 0; i < len; i++)
 54  0 sb.append((char) v[i]);
 55    }
 56  0 return sb.toString();
 57    }
 58   
 59  0 public static String printVersionId(byte[] v)
 60    {
 61  0 StringBuffer sb = new StringBuffer();
 62  0 if (v != null)
 63    {
 64  0 for (byte aV : v) sb.append((char) aV);
 65    }
 66  0 return sb.toString();
 67    }
 68   
 69   
 70  0 public static boolean compareTo(byte[] v)
 71    {
 72  0 if (v == null)
 73  0 return false;
 74  0 if (v.length < version_id.length)
 75  0 return false;
 76  0 for (int i = 0; i < version_id.length; i++)
 77    {
 78  0 if (version_id[i] != v[i])
 79  0 return false;
 80    }
 81  0 return true;
 82    }
 83   
 84  0 public static int getLength()
 85    {
 86  0 return version_id.length;
 87    }
 88   
 89  289 public static short getVersionShort()
 90    {
 91  289 return getVersionShort(version);
 92    }
 93   
 94  654 public static short getVersionShort(String versionString)
 95    {
 96  654 if (versionString == null)
 97  0 throw new IllegalArgumentException("versionString is null");
 98   
 99    // Special cases for version prior to 1.2.4.SP2
 100  654 if ("1.2.4".equals(versionString))
 101  1 return 124;
 102  653 else if ("1.2.4.SP1".equals(versionString))
 103  1 return 1241;
 104   
 105  652 StringTokenizer tokenizer = new StringTokenizer(versionString, ".");
 106   
 107  652 int major = 0;
 108  652 int minor = 0;
 109  652 int patch = 0;
 110   
 111  652 if (tokenizer.hasMoreTokens())
 112  652 major = Integer.parseInt(tokenizer.nextToken());
 113  652 if (tokenizer.hasMoreTokens())
 114  652 minor = Integer.parseInt(tokenizer.nextToken());
 115  652 if (tokenizer.hasMoreTokens())
 116  649 patch = Integer.parseInt(tokenizer.nextToken());
 117   
 118  649 return encodeVersion(major, minor, patch);
 119    }
 120   
 121  1482 public static String getVersionString(short versionShort)
 122    {
 123  1482 if (versionShort == SHORT_1_2_4_SP2)
 124  1 return "1.2.4.SP2";
 125   
 126  1481 switch (versionShort)
 127    {
 128  1 case 124:
 129  1 return "1.2.4";
 130  1 case 1241:
 131  1 return "1.2.4.SP1";
 132  1479 default:
 133  1479 return decodeVersion(versionShort);
 134    }
 135    }
 136   
 137  1225 public static short encodeVersion(int major, int minor, int patch)
 138    {
 139  1225 short version = (short) ((major << MAJOR_SHIFT)
 140    + (minor << MINOR_SHIFT)
 141    + patch);
 142  1225 return version;
 143    }
 144   
 145  1479 public static String decodeVersion(short version)
 146    {
 147  1479 int major = (version & MAJOR_MASK) >> MAJOR_SHIFT;
 148  1479 int minor = (version & MINOR_MASK) >> MINOR_SHIFT;
 149  1479 int patch = (version & PATCH_MASK);
 150  1479 String versionString = major + "." + minor + "." + patch;
 151  1479 return versionString;
 152    }
 153   
 154  0 public static boolean isBefore124(short version)
 155    {
 156  0 return (version > 1241 && version <= SHORT_1_2_3);
 157    }
 158   
 159    /**
 160    * Retroweaver version info.
 161    */
 162    public static class Retro
 163    {
 164  0 public static void main(String[] args)
 165    {
 166  0 System.out.println("\nVersion: \t" + version + " (Retroweaved for JDK 1.4.x compatibility)");
 167  0 System.out.println("Codename: \t" + codename);
 168  0 System.out.println("CVS: \t" + cvs);
 169  0 System.out.println("History: \t(see http://jira.jboss.com/jira/browse/JBCACHE for details)\n");
 170    }
 171    }
 172    }