import java.io.File;_x000D_
import java.io.FileNotFoundException;_x000D_
import java.util.ArrayList;_x000D_
import java.util.Scanner;_x000D_
import java.util.HashSet;_x000D_
_x000D_
/**_x000D_
 * Een klasse om klanteninformatie te lezen uit een csv bestand_x000D_
 * DE klantenfile bevat naaminfromatie, adresinformatie en contactinformatie_x000D_
 * van 88 klanten verspreid over de wereld._x000D_
 * <p>_x000D_
 * Het bestand bevat volgende informatie_x000D_
 * CustomerID CompanyName ContactName ContactTitle Address City Region PostalCode Country Phone Fax_x000D_
 * Informatie van 1 klant bevindt zich op 1 lijn en wordt gescheiden door ;_x000D_
 *_x000D_
 * @author Marc De Caluwé_x000D_
 * @version 2019-12-01_x000D_
 */_x000D_
public class ContactReader {_x000D_
    private String format;_x000D_
    private ArrayList<ContactEntry> entries;_x000D_
_x000D_
    public ContactReader() {_x000D_
        this("contacts.csv");_x000D_
    }_x000D_
_x000D_
    public ContactReader(String filename) {_x000D_
        // The format for the data._x000D_
        format = "CustomerID;Namelient;NameContact;TitleContact;Addresd;City;Region;ZIP;Country;Phone;Fax";_x000D_
        // Where to store the data._x000D_
        entries = new ArrayList<>();_x000D_
_x000D_
        // Attempt to read the complete set of data from file._x000D_
        try {_x000D_
            File pFile = new File("");_x000D_
            File klantFile = new File(pFile.getAbsolutePath() + "/data/" + filename);_x000D_
            Scanner klantfile = new Scanner(klantFile);_x000D_
            // Lees het klantenbestand tot de laatste lijn_x000D_
            while (klantfile.hasNextLine()) {_x000D_
                String klantlijn = klantfile.nextLine();_x000D_
                // Splits de klant en maak er een nieuw Klant-object van_x000D_
                ContactEntry entry = new ContactEntry(klantlijn);_x000D_
                entries.add(entry);_x000D_
            }_x000D_
            klantfile.close();_x000D_
        } catch (FileNotFoundException e) {_x000D_
            System.out.println("Er dook een probleem op: " + e.getMessage());_x000D_
        }_x000D_
    }_x000D_
_x000D_
    public ArrayList<ContactEntry> getEntries() {_x000D_
        return entries;_x000D_
    }_x000D_
_x000D_
    /**_x000D_
     * Print de data._x000D_
     */_x000D_
    public void printData() {_x000D_
        for (ContactEntry entry : entries) {_x000D_
            System.out.println(entry);_x000D_
        }_x000D_
    }_x000D_
_x000D_
    public HashSet<Contact> loadContacts() {_x000D_
        HashSet<Contact> klanten = new HashSet<>();_x000D_
        for(ContactEntry ke : getEntries()) {_x000D_
            String[] data = ke.getData();_x000D_
            Contact k = new Contact(data[ContactEntry.ID]);_x000D_
            k.setName(data[ContactEntry.NAMECONTACT]);_x000D_
            k.setTitle(data[ContactEntry.TITLECONTACT]);_x000D_
            k.setCity(data[ContactEntry.CITY]);_x000D_
            k.setRegion(data[ContactEntry.REGION]);_x000D_
            k.setCountry(data[ContactEntry.COUNTRY]);_x000D_
            klanten.add(k);_x000D_
        }_x000D_
        return klanten;_x000D_
    }_x000D_
_x000D_
    public static void main(String[] args) {_x000D_
        try {_x000D_
            ContactReader kr = new ContactReader();_x000D_
            kr.printData();_x000D_
            System.out.println("---------------------------------------------------------------");_x000D_
            for (ContactEntry ke : kr.getEntries()) {_x000D_
                String[] data = ke.getData();_x000D_
                // we drukken het ID en bijhorende naam van elke klant_x000D_
                System.out.println("ID=" + data[ContactEntry.ID] + ",  name=" + data[ContactEntry.NAMECLIENT]);_x000D_
            }_x000D_
        } catch (Exception e) {_x000D_
            e.printStackTrace();_x000D_
        }_x000D_
    }_x000D_
}_x000D_

// Lees het klantenbestand tot de laatste lijn_x000D_
import java.io.File;_x000D_
import java.io.FileNotFoundException;_x000D_
import java.util.ArrayList;_x000D_
import java.util.Scanner;_x000D_
import java.util.HashSet;_x000D_
_x000D_
/**_x000D_
 * Een klasse om klanteninformatie te lezen uit een csv bestand_x000D_
 * DE klantenfile bevat naaminfromatie, adresinformatie en contactinformatie_x000D_
 * van 88 klanten verspreid over de wereld._x000D_
 * <p>_x000D_
 * Het bestand bevat volgende informatie_x000D_
 * CustomerID CompanyName ContactName ContactTitle Address City Region PostalCode Country Phone Fax_x000D_
 * Informatie van 1 klant bevindt zich op 1 lijn en wordt gescheiden door ;_x000D_
 *_x000D_
 * @author Marc De Caluwé_x000D_
 * @version 2019-12-01_x000D_
 */_x000D_
public class ContactReader {_x000D_
    private String format;_x000D_
    private ArrayList<ContactEntry> entries;_x000D_
_x000D_
    public ContactReader() {_x000D_
        this("contacts.csv");_x000D_
    }_x000D_
_x000D_
    public ContactReader(String filename) {_x000D_
        // The format for the data._x000D_
        format = "CustomerID;Namelient;NameContact;TitleContact;Addresd;City;Region;ZIP;Country;Phone;Fax";_x000D_
        // Where to store the data._x000D_
        entries = new ArrayList<>();_x000D_
_x000D_
        // Attempt to read the complete set of data from file._x000D_
        try {_x000D_
            File pFile = new File("");_x000D_
            File klantFile = new File(pFile.getAbsolutePath() + "/data/" + filename);_x000D_
            Scanner klantfile = new Scanner(klantFile);_x000D_
            // Lees het<SUF>
            while (klantfile.hasNextLine()) {_x000D_
                String klantlijn = klantfile.nextLine();_x000D_
                // Splits de klant en maak er een nieuw Klant-object van_x000D_
                ContactEntry entry = new ContactEntry(klantlijn);_x000D_
                entries.add(entry);_x000D_
            }_x000D_
            klantfile.close();_x000D_
        } catch (FileNotFoundException e) {_x000D_
            System.out.println("Er dook een probleem op: " + e.getMessage());_x000D_
        }_x000D_
    }_x000D_
_x000D_
    public ArrayList<ContactEntry> getEntries() {_x000D_
        return entries;_x000D_
    }_x000D_
_x000D_
    /**_x000D_
     * Print de data._x000D_
     */_x000D_
    public void printData() {_x000D_
        for (ContactEntry entry : entries) {_x000D_
            System.out.println(entry);_x000D_
        }_x000D_
    }_x000D_
_x000D_
    public HashSet<Contact> loadContacts() {_x000D_
        HashSet<Contact> klanten = new HashSet<>();_x000D_
        for(ContactEntry ke : getEntries()) {_x000D_
            String[] data = ke.getData();_x000D_
            Contact k = new Contact(data[ContactEntry.ID]);_x000D_
            k.setName(data[ContactEntry.NAMECONTACT]);_x000D_
            k.setTitle(data[ContactEntry.TITLECONTACT]);_x000D_
            k.setCity(data[ContactEntry.CITY]);_x000D_
            k.setRegion(data[ContactEntry.REGION]);_x000D_
            k.setCountry(data[ContactEntry.COUNTRY]);_x000D_
            klanten.add(k);_x000D_
        }_x000D_
        return klanten;_x000D_
    }_x000D_
_x000D_
    public static void main(String[] args) {_x000D_
        try {_x000D_
            ContactReader kr = new ContactReader();_x000D_
            kr.printData();_x000D_
            System.out.println("---------------------------------------------------------------");_x000D_
            for (ContactEntry ke : kr.getEntries()) {_x000D_
                String[] data = ke.getData();_x000D_
                // we drukken het ID en bijhorende naam van elke klant_x000D_
                System.out.println("ID=" + data[ContactEntry.ID] + ",  name=" + data[ContactEntry.NAMECLIENT]);_x000D_
            }_x000D_
        } catch (Exception e) {_x000D_
            e.printStackTrace();_x000D_
        }_x000D_
    }_x000D_
}_x000D_
