PostgresChunk.java [src/csip] Revision: beaf35d680e39fda49d78cf7e170b55dc5710c27 Date: Tue Apr 25 16:47:08 MDT 2017
/*
* $Id$
*
* This file is part of the Cloud Services Integration Platform (CSIP),
* a Model-as-a-Service framework, API and application suite.
*
* 2012-2017, Olaf David and others, OMSLab, Colorado State University.
*
* OMSLab licenses this file to you under the MIT license.
* See the LICENSE file in the project root for more information.
*/
package csip;
import java.sql.Connection;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
/**
*
* @author od
*/
public class PostgresChunk {
String name;
double minLong;
double maxLong;
Connection[] connections;
int currentConnection;
public PostgresChunk(String name, double minLong, double maxLong) {
this.name = name;
this.minLong = minLong;
this.maxLong = maxLong;
}
@Override
public boolean equals(Object obj) {
return this.name.equals(((PostgresChunk) obj).getName());
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + name.hashCode();
result = (int) (31 * result + minLong);
result = (int) (31 * result + maxLong);
result = 31 * result + currentConnection;
return result;
}
public String getName() {
return name;
}
public double getMinLong() {
return minLong;
}
public double getMaxLong() {
return maxLong;
}
public void setConnections(Connection[] connections) {
this.connections = connections;
}
public Connection[] getConnections() {
return connections;
}
public void connectionInc() {
currentConnection++;
}
public int getCurrentConnectionIdx() {
return currentConnection;
}
public void setCurrentConnectionIdx(int currentConnection) {
this.currentConnection = currentConnection;
}
public Connection getCurrentConnection() {
if ((connections != null) && (connections.length >= currentConnection)) {
return connections[currentConnection];
} else {
return null;
}
}
public JSONObject getJSON() {
try {
JSONObject pgchunk = new JSONObject();
pgchunk.put("name", name);
pgchunk.put("minLong", minLong);
pgchunk.put("maxLong", maxLong);
return pgchunk;
} catch (JSONException jse) {
Config.LOG.warning("Error creating JSON representation of a db chunk object");
}
return new JSONObject();
}
}