Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. package com.cristian;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Optional;
  7. import java.util.function.Function;
  8. import java.util.stream.Collectors;
  9. import java.util.stream.Stream;
  10.  
  11. public class PersonRepository {
  12.  
  13. private static final Map<Integer, Person> peopleMap =
  14. Stream.of(new Person(1, "Foo"), new Person(2, "Bar", new Car(1, 35000)))
  15. .collect(Collectors.toMap(Person::getId, Function.identity()));
  16.  
  17. public Optional<Person> findById(int id) {
  18. return Optional.ofNullable(peopleMap.get(id));
  19. }
  20.  
  21. public List<Person> findAll() {
  22. return new ArrayList<>(peopleMap.values());
  23. }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement