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