package javaphone;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * This class handles the customers information when 
 * searching for the customer id number.
 * 
 * @author iGroup
 */
public class CustomerList extends ArrayList<HashMap> {

    private final DataFileIO customerDataFile;
    
    /**
     * Adds customer to the datafile.
     */
    public CustomerList() {
        customerDataFile = new DataFileIO("customers.xml", "customers", "customer");
        this.addAll(customerDataFile.read());
    }

    /**
     * Searches for customer with specific customerId
     * @param customerId
     * @return customer data as HashMap if customer found 
     *         null if customer not found
     */     
    public HashMap getServiceById(int customerId) {
        for (HashMap customer : this) {
            if (customerId == (int) customer.get("customerId")) {
                return customer;
            }
        }
        return null;
    }

    /**
     * Gets the number of customers by service.
     * @param serviceId
     * @return customer number
     */
    public int getCustomerCountByService(int serviceId) {
        return 0;
    }
    
    /**
     * Prepares the report
     */
    public void prepareReport() {
    }
    
    /**
     * Gets the next contract
     * @return null
     */
    public String getNextContract() {
        return null;
    }

}

@@ -13,16 +13,37 @@
 phone;%0A%0A
+import java.io.File;%0A
 import j
@@ -112,91 +112,74 @@
 ss h
-andles the customers information when %0A * searching for the customer id number
+olds a list of all customers and provides methods to access it
 .%0A *
- 
 %0A * 
@@ -300,20 +300,16 @@
 taFile;%0A
-    
 %0A    /**
@@ -320,33 +320,174 @@
   * 
-Adds customer to the data
+Constructor for the class CustomerList. %3Cbr /%3E%0A     * First creates an instance of DataFileIO %3Cbr /%3E%0A     * and adds reference to HashMap objects it gets from an xml-
 file
@@ -716,32 +716,39 @@
 ific customerId%0A
+     *%0A
      * @param cu
@@ -818,24 +818,8 @@
 und 
-%0A     *         
 null
@@ -834,16 +834,23 @@
 omer not
+%0A     *
  found%0A 
@@ -855,21 +855,16 @@
 %0A     */
-     
 %0A    pub
@@ -878,23 +878,24 @@
 hMap get
-Service
+Customer
 ById(int
@@ -1156,16 +1156,23 @@
 ervice.%0A
+     *%0A
      * @
@@ -1177,16 +1177,18 @@
  @param 
+  
 serviceI
@@ -1208,23 +1208,60 @@
 urn 
-customer number
+ The number of customers with the specified service.
 %0A   
@@ -1335,24 +1335,226 @@
     
-return 0
+int customerCount = 0;%0A        for (HashMap hashMap : this) %7B%0A            if ((int) hashMap.get(%22serviceId%22) == serviceId) %7B%0A                customerCount++;%0A            %7D%0A        %7D%0A        return customerCount
 ;%0A    %7D%0A
     
@@ -1545,28 +1545,24 @@
 ount;%0A    %7D%0A
-    
 %0A    /**%0A   
@@ -1569,80 +1569,431 @@
   * 
-Prepares the report%0A     */%0A    public void prepareReport() %7B
+Gets the number of customers registered by a user.%0A     *%0A     * @param   userId%0A     * @return  The number of customers registered by a user.%0A     */%0A    public int getCustomerCountByUser(int userId) %7B%0A        int customerCount = 0;%0A        for (HashMap hashMap : this) %7B%0A            if ((int) hashMap.get(%22userId%22) == userId) %7B%0A                customerCount++;%0A            %7D%0A        %7D%0A        return customerCount;
 %0A    %7D%0A
-    
 %0A   
@@ -2013,118 +2013,1194 @@
 ets 
-the next contract%0A     * @return null%0A     */%0A    public String getNextContract() %7B%0A        return null;%0A    %7D%0A
+a list of files in a folder with a specific extension.%0A     *%0A     * @param folderName Folder to search for files. Use %22.%22 for root.%0A     * @param validExtension Valid file extension.%0A     * @return ArayList with relative file-paths as Strings.%0A     */%0A    public ArrayList getFileList(String folderName, String validExtension) %7B%0A        ArrayList files = new ArrayList();%0A        File folder = new File(folderName); // the folder to check for files%0A        File%5B%5D folderContent = folder.listFiles(); //a list of all files and folders within the chosen folder%0A%0A        for (File file : folderContent) %7B%0A            String fileName = file.toString();%0A            String fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);%0A            if (file.isFile() & fileExtension.equalsIgnoreCase(validExtension)) %7B%0A                // Checks that it is not a folder or a file of another type.%0A                files.add(fileName);%0A            %7D%0A        %7D%0A        return files;%0A    %7D%0A%0A    /**%0A     * Saves data to xml file.%0A     *%0A     * @return true if data was saved false if data was not saved%0A     */%0A    public boolean saveData() %7B%0A        return customerDataFile.write(this);%0A    %7D
 %0A%7D%0A

Update CustomerList.java