Commit 9d9dc666 authored by firegnom's avatar firegnom
Browse files

Cleanup in generics

parent 2b356a5b
package mvplan;
/**This is a toplevel exception
* @author Maciej Kaniewski
*/
public class MVPlanException extends Exception{
public MVPlanException(String desc) {
......@@ -15,9 +18,6 @@ public class MVPlanException extends Exception{
}
/**this is a toplevel exception for library
* @author Maciej Kaniewski
*/
private static final long serialVersionUID = 1L;
}
......@@ -79,17 +79,17 @@ public class Profile
public static final int INFINITE_DECO=4;
/** Constructor for objects of class Profile */
public Profile(ArrayList knownSegments, ArrayList knownGases, AbstractModel m)
public Profile(ArrayList <SegmentAbstract> knownSegments, ArrayList <Gas> knownGases, AbstractModel m)
{
Gas g; // Used for constructing arraylists of gases and segments
SegmentAbstract s; // as above
Class modelClass;
Class<? extends AbstractModel> modelClass;
inputSegments = new ArrayList();
outputSegments = new ArrayList();
gases = new ArrayList();
inputSegments = new ArrayList <SegmentAbstract>();
outputSegments = new ArrayList<SegmentAbstract>();
gases = new ArrayList<Gas>();
// Is this a new model or a repetative dive ?
if (m==null) {
// Initialise new model.
......@@ -97,8 +97,8 @@ public class Profile
// TODO Define which concrete model to use
try {
if (debug>0) System.out.println("Loading model class:"+prefs.getModelClass());
modelClass = Class.forName(prefs.getModelClass());
model = (AbstractModel)modelClass.newInstance();
modelClass = Class.forName(prefs.getModelClass()).asSubclass(AbstractModel.class);
model = modelClass.newInstance();
} catch (Exception ex) {
model = new ZHL16B();
if (debug>0) System.out.println("Model instantiation exception for: "+ex.getMessage());
......@@ -118,17 +118,17 @@ public class Profile
}
// Construct list of dive segments from known segments
Iterator is=knownSegments.iterator();
Iterator<SegmentAbstract> is=knownSegments.iterator();
while(is.hasNext()) {
s=(SegmentAbstract)is.next();
s=is.next();
// Add enabled dive segments only to input segments
if (s.getEnable().booleanValue()==true)
inputSegments.add(s);
}
// construct list of dive gases from known gases
Iterator ig=knownGases.iterator();
Iterator<Gas> ig=knownGases.iterator();
while(ig.hasNext()) {
g=(Gas)ig.next();
g=ig.next();
g.setVolume(0.0); // Reset the gas volume to zero
if (g.getEnable()==true) {
// Add enabled gases only to gas arraylist
......@@ -139,8 +139,8 @@ public class Profile
}
// Accessor methods for profile
public ArrayList getProfile() { return outputSegments; }
public ArrayList getGases() { return gases; }
public ArrayList<SegmentAbstract> getProfile() { return outputSegments; }
public ArrayList<Gas> getGases() { return gases; }
public AbstractModel getModel() { return model; }
public boolean getIsRepetitiveDive() {return isRepetativeDive;}
public int getSurfaceInterval() { return surfaceInterval; }
......@@ -199,7 +199,7 @@ public class Profile
inFinalAscent=false; // Flag used to work out when all segments are complete and are in flnal ascent
// Process segment list of user defined segments through model
Iterator it=inputSegments.iterator();
Iterator<SegmentAbstract> it=inputSegments.iterator();
while(it.hasNext()) {
s=(SegmentAbstract)it.next(); // Get segment
if (debug >1) System.out.println("Processing: "+s);
......@@ -267,7 +267,7 @@ public class Profile
if(returnCode != SUCCESS)
return returnCode;
// Calculate runtimes and update the segments
Iterator it2=outputSegments.iterator();
Iterator<SegmentAbstract> it2=outputSegments.iterator();
t=0;
while(it2.hasNext()) {
s=(SegmentAbstract)it2.next();
......@@ -280,7 +280,7 @@ public class Profile
}
/*
/**
* Ascend to target depth, decompressing if necessary.
* If inFinalAscent then gradient factors start changing, and automatic gas selection is made.
*/
......@@ -297,7 +297,7 @@ public class Profile
double maxMV=0; // Holds maximum mvgradient at each stop
double nextStopDepth; // Next proposed stop depth
int control=0; // Stores controlling compartment at new depth
double ceiling; // Used to store ceiling
//double ceiling; // Used to store ceiling
Gas tempGas;
SegmentDeco decoSegment; // Use for adding deco segments
......@@ -467,7 +467,7 @@ public class Profile
public void doGasCalcs()
{
SegmentAbstract s;
Iterator it=outputSegments.iterator();
Iterator<SegmentAbstract> it=outputSegments.iterator();
while(it.hasNext()) {
s=(SegmentAbstract)it.next();
......
......@@ -58,25 +58,25 @@ public class TableGeneratorModel {
* @param g ArrayList of known gases
* @param modifiers int[] of profile time modifiers
*/
public TableGeneratorModel(ArrayList s, ArrayList g, int[] modifiers) {
public TableGeneratorModel(ArrayList<SegmentAbstract> s, ArrayList<Gas> g, int[] modifiers) {
// Create new clean ArrayLists
knownSegments = new ArrayList();
knownGases = new ArrayList();
knownSegments = new ArrayList<SegmentAbstract>();
knownGases = new ArrayList<Gas>();
int i;
// Initialise modifiers - gets REFERENCE to array
this.modifiers= modifiers;
// Copy and clean known segments and gases
Iterator is=s.iterator();
Iterator<SegmentAbstract> is=s.iterator();
while(is.hasNext()){
SegmentAbstract segment = (SegmentAbstract)is.next();
SegmentAbstract segment = is.next();
if(segment.getEnable().booleanValue()==true) // Only copy enabled segments
knownSegments.add((SegmentAbstract)segment.clone()); // Clone them to avoid conflicts
}
Iterator ig=g.iterator();
Iterator<Gas> ig=g.iterator();
while(ig.hasNext()){
Gas gas = (Gas)ig.next();
Gas gas = ig.next();
if(gas.getEnable() == true) // Only copy enabled gases
knownGases.add((Gas)gas.clone()); // Clone them to avoid conflicts
}
......@@ -86,7 +86,7 @@ public class TableGeneratorModel {
if (knownSegments.size()>0) {
// Iterate BACK through dive segments and return last one that is NOT a waypoint
for (i=knownSegments.size()-1; i>=0; i--){
if(((SegmentAbstract)knownSegments.get(i)).getTime() > 0.0f ) {
if((knownSegments.get(i)).getTime() > 0.0f ) {
controlSegmentIndex = i;
break;
}
......@@ -196,7 +196,7 @@ public class TableGeneratorModel {
* @return returnCodes as defined in Profile()
*/
public int doMultiDive() {
ArrayList a; // Working arraylist
ArrayList<SegmentAbstract> a; // Working arraylist
SegmentAbstract s; // Working segment
int i,j; // Counters
......@@ -227,14 +227,14 @@ public class TableGeneratorModel {
// Process the profiles
for(i=0;i<=numProfiles-1;i++) { // For each profile ...
// Clone from knownSegments into a new ArrayList
a=new ArrayList();
Iterator is=knownSegments.iterator();
a=new ArrayList<SegmentAbstract>();
Iterator<SegmentAbstract> is=knownSegments.iterator();
while(is.hasNext()) {
s=(SegmentAbstract)is.next();
a.add(s.clone()); // Need to clone s !
s=is.next();
a.add((SegmentAbstract) s.clone()); // Need to clone s !
}
// Adjust LAST segment for modified time
s = (SegmentAbstract)a.get(controlSegmentIndex);
s = a.get(controlSegmentIndex);
double time = s.getTime();
time = time+modifiers[i];
s.setTime(time);
......@@ -282,7 +282,7 @@ public class TableGeneratorModel {
ascentRow=knownSegments.size()+1;
// Sequence through longest profile and look for first deco segment
for (i=0; i<multiProfile[longestProfile].getProfile().size()-1; i++){
if( ((SegmentAbstract)multiProfile[longestProfile].getProfile().get(i)).getType()== SegmentAbstract.DECO ) {
if( (multiProfile[longestProfile].getProfile().get(i)).getType()== SegmentAbstract.DECO ) {
ascentRow=i;
break;
}
......@@ -304,7 +304,7 @@ public class TableGeneratorModel {
segmentArray = new SegmentAbstract [numProfiles][rows];
for(i=0; i<=numProfiles-1;i++){ // For each profile
for(j=0;j<=rows-1;j++) { // For each segment (row)
s=(SegmentAbstract)multiProfile[i].getProfile().get(j);
s=multiProfile[i].getProfile().get(j);
segmentArray [i][j] = s;
}
}
......@@ -332,7 +332,7 @@ public class TableGeneratorModel {
* getKnownSegments - gets the KnownSegments ArrayList
* @return (SegmentAbstract)ArrayList KnownSegments
*/
public ArrayList getKnownSegments() {
public ArrayList<SegmentAbstract> getKnownSegments() {
return knownSegments;
}
}
......@@ -51,9 +51,9 @@ public class SegmentAscDec extends SegmentAbstract
this.rate=rate;
super.time = (endDepth-startDepth)/rate;
if (startDepth < endDepth)
super.type=super.DESCENT;
super.type=DESCENT;
else
super.type=super.ASCENT;
super.type=ASCENT;
}
/** Override gasUsed() to determine the gas used in this segment
......@@ -89,7 +89,7 @@ public class SegmentAscDec extends SegmentAbstract
timeMins=(int)time;
timeSeconds = (int)((time - (double)timeMins)*60.0);
if (super.type == super.ASCENT) s="ASC "; else s="DESC";
if (super.type == ASCENT) s="ASC "; else s="DESC";
return String.format("%1$4s:%2$3.0f"+MvplanInstance.getMvplan().getPrefs().getDepthShortString()+" for %3$02d:%4$02d [%5$3.0f] on %6$s, SP: %7$3.1f, END:%8$3.0f"+MvplanInstance.getMvplan().getPrefs().getDepthShortString(),
s, depth, timeMins, timeSeconds , runTime, gas.toString(), setpoint, getEnd());
......
......@@ -54,7 +54,7 @@ public class SegmentDeco extends SegmentAbstract
super.depth=depth;
super.gas=gas;
super.setpoint=setpoint;
super.type=super.DECO;
super.type=DECO;
super.time=time;
mvMax=0;
gfUsed=0;
......
......@@ -43,7 +43,7 @@ public class SegmentDive extends SegmentAbstract
super.depth=depth;
super.gas=gas;
super.setpoint=setpoint;
super.type=super.CONST;
super.type=CONST;
super.time=time;
}
......
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