mirror of https://github.com/apache/jclouds.git
gogrid: issue 971 adjusting internal class to use ConstuctorProperties
This commit is contained in:
parent
2022bf3fbb
commit
3e1d9b22e7
|
@ -18,19 +18,24 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.gogrid.functions;
|
package org.jclouds.gogrid.functions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.gogrid.domain.Server;
|
import org.jclouds.gogrid.domain.Server;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.functions.ParseJson;
|
import org.jclouds.http.functions.ParseJson;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
|
@ -49,10 +54,17 @@ public class ParseServerNameToCredentialsMapFromJsonResponse implements
|
||||||
// incidental view class to assist in getting the correct data
|
// incidental view class to assist in getting the correct data
|
||||||
// deserialized from json
|
// deserialized from json
|
||||||
private static class Password implements Comparable<Password> {
|
private static class Password implements Comparable<Password> {
|
||||||
@SerializedName("username")
|
@Named("username")
|
||||||
private String userName;
|
private final String userName;
|
||||||
private String password;
|
private final String password;
|
||||||
private Server server;
|
private final Server server;
|
||||||
|
|
||||||
|
@ConstructorProperties({"username", "password", "server"})
|
||||||
|
public Password(String userName, String password, @Nullable Server server) {
|
||||||
|
this.userName = checkNotNull(userName, "username");
|
||||||
|
this.password = checkNotNull(password, "password");
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
return userName;
|
return userName;
|
||||||
|
@ -73,32 +85,21 @@ public class ParseServerNameToCredentialsMapFromJsonResponse implements
|
||||||
if (o == null || getClass() != o.getClass())
|
if (o == null || getClass() != o.getClass())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Password password1 = (Password) o;
|
Password other = (Password) o;
|
||||||
|
return Objects.equal(userName, other.userName)
|
||||||
if (password != null ? !password.equals(password1.password)
|
&& Objects.equal(password, other.password)
|
||||||
: password1.password != null)
|
&& Objects.equal(server, other.server);
|
||||||
return false;
|
|
||||||
if (server != null ? !server.equals(password1.server)
|
|
||||||
: password1.server != null)
|
|
||||||
return false;
|
|
||||||
if (userName != null ? !userName.equals(password1.userName)
|
|
||||||
: password1.userName != null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = userName != null ? userName.hashCode() : 0;
|
return Objects.hashCode(userName, password, server);
|
||||||
result = 31 * result + (password != null ? password.hashCode() : 0);
|
|
||||||
result = 31 * result + (server != null ? server.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Password o) {
|
public int compareTo(Password o) {
|
||||||
if (null == o.getServer() || null == server) return -1;
|
if (null == o.getServer()) return null == server ? 0 : -1;
|
||||||
|
if (server == null) return 1;
|
||||||
return server.getName().compareTo(o.getServer().getName());
|
return server.getName().compareTo(o.getServer().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +108,7 @@ public class ParseServerNameToCredentialsMapFromJsonResponse implements
|
||||||
public Map<String, Credentials> apply(HttpResponse arg0) {
|
public Map<String, Credentials> apply(HttpResponse arg0) {
|
||||||
Map<String, Credentials> serverNameToCredentials = Maps.newHashMap();
|
Map<String, Credentials> serverNameToCredentials = Maps.newHashMap();
|
||||||
for (Password password : json.apply(arg0).getList()) {
|
for (Password password : json.apply(arg0).getList()) {
|
||||||
if( null != password.getServer())
|
if (null != password.getServer())
|
||||||
serverNameToCredentials.put(password.getServer().getName(),
|
serverNameToCredentials.put(password.getServer().getName(),
|
||||||
new Credentials(password.getUserName(), password.getPassword()));
|
new Credentials(password.getUserName(), password.getPassword()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue