PostgresChunk.java [src/csip] Revision: 71821307bfe742c00c6dc582c171224a9ac59935  Date: Fri Apr 21 11:46:19 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;
    }


    public boolean equals(Object obj) {
        return this.name.equals(((PostgresChunk) obj).getName());
    }


    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();
    }
    
}