Skip to content

Instantly share code, notes, and snippets.

@gkhan496
Created July 25, 2018 12:49
package com.mycompany.client;
import java.util.ArrayList;
import java.util.List;
public class CustomerDataService {
public List<Customer> customerList=new ArrayList<>();
Customer e=new Customer();
public CustomerDataService(){
e.setAddress("Hatay/Antakya");
e.setId("0");
e.setName("Gokhan");
e.setPhoneNumber("15134235322452");
customerList.add(e);
}
private static CustomerDataService ourInstance=new
CustomerDataService();
public static CustomerDataService getInstance(){
return ourInstance;
}
public String addCustomer(Customer customer){
String newId=Integer.toString(customerList.size()+1);
customer.setId(newId);
customerList.add(customer);
return newId;
}
public List<Customer> getCustomerList(){
return customerList;
}
public Customer getCustomerById(String id) {
for (Customer customer : customerList) {
if (customer.getId().equals(id)) {
return customer;
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment