- Hlavní stránka
- Balíky
- Třídy
- Soubory

# src/cz/neubauer/tomas/hazardanalysis/model/analysis/Analysis.java

Zobrazit dokumentaci tohoto souboru.

    00001
    00004 package cz.neubauer.tomas.hazardanalysis.model.analysis;
    00005
    00006 import java.io.BufferedWriter;
    00007 import java.io.File;
    00008 import java.io.FileWriter;
    00009 import java.io.IOException;
    00010 import java.util.ArrayList;
    00011
    00012 import cz.neubauer.tomas.hazardanalysis.model.components.Component;
    00013 import cz.neubauer.tomas.hazardanalysis.model.dangers.DangerVariant;
    00014
    00021 public class Analysis {
    00022
    00026         private ArrayList<AnalysisRecord> analysisRecords;
    00027
    00031         public Analysis() {
    00032                 analysisRecords = new ArrayList<AnalysisRecord>(10);
    00033         }
    00034
    00041         public void addAnalysisRecord(AnalysisRecord analysisRecord) {
    00042                 analysisRecords.add(analysisRecord);
    00043         }
    00044
    00053         public AnalysisRecord getAnalysisRecord(int index) {
    00054                 return analysisRecords.get(index);
    00055         }
    00056
    00062         public int getRecordsCount() {
    00063                 return analysisRecords.size();
    00064         }
    00065
    00069         public void printAnalysis() {
    00070                 int recordCount = analysisRecords.size();
    00071                 AnalysisRecord currentRecord;
    00072                 Component currentComponent;
    00073                 for (int i = 0; i < recordCount; i++) {
    00074                         currentRecord = analysisRecords.get(i);
    00075                         currentComponent = currentRecord.getComponent();
    00076                         System.out.println(currentComponent.getName() + "; "
    00077                                         + currentRecord.getComponent().getLocation() + "; "
    00078                                         + currentComponent.getDangersAsString());
    00079                 }
    00080         }
    00081
    00088         public void saveToFile(String fileName) {
    00089                 try {
    00090                         File file = new File(fileName);
    00091                         FileWriter fw = new FileWriter(file);
    00092                         BufferedWriter bw = new BufferedWriter(fw);
    00093
    00094                         int recordCount = analysisRecords.size();
    00095                         AnalysisRecord currentRecord;
    00096                         Component currentComponent;
    00097                         for (int i = 0; i < recordCount; i++) {
    00098                                 currentRecord = analysisRecords.get(i);
    00099                                 currentComponent = currentRecord.getComponent();
    00100                                 bw.write(currentComponent.getName() + ";"
    00101                                                 + currentRecord.getComponent().getLocation() + ";"
    00102                                                 + currentComponent.getDangersAsString());
    00103                                 bw.newLine();
    00104                         }
    00105
    00106                         bw.close();
    00107                 } catch (IOException e) {
    00108                         e.printStackTrace();
    00109                 }
    00110
    00111         }
    00112
    00119         public ArrayList<DangerVariant> getCriticalDangerVariants() {
    00120                 ArrayList<DangerVariant> criticalVariants = new ArrayList<DangerVariant>(
    00121                                 100);
    00122
    00123                 int analysisRecordCount = getRecordsCount();
    00124                 Component currentComponent;
    00125                 for (int i = 0; i < analysisRecordCount; i++) {
    00126                         currentComponent = getAnalysisRecord(i).getComponent();
    00127                         ArrayList<DangerVariant> componentVariants = currentComponent
    00128                                         .getDangerVariants();
    00129                         int dvc = componentVariants.size();
    00130                         DangerVariant dv;
    00131                         for (int j = 0; j < dvc; j++) {
    00132                                 dv = componentVariants.get(j);
    00133                                 if (dv.isCritical() && !criticalVariants.contains(dv)) {
    00134                                         criticalVariants.add(dv);
    00135                                 }
    00136                         }
    00137
    00138                 }
    00139
    00140                 return criticalVariants;
    00141         }
    00142
    00143 }