Skip to content

Instantly share code, notes, and snippets.

@ashleybye
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashleybye/6aabbbc297e2fad4ec4e to your computer and use it in GitHub Desktop.
Save ashleybye/6aabbbc297e2fad4ec4e to your computer and use it in GitHub Desktop.
Initial Logbook Design and Implementation
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package client;
import display.cli.RNRWLogbookDisplay;
import java.io.FileNotFoundException;
import java.io.IOException;
import logbook.Logbook;
import logbook.dao.RNRWLogbookDAO;
/**
*
* @author ashley
*/
public class ClientModule {
public static final String CSV_PATH = "/Users/ashley/Documents/Work/Logbook.csv";
public static void main(String[] args) {
Logbook logbook = null;
try {
logbook = new RNRWLogbookDAO().loadFromCSV(CSV_PATH);
} catch (FileNotFoundException ex) {
System.err.println("File not found");
} catch (IOException ex) {
System.err.println("Some kind of IO Exception");
} catch (NumberFormatException ex) {
System.err.println("Please ensure any empty values are replaced with '0'");
}
RNRWLogbookDisplay cliDisplay = new RNRWLogbookDisplay(logbook);
cliDisplay.displayAllEntriesSummary();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package display.cli;
import logbook.Logbook;
import logbook.RNRWLogbook;
import logbook.entry.LogbookEntry;
/**
*
* @author ashley
*/
public class RNRWLogbookDisplay {
final private String[] HEADINGS = { "Date", "AC Type", "AC Registration",
"P1", "P2, Pupil or Crew", "Mission", "Hours Day P1",
"Hours Day Dual or Crew", "Hours Night P1", "Hours Night Dual or Crew",
"Simulator", "IF Sim", "IF Act", "Inst App Type", "Inst App No", "DL Day",
"DL Night", "GFP", "IFP", "NVG", "RNFA", "Instructional Day", "Instructional Night" };
private RNRWLogbook logbook;
public RNRWLogbookDisplay(Logbook logbook) {
this.logbook = (RNRWLogbook) logbook;
}
public void displayAllEntries() {
if (logbook != null) {
for (LogbookEntry entry : logbook.getAllEntries()) {
System.out.println(entry);
}
}
}
public void displayAllEntriesSummary() {
String headings = "| %1$10s | %2$15s | %3$15s | %4$15s | %5$17s " +
"| %6$20s | %7$12s | %8$22s | %9$14s | %10$24s | %11$9s |%n";
String rowLine = "";
for (int i = 0; i < 207; i++) {
rowLine += "-";
}
System.out.println(rowLine);
System.out.printf(headings, HEADINGS[0], HEADINGS[1], HEADINGS[2], HEADINGS[3],
HEADINGS[4], HEADINGS[5], HEADINGS[6], HEADINGS[7], HEADINGS[8],
HEADINGS[9], HEADINGS[10]);
System.out.println(rowLine);
for (LogbookEntry entry : logbook.getAllEntries()) {
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package logbook.dao;
import com.opencsv.CSVReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Date;
import java.util.ArrayList;
import logbook.Logbook;
import logbook.RNRWLogbook;
import logbook.entry.LogbookEntry;
import logbook.entry.RNRWLogbookEntry;
/**
*
* @author ashley
*/
public class RNRWLogbookDAO {
/**
* @param path
* @return Logbook
* @throws java.io.FileNotFoundException
* @throws java.io.IOException
* @throws java.lang.NumberFormatException
*
* Entries are loaded from a CSV file specified in the path and converted to
* the correct logbook entry format for RN RW Logbooks. Dates are expected
* to be in JDBC format (yyyy-[m]m-[d]d), times in decimal format (1.5 hrs,
* 0.6 hrs, etc). Blank numbers must either be in integer format.
*/
public Logbook loadFromCSV(String path)
throws FileNotFoundException, IOException, NumberFormatException {
ArrayList<LogbookEntry> entries = new ArrayList<>();
CSVReader reader = new CSVReader(new FileReader(path));
String[] rawEntry;
while ((rawEntry = reader.readNext()) != null) {
RNRWLogbookEntry entry = new RNRWLogbookEntry();
entry.setDate(Date.valueOf(rawEntry[0]));
entry.setAcType(rawEntry[1]);
entry.setAcReg(rawEntry[2]);
entry.setPilot1(rawEntry[3]);
entry.setPilot2OrCrew(rawEntry[4]);
entry.setMission(rawEntry[5]);
entry.setHoursDayPilot1(Float.parseFloat(rawEntry[6]));
entry.setHoursDayPilot2OrCrew(Float.parseFloat(rawEntry[7]));
entry.setHoursNightPilot1(Float.parseFloat(rawEntry[8]));
entry.setHoursNightPilot2OrCrew(Float.parseFloat(rawEntry[9]));
entry.setHoursSimulator(Float.parseFloat(rawEntry[10]));
entry.setHoursIFSim(Float.parseFloat(rawEntry[11]));
entry.setHoursIFActual(Float.parseFloat(rawEntry[12]));
entry.setInstAppType(rawEntry[13]);
entry.setInstAppNo(Integer.parseInt(rawEntry[14]));
entry.setDlDay(Integer.parseInt(rawEntry[15]));
entry.setDlNight(Integer.parseInt(rawEntry[16]));
entry.setHoursGFP(Float.parseFloat(rawEntry[17]));
entry.setHoursIFP(Float.parseFloat(rawEntry[18]));
entry.setHoursNVG(Float.parseFloat(rawEntry[19]));
entry.setRnfaNo(Integer.parseInt(rawEntry[20]));
entry.setHoursDayInstruct(Float.parseFloat(rawEntry[21]));
entry.setHoursNightInstruct(Float.parseFloat(rawEntry[22]));
entries.add(entry);
}
return new RNRWLogbook(entries);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package logbook.entry;
import java.util.Date;
/**
*
* @author ashley
*/
public abstract class LogbookEntry {
private Date date;
private String acType;
private String acReg;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getAcType() {
return acType;
}
public void setAcType(String acType) {
this.acType = acType;
}
public String getAcReg() {
return acReg;
}
public void setAcReg(String acReg) {
this.acReg = acReg;
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package logbook.entry;
import java.util.Date;
/**
*
* @author ashley
*/
public class PoolysPilotLogbookEntry extends LogbookEntry {
private String captain;
private String operatingCapacity;
private String journeyFrom;
private String journeyTo;
private Date departureTimeGMT;
private Date arrivalTimeGMT;
private float hoursDaySEPilot1;
private float hoursDaySEPilot2OrDual;
private float hoursDayMEPilot1;
private float hoursDayMEPilot2OrDual;
private float hoursNightSEPilot1;
private float hoursNightSEPilot2OrDual;
private float hoursNightMEPilot1;
private float hoursNightMEPilot2OrDual;
private float hoursIF;
private float hoursIFSim;
private String remarks;
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package logbook.entry;
/**
*
* @author ashley
*/
public class RNRWLogbookEntry extends LogbookEntry {
private String pilot1;
private String pilot2OrCrew;
private String mission;
private float hoursDayPilot1;
private float hoursDayPilot2OrCrew;
private float hoursNightPilot1;
private float hoursNightPilot2OrCrew;
private float hoursSimulator;
private float hoursIFSim;
private float hoursIFActual;
private String instAppType;
private int instAppNo;
private int dlDay;
private int dlNight;
private float hoursGFP;
private float hoursIFP;
private float hoursNVG;
private int rnfaNo;
private float hoursDayInstruct;
private float hoursNightInstruct;
public String getPilot1() {
return pilot1;
}
public void setPilot1(String pilot1) {
this.pilot1 = pilot1;
}
public String getPilot2OrCrew() {
return pilot2OrCrew;
}
public void setPilot2OrCrew(String pilot2OrCrew) {
this.pilot2OrCrew = pilot2OrCrew;
}
public String getMission() {
return mission;
}
public void setMission(String mission) {
this.mission = mission;
}
public float getHoursDayPilot1() {
return hoursDayPilot1;
}
public void setHoursDayPilot1(float hoursDayPilot1) {
this.hoursDayPilot1 = hoursDayPilot1;
}
public float getHoursDayPilot2OrCrew() {
return hoursDayPilot2OrCrew;
}
public void setHoursDayPilot2OrCrew(float hoursDayPilot2OrCrew) {
this.hoursDayPilot2OrCrew = hoursDayPilot2OrCrew;
}
public float getHoursNightPilot1() {
return hoursNightPilot1;
}
public void setHoursNightPilot1(float hoursNightPilot1) {
this.hoursNightPilot1 = hoursNightPilot1;
}
public float getHoursNightPilot2OrCrew() {
return hoursNightPilot2OrCrew;
}
public void setHoursNightPilot2OrCrew(float hoursNightPilot2OrCrew) {
this.hoursNightPilot2OrCrew = hoursNightPilot2OrCrew;
}
public float getHoursSimulator() {
return hoursSimulator;
}
public void setHoursSimulator(float hoursSimulator) {
this.hoursSimulator = hoursSimulator;
}
public float getHoursIFSim() {
return hoursIFSim;
}
public void setHoursIFSim(float hoursIFSim) {
this.hoursIFSim = hoursIFSim;
}
public float getHoursIFActual() {
return hoursIFActual;
}
public void setHoursIFActual(float hoursIFActual) {
this.hoursIFActual = hoursIFActual;
}
public String getInstAppType() {
return instAppType;
}
public void setInstAppType(String instAppType) {
this.instAppType = instAppType;
}
public int getInstAppNo() {
return instAppNo;
}
public void setInstAppNo(int instAppNo) {
this.instAppNo = instAppNo;
}
public int getDlDay() {
return dlDay;
}
public void setDlDay(int dlDay) {
this.dlDay = dlDay;
}
public int getDlNight() {
return dlNight;
}
public void setDlNight(int dlNight) {
this.dlNight = dlNight;
}
public float getHoursGFP() {
return hoursGFP;
}
public void setHoursGFP(float hoursGFP) {
this.hoursGFP = hoursGFP;
}
public float getHoursIFP() {
return hoursIFP;
}
public void setHoursIFP(float hoursIFP) {
this.hoursIFP = hoursIFP;
}
public float getHoursNVG() {
return hoursNVG;
}
public void setHoursNVG(float hoursNVG) {
this.hoursNVG = hoursNVG;
}
public int getRnfaNo() {
return rnfaNo;
}
public void setRnfaNo(int rnfaNo) {
this.rnfaNo = rnfaNo;
}
public float getHoursDayInstruct() {
return hoursDayInstruct;
}
public void setHoursDayInstruct(float hoursDayInstruct) {
this.hoursDayInstruct = hoursDayInstruct;
}
public float getHoursNightInstruct() {
return hoursNightInstruct;
}
public void setHoursNightInstruct(float hoursNightInstruct) {
this.hoursNightInstruct = hoursNightInstruct;
}
@Override
public String toString() {
return "RNRWLogbookEntry{" + "date=" + getDate() + ", acType=" + getAcType()+ ", acReg=" + getAcReg() + ", pilot1=" + pilot1 + ", pilot2OrCrew=" + pilot2OrCrew + ", mission=" + mission + ", hoursDayPilot1=" + hoursDayPilot1 + ", hoursDayPilot2OrCrew=" + hoursDayPilot2OrCrew + ", hoursNightPilot1=" + hoursNightPilot1 + ", hoursNightPilot2OrCrew=" + hoursNightPilot2OrCrew + ", hoursSimulator=" + hoursSimulator + ", hoursIFSim=" + hoursIFSim + ", hoursIFActual=" + hoursIFActual + ", instAppType=" + instAppType + ", instAppNo=" + instAppNo + ", dlDay=" + dlDay + ", dlNight=" + dlNight + ", hoursGFP=" + hoursGFP + ", hoursIFP=" + hoursIFP + ", hoursNVG=" + hoursNVG + ", rnfaNo=" + rnfaNo + ", hoursDayInstruct=" + hoursDayInstruct + ", hoursNightInstruct=" + hoursNightInstruct + '}';
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package logbook;
import java.util.ArrayList;
import java.util.Date;
import logbook.entry.LogbookEntry;
/**
*
* @author ashley
*/
public abstract class Logbook {
protected ArrayList<LogbookEntry> entries;
public Logbook(ArrayList<LogbookEntry> entries) {
this.entries = entries;
}
public void addEntry(LogbookEntry entry) {
this.entries.add(entry);
}
protected abstract LogbookEntry getEntry(int entryId);
protected abstract ArrayList<LogbookEntry> getAllEntries();
protected abstract ArrayList<LogbookEntry> getEntriesBetween(Date from, Date to);
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package logbook;
import java.util.ArrayList;
import java.util.Date;
import logbook.entry.LogbookEntry;
import logbook.entry.RNRWLogbookEntry;
/**
*
* @author ashley
*/
public class RNRWLogbook extends Logbook {
public RNRWLogbook(ArrayList<LogbookEntry> entries) {
super(entries);
}
@Override
public RNRWLogbookEntry getEntry(int entryId) {
return (RNRWLogbookEntry) entries.get(entryId);
}
@Override
public ArrayList<LogbookEntry> getAllEntries() {
return this.entries;
}
public ArrayList<LogbookEntry> getEntriesBetween(Date from, Date to) {
ArrayList<LogbookEntry> entriesInRange = new ArrayList<>();
for (LogbookEntry entry : entries) {
if ((entry.getDate().after(from) && entry.getDate().before(to))
|| entry.getDate().equals(from)
|| entry.getDate().equals(to)) {
entriesInRange.add(entry);
}
}
return entriesInRange;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment