import java.io.*;
import java.util.ArrayList;
public class InspectionResults{
public static final byte HEIGHT_AVG_RESULT = 7,
HEIGHT_RANGE_RESULT = 12,
AREA_AVG_RESULT = 15,
AREA_RANGE_RESULT = 20,
VOLUME_AVG_RESULT = 23,
VOLUME_RANGE_RESULT = 28,
HAV_FAILED_FEATURE_RESULT = 35,
REG_FAILED_FEATURE_RESULT = 38,
BRIDGE_FAILED_FEATURE_RESULT = 41;
private String retrievedData[];
private boolean failed[];
/**
* Constructs this InspectionResult with the data stored in the args.
* This class expects 44 values within the range of the args.
*/
public InspectionResults(String... args){
retrievedData = args;
boolean temp[] ={
((retrievedData[7].equalsIgnoreCase("F")) ? true: false),
((retrievedData[12].equalsIgnoreCase("F")) ? true: false),
((retrievedData[15].equalsIgnoreCase("F")) ? true: false),
((retrievedData[20].equalsIgnoreCase("F")) ? true: false),
((retrievedData[23].equalsIgnoreCase("F")) ? true: false),
((retrievedData[28].equalsIgnoreCase("F")) ? true: false),
((retrievedData[35].equalsIgnoreCase("F")) ? true: false),
((retrievedData[38].equalsIgnoreCase("F")) ? true: false),
((retrievedData[41].equalsIgnoreCase("F")) ? true: false)
};
failed = temp;
}
static class MyArrays{
public static <T> T[] copyOfRange(T[] array, T[] emptyArray, int from, int size){
ArrayList<T> temp = new ArrayList<T>(0);
for(int i = from; i < size; i++){
temp.add(array[i]);
}
return temp.toArray(emptyArray);
}
}
public static void main(String... args){
FileReader fr = null;
BufferedReader br = null;
try{
fr = new FileReader(new File("INSPECT.txt"));
br = new BufferedReader(fr);
}catch(Exception e){e.printStackTrace();}
String dwArray[][] ={ {""}, {""}, {""} };
for(int i = 0; i < dwArray.length; i++){
String temp[] = null;
try{ temp = br.readLine().split(",");}catch(Exception f){f.printStackTrace(); System.exit(1);};
String empty[] = {};
temp = InspectionResults.MyArrays.<String>copyOfRange(temp, empty, 1, temp.length);
dwArray[i] = temp;
}
InspectionResults ir[] =
{
new InspectionResults(dwArray[0]),
new InspectionResults(dwArray[1]),
new InspectionResults(dwArray[2])
};
System.out.println(ir[0]); // as an example
spacer(3);
try{
System.out.println(ir[0].hasFailed(InspectionResults.HEIGHT_AVG_RESULT));
System.out.println(ir[0].getAdjacentValue(InspectionResults.HEIGHT_AVG_RESULT));
}catch(Exception e){
System.out.println(e);
}
try{
fr.close();
br.close();
}catch(Exception e){
}
}
private static void spacer(int lines){
for(int i = 0; i < lines; i++)
System.out.println();
}
/**
* Returns true if the given value has failed, returns false otherwise.
* It's preferred to use the constants defined within this class to get the
* desired information, and not regular ints.
*/
public boolean hasFailed(byte result) throws Exception{
switch(result){
case HEIGHT_AVG_RESULT:
return failed[0];
case HEIGHT_RANGE_RESULT:
return failed[1];
case AREA_AVG_RESULT:
return failed[2];
case AREA_RANGE_RESULT:
return failed[3];
case VOLUME_AVG_RESULT:
return failed[4];
case VOLUME_RANGE_RESULT:
return failed[5];
case HAV_FAILED_FEATURE_RESULT:
return failed[6];
case REG_FAILED_FEATURE_RESULT:
return failed[7];
case BRIDGE_FAILED_FEATURE_RESULT:
return failed[8];
default :
throw new Exception("Attempt to access invalid result type! Use the Result Constants to avoid this error!");
}
}
/**
* Returns the value next to the specified result.
*/
public String getAdjacentValue(byte result) throws Exception{
if(result >= 0 && result < retrievedData.length - 1)
return retrievedData[result + 1];
else throw new Exception("Error! Attempt to access column with either no adjacent value or outside of data-range!");
}
/**
* Simply returns a String representing the date for each value in this class.
*/
@Override
public String toString(){
String temp = "";
for(String element : retrievedData){
if(element.toString() != retrievedData[retrievedData.length - 1])
temp += element + ", ";
else temp += element;
}
return temp;
}
}