1 /*
2 Copyright � 1999 CERN - European Organization for Nuclear Research.
3 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
4 is hereby granted without fee, provided that the above copyright notice appear in all copies and
5 that both that copyright notice and this permission notice appear in supporting documentation.
6 CERN makes no representations about the suitability of this software for any purpose.
7 It is provided "as is" without expressed or implied warranty.
8 */
9 package cern.colt;
10 
11 /**
12  * Information about the current release.
13  * Use this class to distinguish releases and base runtime decisions upon.
14  * Versions are of the form <tt>Major.Minor.Micro.Build</tt>, e.g. <tt>1.0.0.52</tt>
15  * <p>
16  * You can most easily display version info by running <tt>java cern.colt.Version</tt>.
17  */
18 public final class Version {
19 /**
20  * Not yet commented.
21  */
Version()22 private Version() {
23 }
24 /**
25  * Returns all version information as string.
26  */
asString()27 public static String asString() {
28 	if (getPackage()==null) return "whoschek@lbl.gov";
29 	String vendor = getPackage().getImplementationVendor();
30 	if (vendor==null) vendor = "whoschek@lbl.gov";
31 	return
32 		"Version " +
33 		getMajorVersion()  + "." +
34 		getMinorVersion() + "." +
35 		getMicroVersion()  + "." +
36 		getBuildVersion() + " (" +
37 		getBuildTime() + ")" +
38 		"\nPlease report problems to "+ vendor;
39 	}
40 /**
41  * Returns the time this release was build; for example "Tue Apr 11 11:50:39 CEST 2000".
42  */
getBuildTime()43 public static String getBuildTime() {
44 	//String s = "1.2.3.56 (Tue Apr 11 11:50:39 CEST 2000)";
45 	if (getPackage()==null) return "unknown";
46 	String s = getPackage().getImplementationVersion();
47 	if (s==null) return "unknown";
48 	int k = s.indexOf('(');
49 	return s.substring(k+1,s.length()-1);
50 }
51 /**
52  * Returns the build version of this release.
53  */
getBuildVersion()54 public static int getBuildVersion() {
55 	return numbers()[3];
56 }
57 /**
58  * Returns the major version of this release.
59  */
getMajorVersion()60 public static int getMajorVersion() {
61 	return numbers()[0];
62 }
63 /**
64  * Returns the micro version of this release.
65  */
getMicroVersion()66 public static int getMicroVersion() {
67 	return numbers()[2];
68 }
69 /**
70  * Returns the minor version of this release.
71  */
getMinorVersion()72 public static int getMinorVersion() {
73 	return numbers()[1];
74 }
75 /**
76  *
77  */
getPackage()78 private static Package getPackage() {
79 	return Package.getPackage("cern.colt");
80 }
81 /**
82  * Prints <tt>asString</tt> on <tt>System.out</tt>.
83  * @param args ignored.
84  */
main(String[] args)85 public static void main(String[] args) {
86 	System.out.println(asString());
87 }
88 /**
89  * Returns the major version of this release; for example version 1.2.3 returns 1.
90  */
numbers()91 private static int[] numbers() {
92 	int w = 4;
93 	//int[] numbers = new int[w];
94 	int[] numbers = new int[] {1, 1, 0, 0};
95 	return numbers;
96 	/*
97 	if (getPackage()==null) return numbers;
98 	String s = getPackage().getImplementationVersion();
99 	if (s==null) return numbers;
100 	int k = s.indexOf('(');
101 	s = s.substring(0,k);
102 	s = s.trim();
103 	//s = s.replace('.', ' ');
104 	//s = ViolinStrings.Strings.stripBlanks(s);
105 	//s = ViolinStrings.Strings.translate(s, ".", " ");
106 	String[] words = s.split("."); // requires jdk 1.4.x
107 	for (int i=0; i<w; i++) {
108 		numbers[i] = Integer.parseInt(words[i]);
109 		//numbers[i] = Integer.parseInt(ViolinStrings.Strings.word(s, i));
110 		//System.out.println(numbers[i]);
111 	}
112 	return numbers;
113 	*/
114 }
115 }
116