Merge branch 'JAL-3878_ws-overhaul-3' into with_ws_overhaul-3
[jalview.git] / src / jalview / ws2 / api / Credentials.java
1 package jalview.ws2.api;
2
3 import java.util.Objects;
4
5 public final class Credentials
6 {
7   String username = null;
8   String email = null;
9   String password = null;
10   private static final Credentials EMPTY = new Credentials();
11
12   private Credentials() {
13   }
14   
15   public static final Credentials empty()
16   {
17     return EMPTY;
18   }
19
20   public static final Credentials usingEmail(String email) {
21     Objects.requireNonNull(email);
22     if (email.isEmpty())
23       throw new IllegalArgumentException("empty email");
24     Credentials credentials = new Credentials();
25     credentials.email = email;
26     return credentials;
27   }
28   
29   public static final Credentials usingEmail(String email, String password) {
30     Objects.requireNonNull(email);
31     Objects.requireNonNull(password);
32     if (email.isEmpty())
33       throw new IllegalArgumentException("empty email");
34     Credentials credentials = new Credentials();
35     credentials.email = email;
36     credentials.password = password;
37     return credentials;
38   }
39   
40   public static final Credentials usingUsername(String username, String password) {
41     Objects.requireNonNull(username);
42     Objects.requireNonNull(password);
43     if (username.isEmpty())
44       throw new IllegalArgumentException("empty username");
45     Credentials credentials = new Credentials();
46     credentials.username = username;
47     credentials.password = password;
48     return credentials;
49   }
50 }