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.Arrays;
23 import java.util.Collection;
24 import java.util.Map;
25
26 import org.eclipse.aether.repository.Authentication;
27 import org.eclipse.aether.repository.AuthenticationContext;
28 import org.eclipse.aether.repository.AuthenticationDigest;
29
30
31
32
33
34 final class ChainedAuthentication
35 implements Authentication
36 {
37
38 private final Authentication[] authentications;
39
40 ChainedAuthentication( Authentication... authentications )
41 {
42 if ( authentications != null && authentications.length > 0 )
43 {
44 this.authentications = authentications.clone();
45 }
46 else
47 {
48 this.authentications = new Authentication[0];
49 }
50 }
51
52 ChainedAuthentication( Collection<? extends Authentication> authentications )
53 {
54 if ( authentications != null && !authentications.isEmpty() )
55 {
56 this.authentications = authentications.toArray( new Authentication[authentications.size()] );
57 }
58 else
59 {
60 this.authentications = new Authentication[0];
61 }
62 }
63
64 public void fill( AuthenticationContext context, String key, Map<String, String> data )
65 {
66 for ( Authentication authentication : authentications )
67 {
68 authentication.fill( context, key, data );
69 }
70 }
71
72 public void digest( AuthenticationDigest digest )
73 {
74 for ( Authentication authentication : authentications )
75 {
76 authentication.digest( digest );
77 }
78 }
79
80 @Override
81 public boolean equals( Object obj )
82 {
83 if ( this == obj )
84 {
85 return true;
86 }
87 if ( obj == null || !getClass().equals( obj.getClass() ) )
88 {
89 return false;
90 }
91 ChainedAuthentication that = (ChainedAuthentication) obj;
92 return Arrays.equals( authentications, that.authentications );
93 }
94
95 @Override
96 public int hashCode()
97 {
98 return Arrays.hashCode( authentications );
99 }
100
101 @Override
102 public String toString()
103 {
104 StringBuilder buffer = new StringBuilder( 256 );
105 for ( Authentication authentication : authentications )
106 {
107 if ( buffer.length() > 0 )
108 {
109 buffer.append( ", " );
110 }
111 buffer.append( authentication );
112 }
113 return buffer.toString();
114 }
115
116 }