Autour de Java

Totorials, howto and how it works at Lebanese java Users Group and Cnam Liban

View project on GitHub
package net.cofares.ljug.rest;

import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

public class CustomerList {
  private static final CopyOnWriteArrayList<Customer> cList = new CopyOnWriteArrayList<>();

  static {
    // Create list of customers
    cList.add(
        new Customer.CustomerBuilder().id()
        .firstName("George")
        .lastName("Washington")
        .email("[email protected]")
        .city("Mt Vernon")
        .state("VA")
        .birthday("1732-02-23")
        .build()
    );

    cList.add(
        new Customer.CustomerBuilder().id()
        .firstName("John")
        .lastName("Adams")
        .email("[email protected]")
        .city("Braintree")
        .state("MA")
        .birthday("1735-10-30")
        .build()
    );

    cList.add(
        new Customer.CustomerBuilder().id()
        .firstName("Thomas")
        .lastName("Jefferson")
        .email("[email protected]")
        .city("CharlottesVille")
        .state("VA")
        .birthday("1743-04-13")
        .build()
    );

    cList.add(
        new Customer.CustomerBuilder().id()
        .firstName("James")
        .lastName("Madison")
        .email("[email protected]")
        .city("Orange")
        .state("VA")
        .birthday("1751-03-16")
        .build()
    );

    cList.add(
        new Customer.CustomerBuilder().id()
        .firstName("James")
        .lastName("Monroe")
        .email("[email protected]")
        .city("New York")
        .state("NY")
        .birthday("1758-04-28")
        .build()
    );

  }
  
  private CustomerList(){}
  
  public static CopyOnWriteArrayList<Customer> getInstance(){
    return cList;
  }
  
  public static void testList(){
    CopyOnWriteArrayList<Customer> list = CustomerList.getInstance();
    list.stream()
        .forEach(i -> System.out.println(i));
    String cString = 
        list.stream()
        .map( c -> c.toString())
        .collect(Collectors.joining("\n"));
    System.out.println(cString);
  }
    
  public static void main(String[] args) {
    CustomerList.testList();
  }
  
}