-
Notifications
You must be signed in to change notification settings - Fork 0
/
FM.java
executable file
·71 lines (60 loc) · 1.56 KB
/
FM.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class FM {
private Scanner scanner; //= new Scanner(new File("tall.txt"));
private double [][] TestData;
String fname;
int linecount;
int IOSize;
int datasets;
public FM(String filename, int iosize){
IOSize=iosize;
fname=filename;
datasets=validateData();
System.out.println("Dataset Count: "+datasets);
TestData = new double[datasets][iosize];
}
public double[][] readData(){
boolean intfound=false;
try {
scanner = new Scanner(new File(fname),"UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int j = 0;j<datasets;j++){
for(int i=0;i<IOSize;i++){
intfound=false;
while(scanner.hasNextInt() && intfound==false){
try{
TestData[j][i] = scanner.nextInt();
intfound=true;
}
catch (NumberFormatException ex) { continue; }
}}
}
scanner.close();
return TestData;
}
private int validateData(){
int setcount=0;
try {
scanner = new Scanner(new File(fname),"UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(scanner.hasNextInt()){
try{
scanner.nextInt();
setcount++;
}
catch (NumberFormatException ex) { continue; }
}
System.out.println("Incomplete Integers: "+(setcount%IOSize));
scanner.close();
return ((setcount-(setcount%IOSize))/IOSize);
}
public int getdatacount(){ return datasets;}
}