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