package io.github.rebelizant.jaxrsexample.persistence;

import io.github.rebelizant.jaxrsexample.domain.Address;
import io.github.rebelizant.jaxrsexample.domain.Customer;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

/**
 * @author rebelizant
 *         Created on 18.04.16
 */
@Component
public class CustomerRepositoryImpl implements CustomerRepository {

    private ConcurrentMap<Long, Customer> customers = new ConcurrentHashMap<>();

    public CustomerRepositoryImpl() {
        Customer customer = new Customer();
        customer.setId(1L);
        customer.setFirstName("John");
        customer.setLastName("Konstantine");
        Address address = new Address();
        address.setCountry("UK");
        address.setCity("London");
        customer.setAddress(address);
        addCustomer(customer);
    }

    @Override
    public void addCustomer(Customer customer) {
        customers.put(customer.getId(), customer);
    }

    @Override
    public List<Customer> getCustomers() {
        return customers.values().stream().collect(Collectors.toList());
    }

    @Override
    public void updateCustomer(Long id, Customer customer) {
        customers.put(id, customer);
    }

    @Override
    public Customer getCustomer(Long id) {
        return customers.get(id);
    }

    @Override
    public void deleteCustomer(Long id) {
        customers.remove(id);
    }
}

@@ -364,16 +364,120 @@
 ctors;%0A%0A
+import java.util.stream.Stream;%0Aimport java.util.stream.IntStream;%0Aimport java.util.stream.Collectors;%0A%0A
 /**%0A * @
@@ -664,36 +664,8 @@
 mers
- = new ConcurrentHashMap%3C%3E()
 ;%0A%0A 
@@ -713,332 +713,169 @@
     
-C
+c
 ustomer
- customer = new Customer();%0A        customer.setId(1L);%0A        customer.setFirstName(%22John%22);%0A        customer.setLastName(%22Konstantine%22);%0A        Address address = new Address();%0A        address.setCountry(%22UK%22);%0A        address.setCity(%22London%22);%0A        customer.setAddress(address);%0A        addCustomer(customer
+s = IntStream.range(1, 21).mapToObj(id -%3E randomCustomer(id))%0A                                .collect(Collectors.toConcurrentMap(c -%3E c.getId(), c -%3E c)
 );%0A 
@@ -1447,10 +1447,635 @@
 ;%0A    %7D%0A
+    %0A    private Customer randomCustomer(int id) %7B%0A        Customer customer = new Customer();%0A        customer.setId(Long.valueOf(id));%0A        customer.setFirstName(String.format(%22FirstName-%25s%22, id));%0A        customer.setLastName(String.format(%22LastName-%25s%22, id));%0A        Address address = new Address();%0A        address.setCountry(String.format(%22Country-%25s%22, id %25 3));%0A        address.setState(String.format(%22State-%25s%22, id %25 3));%0A        address.setCity(String.format(%22City-%25s%22, id %25 5));%0A        address.setStreet(String.format(%22Street-%25s%22, id %25 7));%0A        customer.setAddress(address);%0A        return customer;%0A    %7D%0A
 %7D%0A

add 20 generated customers for demo