summaryrefslogtreecommitdiff
path: root/src/main/java/foo/zaaarf/routecompass/Route.java
blob: ade19a651b06cc674b84e9d5266b49b773fc7410 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package foo.zaaarf.routecompass;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Internal representation of a REST route.
 */
public class Route {
   public final String route;
   public final String method;
   public final String produces;
   public final String consumes;
   public final boolean deprecated;

   public Route(String route, RequestMethod[] methods, MediaType consumes, MediaType produces, boolean deprecated) {
      this.route = route;

      StringBuilder methodStringBuilder = new StringBuilder("[");
      for(RequestMethod m : methods)
         methodStringBuilder
            .append(m.name())
            .append("|");
      methodStringBuilder
         .deleteCharAt(methodStringBuilder.length() - 1)
         .append("]");
      this.method = methodStringBuilder.toString();

      if(produces != null) this.produces = produces.toString();
      else this.produces = null;

      if(consumes != null) this.consumes = consumes.toString();
      else this.consumes = null;

      this.deprecated = deprecated;
   }
}