Advertisement
Zizalik

CurrencyDataJSON

May 16th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package kontrolltoo;
  7.  
  8. import XML.Continent;
  9. import XML.CurrencyXML;
  10. import java.io.File;
  11. import java.io.FileNotFoundException;
  12. import java.io.FileReader;
  13. import java.io.IOException;
  14. import java.util.ArrayList;
  15. import java.util.HashSet;
  16. import java.util.List;
  17. import java.util.Scanner;
  18. import java.util.Set;
  19. import java.util.logging.Level;
  20. import java.util.logging.Logger;
  21. import org.codehaus.jackson.map.ObjectMapper;
  22.  
  23.  
  24. public class CurrencyData {
  25. //Txt fail
  26. public static List<CurrencyTxt> data = new ArrayList<CurrencyTxt>();
  27. //JSON
  28. public static List<CurrencyJSON> currency=new ArrayList();
  29. //XML;
  30. public static Set<CurrencyXML> currEu = new HashSet<>();
  31. public static Set<CurrencyXML> currAsia = new HashSet<>();
  32. public static Set<CurrencyXML> currUSA = new HashSet<>();
  33.  
  34. static{
  35. //loeb andmed failist
  36. try {
  37. Scanner scan = new Scanner(new FileReader("Currency.txt"));
  38. String pealkiri = scan.nextLine();
  39. while (scan.hasNext()) {
  40. String[] line = scan.nextLine().split(",");
  41.  
  42.  
  43. CurrencyTxt curr = new CurrencyTxt(line[0], line[1] ,line[2], line[3], line[4], line[5]);
  44. data.add(curr); // lisab andmed listi
  45.  
  46. //XML Currency
  47. if(line[3].equals("Europe")){
  48. CurrencyXML curr2 = new CurrencyXML(line[0], line[1] ,line[2], line[4], line[5]);
  49. currEu.add(curr2); // lisab andmed listi
  50. }
  51. else if(line[3].equals("Asia")){
  52. CurrencyXML curr2 = new CurrencyXML(line[0], line[1] ,line[2], line[4], line[5]);
  53. currAsia.add(curr2); // lisab andmed listi
  54. }
  55. else if(line[3].equals("North America")){
  56. CurrencyXML curr2 = new CurrencyXML(line[0], line[1] ,line[2], line[4], line[5]);
  57. currUSA.add(curr2); // lisab andmed listi
  58. }
  59.  
  60.  
  61.  
  62.  
  63. //jackson Convert Java object to JSON
  64. currency.add(new CurrencyJSON(line[0], line[1] ,line[2], line[5]));
  65. ObjectMapper mapper=new ObjectMapper();
  66. mapper.writeValue(new File("CurrencyJ.json"), currency);
  67.  
  68. }
  69. } catch (FileNotFoundException ex) {
  70. } catch (IOException ex) {
  71. Logger.getLogger(CurrencyData.class.getName()).log(Level.SEVERE, null, ex);
  72. }
  73.  
  74.  
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement