Commit 8be349f0 authored by firegnom's avatar firegnom
Browse files

modified version handling

parent 0644d691
......@@ -32,6 +32,9 @@ import java.io.*;
import java.net.*;
import java.beans.XMLDecoder;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class VersionManager {
public final static int UNDEFINED=0;
public final static int CURRENT=1;
......@@ -65,13 +68,16 @@ public class VersionManager {
Version latestVersion;
String url;
// Build url of the form: "http://192.168.1.100:8080/mvplan/version.jsp?command=current&id=1234-1234-1234-1234-1234-1234-1234-1234-1234"
url = MvplanInstance.getMvplan().getPrefs().getUpdateVersionURL()+"?command=current&id=1234-1234-1234-1234-1234-1234-1234-1234-1234";
url = MvplanInstance.getMvplan().getPrefs().getUpdateVersionURL();
try {
latestVersion = readURL(url);
} catch (Exception e) {
if(MvplanInstance.getMvplan().getDebug()>0) System.err.println("Failed to read from network.\n");
if(MvplanInstance.getMvplan().getDebug()>0) {
System.err.println("Failed to read from network.\n");
System.err.println("Url:"+url);
e.printStackTrace();
}
resultCode=ERROR;
return;
}
......@@ -96,13 +102,11 @@ public class VersionManager {
URL target = new URL(url);
URLConnection targetConnection = target.openConnection();
// Java 1.5 only
targetConnection.setConnectTimeout(15000);
XMLDecoder decoder = new XMLDecoder(
XStream x = new XStream(new DomDriver());
Version v = (Version) x.fromXML(
new BufferedInputStream(
targetConnection.getInputStream()));
Version v = (Version)decoder.readObject();
decoder.close();
return v;
}
......
......@@ -30,13 +30,32 @@ import java.text.MessageFormat;
import mvplan.main.MvplanInstance;
import mvplan.prefs.Prefs;
public class Gas implements Comparable, Serializable, Cloneable
/**
*
* */
public class Gas implements Comparable<Gas>, Serializable, Cloneable
{
private double fHe,fO2; // Gas fractions
private double mod; // Maximum operating depth
private double volume; // Accumulate gas volume
private boolean enable; // Gas is enabled for use
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Gas fractions
* */
private double fHe,fO2;
/**
* Maximum operating depth
* */
private double mod;
/**
* Accumulate gas volume
* */
private double volume;
/**
* Gas is enabled for use
* */
private boolean enable;
/** Constructor for Gas objects. Fractions must add to <= 1.0. Remainder assumed Nitrogen.
* If constructed with erroneous data is set up as air.
......@@ -48,14 +67,14 @@ public class Gas implements Comparable, Serializable, Cloneable
public Gas(double fHe, double fO2, double mod)
{
setGas(fHe,fO2,mod);
enable=true; //Boolean.TRUE;
enable=true;
this.volume=0.0;
}
/** Empty constructor for bean interface */
public Gas() {
}
/*
/**
* Method to validate a field for limits only
*/
public static boolean validate(String field, double value) {
......@@ -67,7 +86,7 @@ public class Gas implements Comparable, Serializable, Cloneable
return false;
}
/*
/**
* Method to validate all inputs (fO2, fHe and MOD)
*/
public static boolean validate(double fHe, double fO2, double mod) {
......@@ -92,21 +111,21 @@ public class Gas implements Comparable, Serializable, Cloneable
return passed;
}
/*
/**
* Method to get a maximum MOD based on O2 fraction
*/
public static double getMaxMod(double o) {
Prefs prefs = MvplanInstance.getPrefs();
return (prefs.getMaxMOD()/o * prefs.getPConversion())-prefs.getPConversion();
}
/*
/**
* Method to get a MOD based on O2 fraction and maximum ppO2
*/
public static double getMod(double fO2, double ppO2) {
Prefs prefs = MvplanInstance.getPrefs();
return (ppO2/fO2 * prefs.getPConversion())-prefs.getPConversion();
}
/*
/**
* Method to get a ppO2 based on O2 fraction and MOD
*/
public static double getppO2(double f, double m) {
......@@ -132,11 +151,9 @@ public class Gas implements Comparable, Serializable, Cloneable
* @param Object (Gas) to compare to
* @return Integer, Mod of compared Gas - Mod of this gas
*/
public int compareTo(Object o)
public int compareTo(Gas g)
{
double m;
Gas g;
g = (Gas)o;
m=g.getMod();
return (int)(m-mod);
}
......@@ -162,7 +179,7 @@ public class Gas implements Comparable, Serializable, Cloneable
public void setEnable(boolean state) { enable = state;}
public void setVolume(double vol) { volume=vol;}
/* setGas() - sets gas fractions
/** setGas() - sets gas fractions
* or creates Air by default
*/
public void setGas(double fHe,double fO2, double mod)
......@@ -201,7 +218,7 @@ public class Gas implements Comparable, Serializable, Cloneable
return(name);
}
/*
/**
* Make short name for tables
*/
public String getShortName()
......
......@@ -17,8 +17,8 @@ public class MvplanInstance {
public static final int MAJOR_VERSION = 1; // Application version codes
public static final int MINOR_VERSION = 6;
public static final int PATCH_VERSION = 0;
public static final String VERSION_STATUS = "BETA"; // Application status
public static final String BUILD_DATE = "10-04-2012"; // Application
public static final String VERSION_STATUS = "TEST"; // Application status
public static final String BUILD_DATE = "17-04-2012"; // Application
// release date
public static Version mvplanVersion; // App version. See Version Class
private static IMvplan mvplan;
......
......@@ -174,9 +174,9 @@ public class Prefs implements Serializable
updateCheckDisable=false;
updateCheckFrequency=7;
if(debug>0)
updateVersionURL="http://server.local/mvplan/Version";
updateVersionURL="http://mvplan.googlecode.com/hg/ver/DEV/version.xml";
else
updateVersionURL="http://services.wittig.net.au/mvplan/Version";
updateVersionURL="http://mvplan.googlecode.com/hg/ver/REL/version.xml";
homeURL="http://wittig.net.au/diving/mvplan.html";
modifiers = new int[] {0,2,4,6,8}; // Default modifiers for multi-dive plans
// Default units strings are managed here as we know the units
......@@ -277,9 +277,9 @@ public class Prefs implements Serializable
if (lastUpdateCheck==null) lastUpdateCheck=Calendar.getInstance().getTime();
if (updateCheckFrequency<0 || updateCheckFrequency>365) updateCheckFrequency=7;
if(debug>0)
updateVersionURL="http://server.local/mvplan/Version";
updateVersionURL="http://mvplan.googlecode.com/hg/ver/DEV/version.xml";
else
updateVersionURL="http://services.wittig.net.au/mvplan/Version";
updateVersionURL="http://mvplan.googlecode.com/hg/ver/REL/version.xml";
homeURL="http://wittig.net.au/diving/mvplan.html";
if (modifiers == null) modifiers = new int [] {0,2,4,6,8};
if (!showStopTime && !showRunTime) showRunTime=true;
......
......@@ -33,7 +33,17 @@ public class Version implements Comparable<Version> {
private int patchVersion;
private String statusString;
private String dateString;
private HashMap lookupTable;
private final static HashMap<String,Integer> lookupTable;
// Create lookuptable hashmap
static {
lookupTable = new HashMap<String, Integer>();
lookupTable.put("UNDEFINED",new Integer(0));
lookupTable.put("TEST",new Integer(1));
lookupTable.put("ALPHA",new Integer(2));
lookupTable.put("BETA",new Integer(3));
lookupTable.put("RELEASED",new Integer(4));
}
public static final int UNDEFINED=0;
public static final int TEST=10;
......@@ -48,13 +58,6 @@ public class Version implements Comparable<Version> {
}
public Version(int major, int minor, int patch, String status, String date){
// Create hashmap
lookupTable = new HashMap();
lookupTable.put("UNDEFINED",new Integer(0));
lookupTable.put("TEST",new Integer(1));
lookupTable.put("ALPHA",new Integer(2));
lookupTable.put("BETA",new Integer(3));
lookupTable.put("RELEASED",new Integer(4));
// Initialise fields
majorVersion=major;
minorVersion=minor;
......
/**
*
*/
package mvplan.util;
import java.io.File;
import java.io.FileOutputStream;
import mvplan.main.MvplanInstance;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
/**
* @author Maciej Kaniewski
*
*/
public class VersionXmlTest {
private final static String FILE = "test_version.xml";
@Before
public void exportCurrentVersionToFile() throws Exception{
XStream x = new XStream(new DomDriver());
Version v = MvplanInstance.getVersion();
x.toXML(v, new FileOutputStream(new File(FILE)));
}
@Test
public void testLoad() throws Exception{
XStream x = new XStream(new DomDriver());
Version v = (Version) x.fromXML(new File(FILE));
assertEquals(0,v.compareTo(MvplanInstance.getVersion()));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment