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