1 package JSci; 2 3 import java.io.*; 4 import java.net.*; 5 import java.util.ResourceBundle ; 6 7 12 public final class Version extends Object implements Serializable { 13 16 public final int major; 17 20 public final int minor; 21 24 public final String platform; 25 28 public final String home; 29 32 public static Version getCurrent() { 33 ResourceBundle bundle = ResourceBundle.getBundle("JSci.Bundle"); 34 int major = Integer.parseInt(bundle.getString("version.major")); 35 int minor = Integer.parseInt(bundle.getString("version.minor")); 36 String platform = bundle.getString("version.platform"); 37 String home = bundle.getString("version.home"); 38 return new Version(major, minor, home, platform); 39 } 40 43 public static Version getLatest() throws IOException { 44 Version latest = null; 45 try { 46 URL serurl = new URL(getCurrent().home+"version.ser"); 47 ObjectInputStream in = new ObjectInputStream(serurl.openStream()); 48 latest = (Version) in.readObject(); 49 in.close(); 50 } catch(MalformedURLException murle) { 51 } catch(ClassNotFoundException cnfe) {} 52 return latest; 53 } 54 57 private Version(int major, int minor, String home, String platform) { 58 this.major = major; 59 this.minor = minor; 60 this.home = home; 61 this.platform = platform; 62 } 63 66 public boolean equals(Object o) { 67 if(!(o instanceof Version)) 68 return false; 69 Version ver = (Version) o; 70 return (major == ver.major) && (minor == ver.minor) && platform.equals(ver.platform); 71 } 72 public int hashCode() { 73 return 37*(37*(37*17+major)+minor)+platform.hashCode(); 74 } 75 78 public String toString() { 79 return new StringBuffer ().append(major).append('.').append(minor).toString(); 80 } 81 84 public boolean isLater(Version ver) { 85 return (major>ver.major) || 86 (major == ver.major && minor>ver.minor); 87 } 88 } 89 90 | Popular Tags |