1 package org.jboss.cache; 2 3 import java.util.StringTokenizer ; 4 5 11 public class Version 12 { 13 public static final String version = "2.0.0.ALPHA2"; 14 public static final String codename = "Habanero"; 15 public static byte[] version_id = {'0', '2', '0', '0', 'a'}; 16 public static final String cvs = "$Id: Version.java,v 1.26 2006/12/30 17:49:54 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 30 public static void main(String [] args) 31 { 32 System.out.println("\nVersion: \t" + version); 33 System.out.println("Codename: \t" + codename); 34 System.out.println("CVS: \t" + cvs); 35 System.out.println("History: \t(see http://jira.jboss.com/jira/browse/JBCACHE for details)\n"); 36 } 37 38 41 public static String printVersion() 42 { 43 return "JBossCache '" + codename + "' " + version + "[ " + cvs + "]"; 44 } 45 46 public static String printVersionId(byte[] v, int len) 47 { 48 StringBuffer sb = new StringBuffer (); 49 if (v != null) 50 { 51 if (len <= 0) 52 len = v.length; 53 for (int i = 0; i < len; i++) 54 sb.append((char) v[i]); 55 } 56 return sb.toString(); 57 } 58 59 public static String printVersionId(byte[] v) 60 { 61 StringBuffer sb = new StringBuffer (); 62 if (v != null) 63 { 64 for (int i = 0; i < v.length; i++) 65 sb.append((char) v[i]); 66 } 67 return sb.toString(); 68 } 69 70 71 public static boolean compareTo(byte[] v) 72 { 73 if (v == null) 74 return false; 75 if (v.length < version_id.length) 76 return false; 77 for (int i = 0; i < version_id.length; i++) 78 { 79 if (version_id[i] != v[i]) 80 return false; 81 } 82 return true; 83 } 84 85 public static int getLength() 86 { 87 return version_id.length; 88 } 89 90 public static short getVersionShort() 91 { 92 return getVersionShort(version); 93 } 94 95 public static short getVersionShort(String versionString) 96 { 97 if (versionString == null) 98 throw new IllegalArgumentException ("versionString is null"); 99 100 if ("1.2.4".equals(versionString)) 102 return 124; 103 else if ("1.2.4.SP1".equals(versionString)) 104 return 1241; 105 106 StringTokenizer tokenizer = new StringTokenizer (versionString, "."); 107 108 int major = 0; 109 int minor = 0; 110 int patch = 0; 111 112 if (tokenizer.hasMoreTokens()) 113 major = Integer.parseInt(tokenizer.nextToken()); 114 if (tokenizer.hasMoreTokens()) 115 minor = Integer.parseInt(tokenizer.nextToken()); 116 if (tokenizer.hasMoreTokens()) 117 patch = Integer.parseInt(tokenizer.nextToken()); 118 119 return encodeVersion(major, minor, patch); 120 } 121 122 public static String getVersionString(short versionShort) 123 { 124 if (versionShort == SHORT_1_2_4_SP2) 125 return "1.2.4.SP2"; 126 127 switch (versionShort) 128 { 129 case 124: 130 return "1.2.4"; 131 case 1241: 132 return "1.2.4.SP1"; 133 default: 134 return decodeVersion(versionShort); 135 } 136 } 137 138 public static short encodeVersion(int major, int minor, int patch) 139 { 140 short version = (short) ((major << MAJOR_SHIFT) 141 + (minor << MINOR_SHIFT) 142 + patch); 143 return version; 144 } 145 146 public static String decodeVersion(short version) 147 { 148 int major = (version & MAJOR_MASK) >> MAJOR_SHIFT; 149 int minor = (version & MINOR_MASK) >> MINOR_SHIFT; 150 int patch = (version & PATCH_MASK); 151 String versionString = major + "." + minor + "." + patch; 152 return versionString; 153 } 154 155 public static boolean isBefore124(short version) 156 { 157 return (version > 1241 && version <= SHORT_1_2_3); 158 } 159 160 public static class Retro 161 { 162 public static void main(String [] args) 163 { 164 System.out.println("\nVersion: \t" + version + " (Retroweaved for JDK 1.4.x compatibility)"); 165 System.out.println("Codename: \t" + codename); 166 System.out.println("CVS: \t" + cvs); 167 System.out.println("History: \t(see http://jira.jboss.com/jira/browse/JBCACHE for details)\n"); 168 } 169 } 170 } 171 | Popular Tags |