package spimonitoring;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.lang.reflect.Array;
public class InspectionResults44{
public static final byte HEIGHT_AVG_RESULT = 6,
HEIGHT_RANGE_RESULT = 11,
AREA_AVG_RESULT = 16,
AREA_RANGE_RESULT = 22,
VOLUME_AVG_RESULT = 29,
VOLUME_RANGE_RESULT = 28,
HAV_FAILED_FEATURE_RESULT = 35,
REG_OFF_RESULT = 38,
BRIDGE_LEN_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 InspectionResults44(String... args){
retrievedData = args;
boolean temp[] ={
((retrievedData[6].equalsIgnoreCase("F")) ? true: false),//7
((retrievedData[11].equalsIgnoreCase("F")) ? true: false),//12
((retrievedData[16].equalsIgnoreCase("F")) ? true: false),//15
((retrievedData[22].equalsIgnoreCase("F")) ? true: false),//20
((retrievedData[29].equalsIgnoreCase("F")) ? true: false),//23
// ((retrievedData[28].equalsIgnoreCase("F")) ? true: false),//28
// ((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){
String line = null;
int countline = 0;
int startAtLineNo = 7;
FileReader fr = null;
BufferedReader br = null;
try{
fr = new FileReader(new File("K:\\Spi5\\240-25-04-B-02-R1.F.T.#10.489a5f8e.spi.csv"));
br = new BufferedReader(fr);
}catch(Exception e){e.printStackTrace();}
String dwArray[][] ={ {""}, {""}, {""} };
try {
while ((line = br.readLine()) != null) {
if (countline >= startAtLineNo) {
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 = InspectionResults44.MyArrays.<String>copyOfRange(temp, empty, 1, temp.length);
dwArray[i] = temp;
}
InspectionResults44 ir[] =
{
new InspectionResults44(dwArray[0]),
new InspectionResults44(dwArray[1]),
new InspectionResults44(dwArray[2])
};
System.out.println(ir[0]); // as an example
spacer(3);
try{
System.out.println(ir[0].hasFailed(InspectionResults32.HEIGHT_AVG_RESULT));
System.out.println(ir[0].getAdjacentValue(InspectionResults32.HEIGHT_AVG_RESULT));
System.out.println(ir[0].hasFailed(InspectionResults32.AREA_AVG_RESULT));
System.out.println(ir[0].getAdjacentValue(InspectionResults32.AREA_AVG_RESULT));
System.out.println(ir[0].hasFailed(InspectionResults32.VOLUME_AVG_RESULT));
System.out.println(ir[0].getAdjacentValue(InspectionResults32.VOLUME_AVG_RESULT));
System.out.println(ir[0].hasFailed(InspectionResults32.REG_OFF_RESULT));
System.out.println(ir[0].getAdjacentValue(InspectionResults32.REG_OFF_RESULT));
System.out.println(ir[0].hasFailed(InspectionResults32.BRIDGE_LEN_RESULT));
System.out.println(ir[0].getAdjacentValue(InspectionResults32.BRIDGE_LEN_RESULT));
}catch(Exception e){
System.out.println(e);
}
}countline++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
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_OFF_RESULT:
return failed[7];
case BRIDGE_LEN_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 data 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;
}
}