1   package eu.fbk.knowledgestore.server.http;
2   
3   import java.net.URL;
4   
5   import javax.annotation.Nullable;
6   
7   import com.google.common.base.Objects;
8   import com.google.common.base.Preconditions;
9   
10  import eu.fbk.knowledgestore.internal.Util;
11  
12  public final class KeystoreConfig {
13  
14      private final String location;
15  
16      private final URL url;
17  
18      private final String password;
19  
20      @Nullable
21      private final String alias;
22  
23      @Nullable
24      private final String type;
25  
26      public KeystoreConfig(final String location, final String password) {
27          this(location, password, null, null);
28      }
29  
30      public KeystoreConfig(final String location, final String password,
31              @Nullable final String alias, @Nullable final String type) {
32          this.location = Preconditions.checkNotNull(location);
33          this.password = Preconditions.checkNotNull(password);
34          this.alias = alias;
35          this.type = type;
36          this.url = Util.getURL(location);
37      }
38  
39      public String getLocation() {
40          return this.location;
41      }
42  
43      public URL getURL() {
44          return this.url;
45      }
46  
47      public String getPassword() {
48          return this.password;
49      }
50  
51      @Nullable
52      public String getAlias() {
53          return this.alias;
54      }
55  
56      @Nullable
57      public String getType() {
58          return this.type;
59      }
60  
61      @Override
62      public boolean equals(@Nullable final Object object) {
63          if (object == this) {
64              return true;
65          }
66          if (!(object instanceof KeystoreConfig)) {
67              return false;
68          }
69          final KeystoreConfig o = (KeystoreConfig) object;
70          return this.location.equals(o.location) //
71                  && this.password.equals(o.password) //
72                  && Objects.equal(this.alias, o.alias) //
73                  && Objects.equal(this.type, o.type);
74      }
75  
76      @Override
77      public int hashCode() {
78          return Objects.hashCode(this.location, this.password, this.alias, this.type);
79      }
80  
81      @Override
82      public String toString() {
83          final StringBuilder b = new StringBuilder();
84          b.append("location=").append(this.location);
85          b.append(", password=").append(this.password);
86          if (this.alias != null) {
87              b.append(", alias=").append(this.alias);
88          }
89          if (this.type != null) {
90              b.append(", type=").append(this.type);
91          }
92          return b.toString();
93      }
94  
95  }