enterprises.orbital.impl.evexmlapi.ApiRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eve-xml-api Show documentation
Show all versions of eve-xml-api Show documentation
Library to interact with EVE XML API servers
package enterprises.orbital.impl.evexmlapi;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
* Class encapsulating an API request which consists of:
*
* - An ApiEndpoint
*
- An optional ApiAuth containing credentials
*
- An optional Map<String, String> of query parameters
*
*/
public class ApiRequest implements Comparable {
private final ApiEndpoint endpoint;
private final ApiAuth auth;
private final Map params;
public ApiRequest(ApiEndpoint endpoint, ApiAuth auth, Map params) {
this.endpoint = endpoint;
this.auth = auth;
this.params = params;
}
public ApiRequest(ApiEndpoint endpoint, Map params) {
this(endpoint, null, params);
}
public ApiRequest(ApiEndpoint endpoint, ApiAuth auth) {
this(endpoint, auth, new HashMap());
}
public ApiRequest(ApiEndpoint endpoint) {
this(endpoint, null, new HashMap());
}
public ApiEndpoint getEndpoint() {
return endpoint;
}
public ApiAuth getAuth() {
return auth;
}
public Map getParams() {
return params;
}
@Override
public int hashCode() {
StringBuilder temp = new StringBuilder(endpoint.getPath());
temp.append(endpoint.getVersion()).append(auth.getKeyID()).append(auth.getCharacterID()).append(auth.getVCode());
for (Entry entry : params.entrySet()) {
temp.append(entry.getKey()).append(entry.getValue());
}
return temp.toString().hashCode();
}
@Override
public int compareTo(ApiRequest o) {
return o.hashCode() - hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ApiRequest) return compareTo((ApiRequest) obj) == 0;
return false;
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("Endpoint: ").append(endpoint).append("\n");
result.append("Auth: ").append(String.valueOf(auth)).append("\n");
for (Entry entry : params.entrySet()) {
result.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
}
return result.toString();
}
}