Java Reference
In-Depth Information
removeCustomer(id);
customers.add(customer);
}
return customer;
}
public Collection<Customer> getAllCustomers() {
return (customers);
}
public Customer removeCustomer(String id) {
Customer customerToRemove;
synchronized (customers) {
customerToRemove = getCustomerById(id);
if (null != customerToRemove)
customers.remove(customerToRemove);
}
return customerToRemove;
}
public Customer getCustomerById(final String id) {
return (Customer) CollectionUtils.find(customers, new Predicate() {
public boolean evaluate(Object o) {
Customer customer = (Customer) o;
return customer.getId().equals(id);
}
});
}
public Customer createCustomer(String firstName, String lastName, Date birthdate ){
synchronized (customers) {
final Customer newCustomer = new Customer(
firstName, lastName, birthdate);
if (!customers.contains(newCustomer)) {
customers.add(newCustomer);
return newCustomer;
} else {
return (Customer) CollectionUtils.find(
customers, new Predicate() {
public boolean evaluate(Object o) {
Customer customer = (Customer) o;
return customer.equals(newCustomer);
}
});
}
}
}
}
Search WWH ::




Custom Search