-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManipulationFichier.java
More file actions
118 lines (84 loc) · 3.49 KB
/
ManipulationFichier.java
File metadata and controls
118 lines (84 loc) · 3.49 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.io.*;
import java.util.ArrayList;
import java.util.Queue;
import java.util.Scanner;
import java.util.regex.*;
import static java.lang.Double.parseDouble;
public class ManipulationFichier {
private static ArrayList<Integer> arrayBox;
private static ArrayList<Coordinates> arrayCoord;
public static void setArrayBox(ArrayList<Integer> arrayBox) {
ManipulationFichier.arrayBox = arrayBox;
}
public static void setArrayCoord( ArrayList<Coordinates> arrayCoord) {
ManipulationFichier.arrayCoord = arrayCoord;
}
public static ArrayList<Coordinates> getArrayCoord() {
return arrayCoord;
}
public static ArrayList<Integer> getArrayBox() {
return arrayBox;
}
// Sorts the informations from the input file to put the strings as arguments in the program
public static void setData(String writefilestr, String s, GestionCamion c1, String input1){
ManipulationFichier inputData = new ManipulationFichier();
try {
BufferedWriter deletef = new BufferedWriter(new FileWriter(writefilestr, false));
deletef.close();
} catch (IOException e) {
System.out.println("Erreur dans l'ecriture du fichier");
}
Pattern pattern = Pattern.compile("(\\d+) \\((-?\\d+\\.\\d+),(-?\\d+\\.\\d+)\\)");
Matcher matcher = pattern.matcher(s);
ArrayList<Integer> box = new ArrayList();
ArrayList<Coordinates> positions = new ArrayList();
while (matcher.find()) {
int number = Integer.parseInt(matcher.group(1));
double latitude = parseDouble(matcher.group(2));
double longitude = parseDouble(matcher.group(3));
box.add(number);
Coordinates ob1 = new Coordinates(longitude,latitude);
positions.add(ob1);
}
String[] numbers = input1.split("\\s+");
int firstNumber = Integer.parseInt(numbers[0]);
int secondNumber = Integer.parseInt(numbers[1]);
if (firstNumber>secondNumber){
c1.setContentTruck(secondNumber);
}else{
c1.setContentTruck(firstNumber);
}
inputData.setArrayBox(box);
inputData.setArrayCoord(positions);
}
// Retrieves the file with the name entered in the first argument and converts it into strings
public static void readFile(String nameFile, String writefilename, GestionCamion c1){
try {
//Fetches the file and reads it
File file = new File(nameFile);
Scanner FileReader = new Scanner(file);
String lines = "";
String input1 = FileReader.nextLine();
//Converts the lines into strings
while (FileReader.hasNextLine()) {
String input = FileReader.nextLine();
String aLine = input + "/n";
lines = lines + aLine;
}
FileReader.close();
setData(writefilename,lines, c1, input1);
} catch (FileNotFoundException e) {
System.out.println("File not found.");
}
}
// Writes the output on the new file
public static void writeFile(String writefilename, String out) {
try {
BufferedWriter outputs = new BufferedWriter(new FileWriter(writefilename, true));
outputs.write(out+"\n");
outputs.close();
} catch (IOException e) {
System.out.println("Erreur dans l'ecriture du fichier");
}
}
}