1 package org.eclipse.aether.util.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Map;
23 import static java.util.Objects.requireNonNull;
24
25 import org.eclipse.aether.repository.Authentication;
26 import org.eclipse.aether.repository.AuthenticationContext;
27 import org.eclipse.aether.repository.AuthenticationDigest;
28
29
30
31
32 final class StringAuthentication
33 implements Authentication
34 {
35
36 private final String key;
37
38 private final String value;
39
40 StringAuthentication( String key, String value )
41 {
42 this.key = requireNonNull( key, "authentication key cannot be null" );
43 if ( key.length() == 0 )
44 {
45 throw new IllegalArgumentException( "authentication key cannot be empty" );
46 }
47 this.value = value;
48 }
49
50 public void fill( AuthenticationContext context, String key, Map<String, String> data )
51 {
52 context.put( this.key, value );
53 }
54
55 public void digest( AuthenticationDigest digest )
56 {
57 digest.update( key, value );
58 }
59
60 @Override
61 public boolean equals( Object obj )
62 {
63 if ( this == obj )
64 {
65 return true;
66 }
67 if ( obj == null || !getClass().equals( obj.getClass() ) )
68 {
69 return false;
70 }
71 StringAuthentication that = (StringAuthentication) obj;
72 return eq( key, that.key ) && eq( value, that.value );
73 }
74
75 private static <T> boolean eq( T s1, T s2 )
76 {
77 return s1 != null ? s1.equals( s2 ) : s2 == null;
78 }
79
80 @Override
81 public int hashCode()
82 {
83 int hash = 17;
84 hash = hash * 31 + key.hashCode();
85 hash = hash * 31 + ( ( value != null ) ? value.hashCode() : 0 );
86 return hash;
87 }
88
89 @Override
90 public String toString()
91 {
92 return key + "=" + value;
93 }
94
95 }