View Javadoc

1   package org.jcr_blog.commons.gravatar;
2   
3   /**
4    * Parameter for Gravatar Request.
5    * See Builder Pattern.
6    * See http://de.gravatar.com/site/implement/images/ .
7    * @author Sebastian Prehn <sebastian.prehn@planetswebdesign.de>
8    */
9   public class Parameter {
10  
11      // required parameter
12      final String email;
13  
14      // optional parameters
15      private Integer size = null;
16      private Rating rating = null;
17      private DefaultImage defaultImage = null;
18      private boolean secure = false;
19      private boolean forceDefault = false;
20  
21      public Parameter(final String email) {
22          if(email == null) {
23              throw new IllegalArgumentException("email must not be null");
24          }
25          this.email = email;
26      }
27  
28      public Parameter size(final int size) {
29          if (!(1 <= size && size <= 512)) {
30              throw new IllegalArgumentException("images size has to be within 1px to 512px");
31          }
32          this.size = size;
33          return this;
34      }
35  
36      public Parameter rating(final Rating rating) {
37          if (rating == null) {
38              throw new IllegalArgumentException("rating must not be null");
39          }
40          this.rating = rating;
41          return this;
42      }
43  
44      public Parameter defaultImage(final DefaultImage defaultImage) {
45          if(defaultImage == null) {
46              throw new IllegalArgumentException("defaultImage must not be null");
47          }
48          this.defaultImage = defaultImage;
49          return this;
50      }
51  
52      public Parameter secure(final boolean secure) {
53          this.secure = secure;
54          return this;
55      }
56  
57      public Parameter forceDefault(final boolean forceDefault) {
58          this.forceDefault = forceDefault;
59          return this;
60      }
61      
62      public DefaultImage getDefaultImage() {
63          return this.defaultImage;
64      }
65  
66      public String getEmail() {
67          return this.email;
68      }
69  
70      public Rating getRating() {
71          return this.rating;
72      }
73  
74      public Integer getSize() {
75          return this.size;
76      }
77  
78      public boolean isSecure() {
79          return this.secure;
80      }
81  
82      public boolean isForceDefault() {
83          return forceDefault;
84      }
85  
86  }