--- miscJava/Test4Simple/src/main/java/dk/thoerup/webservice/PersonService.java 2015/04/29 09:32:47 2521 +++ miscJava/Test4Simple/src/main/java/dk/thoerup/webservice/PersonService.java 2015/04/29 09:47:11 2522 @@ -1,5 +1,6 @@ package dk.thoerup.webservice; +import java.util.ArrayList; import java.util.Collection; import java.util.GregorianCalendar; import java.util.HashMap; @@ -62,17 +63,24 @@ @Path("/search") @GET @Produces(MediaType.APPLICATION_JSON) - public Person search( - @Size(min=1) @QueryParam("q") String q + public Collection search( + @QueryParam("q") String q ) { q = q.toLowerCase(); + ArrayList result = new ArrayList(); + for(Person p : persons.values()) { - if (p.getName().toLowerCase().contains(q)) - return p; + if (p.getName().toLowerCase().contains(q)) { + result.add(p); + } + + } + if (result.isEmpty()) { + throw new PersonNotFoundException(); } - throw new PersonNotFoundException(); + return result; }