http://java.sun.com/j2se/1.5.0/docs/api/java/util/Arrays.html

Apparently 1.5 doesn't support copyOfRange...

hmm I think this is doable--

import java.util.ArrayList;

public 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 values[] = {"Tom", "Joe", "Sarah"};
		String temp[] = {};

		String result[] = MyArrays.<String>copyOfRange(values, temp, 1, values.length);

		for(String element : result){
			System.out.print(element + " ");
		}

	}

}

yes it does work... so i just need to apply this concept.. to your script???

yes it does work... so i just need to apply this concept.. to your script???

Yes, either supply the class MyArrays to the same directory as InspectionResults or provide MyArrays as an inner class to InspectionResults.

Then replace the incompatible code with my version and you should be set. (Remember my version requires that you additionally supply an empty array (not a null one, but an empty array of the same type)).

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;
	}
}

Hi Mr. Alex!

Thank you in advance....

what i'm trying to do is....

public  void listRecursively(File fdir, int depth) throws IOException {

		/*Transform milliseconds time to gregorian time */
		long datefiles = fdir.lastModified();
		SimpleDateFormat Date = new SimpleDateFormat (" dd/MM/yyyy , HH:mm:ss aaa");
		Date nDate = new Date(datefiles);

		String F = ",F,";
		int count = 0;

		/*Line counter*/
		try
		{
			RandomAccessFile File = new RandomAccessFile(fdir,"r");
			long lastline=File.length();
			File.close();

			FileReader fileRead = new FileReader(fdir);
			BufferedReader bufferReader = new BufferedReader(fileRead);

			Scanner scan = new Scanner(fdir);
			while(scan.hasNextLine()){
				
//				if(scan.nextLine().contains(F))
//					count++;
				String linha = scan.nextLine();   
				if (linha.contains(F))   
					count++;
				InspectionResults44 inspectionResults = new InspectionResults44(linha.split(","));
				
				if (linha.split(",").length == 32){
					
					 byte HEIGHT_AVG_RESULT = 6,
					 AREA_AVG_RESULT = 11,
					 VOLUME_AVG_RESULT = 16,
					 REG_OFF_RESULT = 22,
					 BRIDGE_LEN_RESULT = 29;
					
				} else{//File with 44
					
					  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_OFF_RESULT = 38,
					  BRIDGE_LEN_RESULT = 41;
				}
				
					if(inspectionResults.hasFailed(HEIGHT_AVG_RESULT)){// faz isso para todas as variáveis.   
						AdjacentValue = getAdjacentValue(HEIGHT_AVG_RESULT);   
								
				}
			}

			fileRead.close();
			bufferReader.close();

//			/*Start Line counter mode2*/
//			LineNumberReader lineRead = new LineNumberReader(fileRead);
//			lineRead.skip(lastline);
//			int countline = lineRead.getLineNumber()-6; //number of default lines = 6
//			fileRead.close();
//			lineRead.close();
//			/*End Line counter mode2*/

			/* Output1 */
			if (fdir.getPath().endsWith(".csv") /*&& fdir.lastModified() > HostFile.lastModified()*/)
				System.out.println(INDENTS[depth] + x +", "+fdir.getName() +", "+ count +","+Date.format(nDate));
			/* Output2 */
			if (fdir.getPath().endsWith(".csv") /*&& fdir.lastModified() > HostFile.lastModified()*/)
				fw.write( INDENTS[depth] + x +", "+ fdir.getName() +", "+ count +","+ Date.format(nDate)+ System.getProperty("line.separator"));
			fw.flush();
			//if (fdir.getPath().endsWith(".csv") && (fdir.length()/512 )>= 1 && fdir.length()/512 <= 3)	
		}
		catch(IOException e){
		} 
		if (fdir.isDirectory() && !fdir.isHidden() && depth < MAX_DEPTH) {
			for (File f : fdir.listFiles()){  // Go over each file/subdirectory.
				listRecursively(f, depth+1);
			}}}

but something is not flowing as i intend...

in this part

if(inspectionResults.hasFailed(HEIGHT_AVG_RESULT)){
						 Height = getAdjacentValue(HEIGHT_AVG_RESULT);

why i can't retrieve the value like this...??

thank you!

You'll want to declare the numbers before the if blocks if you want them to be visible to the rest of the values in the try block--

InspectionResults44 inspectionResults = new InspectionResults44(linha.split(","));


					  byte HEIGHT_AVG_RESULT = 0,
					  HEIGHT_RANGE_RESULT = 0,
					  AREA_AVG_RESULT = 0,
					  AREA_RANGE_RESULT = 0,
					  VOLUME_AVG_RESULT = 0,
					  VOLUME_RANGE_RESULT = 0,
					  HAV_FAILED_FEATURE_RESULT = 0,
					  REG_OFF_RESULT = 0,
					  BRIDGE_LEN_RESULT = 0;


				
				if (linha.split(",").length == 32){
					
					 HEIGHT_AVG_RESULT = 6,
					 AREA_AVG_RESULT = 11,
					 VOLUME_AVG_RESULT = 16,
					 REG_OFF_RESULT = 22,
					 BRIDGE_LEN_RESULT = 29;
					
				} else{//File with 44
					
					  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_OFF_RESULT = 38,
					  BRIDGE_LEN_RESULT = 41;
				}
				
					if(inspectionResults.hasFailed(HEIGHT_AVG_RESULT)){// faz isso para todas as variáveis.   
						AdjacentValue = getAdjacentValue(HEIGHT_AVG_RESULT);

--Also don't forget to use the appropriate InspectionResults44 object with the call to getAdjacentValue(HEIGHT_AVG_RESULT) --

AdjacentValue = inspectionResults.getAdjacentValue(HEIGHT_AVG_RESULT);

HI!

The first block i'd already define previously...

byte HEIGHT_AVG_RESULT = 0,
					  HEIGHT_RANGE_RESULT = 0,
					  AREA_AVG_RESULT = 0,
					  AREA_RANGE_RESULT = 0,
					  VOLUME_AVG_RESULT = 0,
					  VOLUME_RANGE_RESULT = 0,
					  HAV_FAILED_FEATURE_RESULT = 0,
					  REG_OFF_RESULT = 0,
					  BRIDGE_LEN_RESULT = 0;

my problem is with

AdjacentValue = inspectionResults.getAdjacentValue(HEIGHT_AVG_RESULT);

thanks

Notice that you are masking the upmost declared variables with newly defined ones in your if statements--

if (linha.split(",").length == 32){
					
                                        // values already defined, get rid of "byte"
					/* byte*/ HEIGHT_AVG_RESULT = 6,
					 AREA_AVG_RESULT = 11,
					 VOLUME_AVG_RESULT = 16,
					 REG_OFF_RESULT = 22,
					 BRIDGE_LEN_RESULT = 29;
					
				} else{//File with 44
					  
                                         // values already defined, get rid of "byte"
					  /*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_OFF_RESULT = 38,
					  BRIDGE_LEN_RESULT = 41;
				}

doesn't work...:(

public  void listRecursively(File fdir, int depth) throws IOException {

		/*Transform milliseconds time to gregorian time */
		long datefiles = fdir.lastModified();
		SimpleDateFormat Date = new SimpleDateFormat (" dd/MM/yyyy , HH:mm:ss aaa");
		Date nDate = new Date(datefiles);

		String F = ",F,";
		int count = 0;

		/*Line counter*/
		try
		{
			RandomAccessFile File = new RandomAccessFile(fdir,"r");
			long lastline=File.length();
			File.close();

			FileReader fileRead = new FileReader(fdir);
			BufferedReader bufferReader = new BufferedReader(fileRead);

			Scanner scan = new Scanner(fdir);
			while(scan.hasNextLine()){
				
//				if(scan.nextLine().contains(F))
//					count++;
				String linha = scan.nextLine();   
				if (linha.contains(F))   
					count++;
				InspectionResults44 inspectionResults = new InspectionResults44(linha.split(","));
				
				if (linha.split(",").length == 32){
					
					 HEIGHT_AVG_RESULT = 6;
					 AREA_AVG_RESULT = 11;
					 VOLUME_AVG_RESULT = 16;
					 REG_OFF_RESULT = 22;
					 BRIDGE_LEN_RESULT = 29;
					
				} else{//File with 44
					
					  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_OFF_RESULT = 38;
					  BRIDGE_LEN_RESULT = 41;
				}
				
					if(inspectionResults.hasFailed(HEIGHT_AVG_RESULT)){
						adjacentValue = inspectionResults.getAdjacentValue(HEIGHT_AVG_RESULT);   
				}
			}

			fileRead.close();
			bufferReader.close();

//			/*Start Line counter mode2*/
//			LineNumberReader lineRead = new LineNumberReader(fileRead);
//			lineRead.skip(lastline);
//			int countline = lineRead.getLineNumber()-6; //number of default lines = 6
//			fileRead.close();
//			lineRead.close();
//			/*End Line counter mode2*/

			/* Output1 */
			if (fdir.getPath().endsWith(".csv") /*&& fdir.lastModified() > HostFile.lastModified()*/)
				System.out.println(INDENTS[depth] + x +", "+fdir.getName() +", "+ count +","+Date.format(nDate));
			/* Output2 */
			if (fdir.getPath().endsWith(".csv") /*&& fdir.lastModified() > HostFile.lastModified()*/)
				fw.write( INDENTS[depth] + x +", "+ fdir.getName() +", "+ count +","+ Date.format(nDate)+ System.getProperty("line.separator"));
			fw.flush();
			//if (fdir.getPath().endsWith(".csv") && (fdir.length()/512 )>= 1 && fdir.length()/512 <= 3)	
		}
		catch(IOException e){
		} 
		if (fdir.isDirectory() && !fdir.isHidden() && depth < MAX_DEPTH) {
			for (File f : fdir.listFiles()){  // Go over each file/subdirectory.
				listRecursively(f, depth+1);
			}}}

Where in your code did you place those variables?

They need to be visible to the method that is being called - either through global scope or within the same scope as the method.

here it is!

public class SpimonitoringFrame extends javax.swing.JFrame {

	/* SPIMON */
	static final int      MAX_DEPTH  = 100;  					// Max 100 levels (directory nesting)
	static final String   INDENT_STR = "   ";                 	// Single indent.
	static final String[] INDENTS    = new String[MAX_DEPTH]; 	// Indent array.
	private static  FileWriter fw;
	private static  FileWriter fw2;
	private static  FileWriter xw;
	static int x;

	/* SPIMON end*/

	/*Pane Moncal */
	protected int numberDistributions = 10;
	Calculator[] gc = new Calculator[10];
	protected final static int BINOMIAL = 0;
	protected final static int HYPERGEOMETRIC = 1;
	protected final static int NEGATIVE_BINOMIAL = 2;
	protected final static int STUDENT_T = 3;
	protected final static int F = 4;
	protected final static int POISSON = 5;
	protected final static int CHI_SQUARE = 6;
	protected final static int GAMMA = 7;
	protected final static int BETA = 8;
	protected final static int NORMAL = 9;
	protected final static String[] distLabel = {"binomial", "hypergeometric",
		"negative binomial", "Student t", "F", "Poisson",
		"Chi square", "gamma", "beta", "normal"};
	
	

	/*Pane Moncal end*/

	private final Timer busyIconTimer;
	private final Icon idleIcon;
	private final Icon[] busyIcons = new Icon[15];
	private int busyIconIndex = 0;

	private JDialog aboutBox;
	byte HEIGHT_AVG_RESULT = 0,
	  HEIGHT_RANGE_RESULT = 0,
	  AREA_AVG_RESULT = 0 ,
	  AREA_RANGE_RESULT = 0,
	  VOLUME_AVG_RESULT = 0,
	  VOLUME_RANGE_RESULT = 0,
	  HAV_FAILED_FEATURE_RESULT = 0,
	  REG_OFF_RESULT = 0,
	  BRIDGE_LEN_RESULT = 0;
	

	public SpimonitoringFrame() {
...

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.