package org.eclipse.aether.util.repository;
import java.util.Map;
import static java.util.Objects.requireNonNull;
import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.AuthenticationContext;
import org.eclipse.aether.repository.AuthenticationDigest;
final class ComponentAuthentication
implements Authentication
{
private final String key;
private final Object value;
ComponentAuthentication( String key, Object value )
{
this.key = requireNonNull( key, "authentication key cannot be null" );
if ( key.length() == 0 )
{
throw new IllegalArgumentException( "authentication key cannot be empty" );
}
this.value = value;
}
public void fill( AuthenticationContext context, String key, Map<String, String> data )
{
context.put( this.key, value );
}
public void digest( AuthenticationDigest digest )
{
if ( value != null )
{
digest.update( key, value.getClass().getName() );
}
}
@Override
public boolean equals( Object obj )
{
if ( this == obj )
{
return true;
}
if ( obj == null || !getClass().equals( obj.getClass() ) )
{
return false;
}
ComponentAuthentication that = (ComponentAuthentication) obj;
return key.equals( that.key ) && eqClass( value, that.value );
}
private static <T> boolean eqClass( T s1, T s2 )
{
return ( s1 == null ) ? s2 == null : s2 != null && s1.getClass().equals( s2.getClass() );
}
@Override
public int hashCode()
{
int hash = 17;
hash = hash * 31 + key.hashCode();
hash = hash * 31 + ( ( value != null ) ? value.getClass().hashCode() : 0 );
return hash;
}
@Override
public String toString()
{
return key + "=" + value;
}
}