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