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