Skip to content

Commit a5cade0

Browse files
author
AisekleOvus
committed
The little lib provides find edit and add methods for *.csv files
1 parent f2455c2 commit a5cade0

File tree

6 files changed

+18499
-1
lines changed

6 files changed

+18499
-1
lines changed

v_0.1/source/com/ovus/aisekle/csv/Acsvl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private static boolean columnsAccordance(File file, Map<Long, String> lines, Str
4545
return lines.entrySet().stream().allMatch(entry -> entry.getValue().split(delimiter).length == fileColumnsCounter);
4646
}
4747

48-
// Fine Line Method
48+
// Find Line Method
4949

5050
public static void findLine(File file, String searchString, BiConsumer<Long, String> callback)
5151
throws AcsvlException {

v_0.2/com/ovus/aisekle/example/Copper.csv

+8,097
Large diffs are not rendered by default.

v_0.2/com/ovus/aisekle/example/Gold.csv

+10,330
Large diffs are not rendered by default.
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
import com.ovus.aisekle.csv.*;
5+
6+
public class Main {
7+
public static void main(String[] args) {
8+
File goldFile = new File("Gold.csv");
9+
File copperFile = new File("Copper.csv");
10+
File copperInGoldFile = new File("CopperInGold.csv");
11+
String delimiter = ",";
12+
/* LinkedHashSet <String> copperInGoldLines = new LinkedHashSet<>();
13+
14+
try(Scanner scanner = new Scanner(copperFile)) {
15+
16+
while(scanner.hasNext()) {
17+
String copperFileLine = scanner.nextLine();
18+
Integer priceCopperInGold = 0;
19+
String[] copperFileAsArray = copperFileLine.split(delimiter);
20+
Acsvl.findLine(goldFile, copperFileAsArray[0], 1, delimiter, (n, str) -> {
21+
String[] goldFileLineAsArray = str.split(delimiter);
22+
String date = goldFileLineAsArray[0];
23+
Double copperInGoldClose = Double.parseDouble(copperFileAsArray[1])*2200/Double.parseDouble(goldFileLineAsArray[1]);
24+
Double copperInGoldOpen = Double.parseDouble(copperFileAsArray[2])*2200/Double.parseDouble(goldFileLineAsArray[2]);
25+
Double copperInGoldHigh = Double.parseDouble(copperFileAsArray[3])*2200/Double.parseDouble(goldFileLineAsArray[3]);
26+
Double copperInGoldLow = Double.parseDouble(copperFileAsArray[4])*2200/Double.parseDouble(goldFileLineAsArray[4]);
27+
copperInGoldLines.add(date+delimiter+copperInGoldClose.toString()+delimiter
28+
+copperInGoldOpen.toString()+delimiter
29+
+copperInGoldHigh.toString()+delimiter
30+
+copperInGoldLow.toString()+delimiter);
31+
});
32+
}
33+
Acsvl.addLines(copperInGoldFile, copperInGoldLines);
34+
}catch(FileNotFoundException fnfe) {
35+
System.out.println("File Not Found !");
36+
}catch(AcsvlException acsvle) {
37+
acsvle.printStackTrace();
38+
}*/
39+
String[] copperFileLineAsArray = new String[256];
40+
String[] goldFileLineAsArray = new String[256];
41+
long linesCounter = 0L;
42+
Long lineNumber = 0L;
43+
try(Scanner scanner = new Scanner(copperFile)) {
44+
BufferedWriter bwr = new BufferedWriter(new FileWriter(copperInGoldFile));
45+
while(scanner.hasNext()) {
46+
linesCounter++;
47+
/*String[] */copperFileLineAsArray = scanner.nextLine().split(delimiter);
48+
lineNumber = Acsvl.findNextLine(goldFile, copperFileLineAsArray[0], 0, 1, delimiter).getKey();
49+
/*String[] */goldFileLineAsArray = Acsvl.findNextLine(goldFile, copperFileLineAsArray[0], 0, 1, delimiter).getValue().split(delimiter);
50+
if(lineNumber > 0) {
51+
String date = goldFileLineAsArray[0];
52+
Double copperInGoldClose = Double.parseDouble(copperFileLineAsArray[1])*2200/Double.parseDouble(goldFileLineAsArray[1]);
53+
Double copperInGoldOpen = Double.parseDouble(copperFileLineAsArray[2])*2200/Double.parseDouble(goldFileLineAsArray[2]);
54+
Double copperInGoldHigh = Double.parseDouble(copperFileLineAsArray[3])*2200/Double.parseDouble(goldFileLineAsArray[3]);
55+
Double copperInGoldLow = Double.parseDouble(copperFileLineAsArray[4])*2200/Double.parseDouble(goldFileLineAsArray[4]);
56+
bwr.write(date+delimiter+String.format(Locale.US,"%1$.3g", copperInGoldClose)+delimiter
57+
+String.format(Locale.US,"%1$.3g", copperInGoldOpen)+delimiter
58+
+String.format(Locale.US,"%1$.3g", copperInGoldHigh)+delimiter
59+
+String.format(Locale.US,"%1$.3g", copperInGoldLow)+delimiter+System.lineSeparator());
60+
}
61+
}
62+
bwr.flush();
63+
bwr.close();
64+
}catch(Exception e) {
65+
System.out.println(linesCounter+" : goldFileLineAsArray.length = "+goldFileLineAsArray.length+" copperFileLineAsArray.length = "+copperFileLineAsArray.length);
66+
System.out.println("copperFileLineAsArray = \n"+Arrays.toString(copperFileLineAsArray));
67+
System.out.println("goldFileLineAsArray = \n"+Arrays.toString(goldFileLineAsArray));
68+
e.printStackTrace();
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)