/[projects]/miscJava/Test4Simple/src/main/java/dk/thoerup/webservice/PersonService.java
ViewVC logotype

Diff of /miscJava/Test4Simple/src/main/java/dk/thoerup/webservice/PersonService.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2521 by torben, Wed Apr 29 09:32:47 2015 UTC revision 2522 by torben, Wed Apr 29 09:47:11 2015 UTC
# Line 1  Line 1 
1  package dk.thoerup.webservice;  package dk.thoerup.webservice;
2    
3    import java.util.ArrayList;
4  import java.util.Collection;  import java.util.Collection;
5  import java.util.GregorianCalendar;  import java.util.GregorianCalendar;
6  import java.util.HashMap;  import java.util.HashMap;
# Line 62  public class PersonService { Line 63  public class PersonService {
63          @Path("/search")          @Path("/search")
64          @GET          @GET
65          @Produces(MediaType.APPLICATION_JSON)          @Produces(MediaType.APPLICATION_JSON)
66          public Person search(          public Collection<Person> search(
67                          @Size(min=1) @QueryParam("q") String q                          @QueryParam("q") String q
68                          ) {                          ) {
69                  q = q.toLowerCase();                  q = q.toLowerCase();
70                                    
71                    ArrayList<Person> result = new ArrayList<Person>();
72                    
73                  for(Person p : persons.values()) {                  for(Person p : persons.values()) {
74                          if (p.getName().toLowerCase().contains(q))                          if (p.getName().toLowerCase().contains(q)) {
75                                  return p;                                  result.add(p);
76                            }
77                                    
78                    }
79                    if (result.isEmpty()) {
80                            throw new PersonNotFoundException();
81                  }                  }
82                                    
83                  throw new PersonNotFoundException();                  return result;
84          }          }
85    
86    

Legend:
Removed from v.2521  
changed lines
  Added in v.2522

  ViewVC Help
Powered by ViewVC 1.1.20