Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package kontrolltoo;
- import XML.Continent;
- import XML.CurrencyXML;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Scanner;
- import java.util.Set;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.codehaus.jackson.map.ObjectMapper;
- public class CurrencyData {
- //Txt fail
- public static List<CurrencyTxt> data = new ArrayList<CurrencyTxt>();
- //JSON
- public static List<CurrencyJSON> currency=new ArrayList();
- //XML;
- public static Set<CurrencyXML> currEu = new HashSet<>();
- public static Set<CurrencyXML> currAsia = new HashSet<>();
- public static Set<CurrencyXML> currUSA = new HashSet<>();
- static{
- //loeb andmed failist
- try {
- Scanner scan = new Scanner(new FileReader("Currency.txt"));
- String pealkiri = scan.nextLine();
- while (scan.hasNext()) {
- String[] line = scan.nextLine().split(",");
- CurrencyTxt curr = new CurrencyTxt(line[0], line[1] ,line[2], line[3], line[4], line[5]);
- data.add(curr); // lisab andmed listi
- //XML Currency
- if(line[3].equals("Europe")){
- CurrencyXML curr2 = new CurrencyXML(line[0], line[1] ,line[2], line[4], line[5]);
- currEu.add(curr2); // lisab andmed listi
- }
- else if(line[3].equals("Asia")){
- CurrencyXML curr2 = new CurrencyXML(line[0], line[1] ,line[2], line[4], line[5]);
- currAsia.add(curr2); // lisab andmed listi
- }
- else if(line[3].equals("North America")){
- CurrencyXML curr2 = new CurrencyXML(line[0], line[1] ,line[2], line[4], line[5]);
- currUSA.add(curr2); // lisab andmed listi
- }
- //jackson Convert Java object to JSON
- currency.add(new CurrencyJSON(line[0], line[1] ,line[2], line[5]));
- ObjectMapper mapper=new ObjectMapper();
- mapper.writeValue(new File("CurrencyJ.json"), currency);
- }
- } catch (FileNotFoundException ex) {
- } catch (IOException ex) {
- Logger.getLogger(CurrencyData.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement