All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jelastic.api.environment.response.ArrayCrossNetworkIPAddressResponse Maven / Gradle / Ivy

The newest version!
/*Server class MD5: f92815c3ff7c2be80efed21b75f1e139*/
package com.jelastic.api.environment.response;

import com.jelastic.api.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.*;

/**
 * @name Jelastic API Client
 * @version 8.11.2
 * @copyright Jelastic, Inc.
 */
public class ArrayCrossNetworkIPAddressResponse extends Response {

    private static final String DETACHED_IPS = "detachedCrossNetworkIps";

    private static final String ATTACHED_IPS = "attachedCrossNetworkIps";

    private Set attachedCrossNetworkIps = new HashSet<>();

    private Set detachedCrossNetworkIps = new HashSet<>();

    public ArrayCrossNetworkIPAddressResponse(int result, String error) {
        super(result, error);
    }

    public ArrayCrossNetworkIPAddressResponse(int result) {
        super(result);
    }

    public ArrayCrossNetworkIPAddressResponse() {
        this(Response.OK);
    }

    public ArrayCrossNetworkIPAddressResponse(Set crossNetworkIpAddresses, boolean isAttached) {
        this(Response.OK);
        if (crossNetworkIpAddresses != null && !crossNetworkIpAddresses.isEmpty()) {
            if (isAttached) {
                attachedCrossNetworkIps = crossNetworkIpAddresses;
            } else {
                detachedCrossNetworkIps = crossNetworkIpAddresses;
            }
        }
    }

    public Set getAttachedCrossNetworkIps() {
        return attachedCrossNetworkIps;
    }

    public Set getDetachedCrossNetworkIps() {
        return detachedCrossNetworkIps;
    }

    @Override
    protected JSONObject _toJSON() throws JSONException {
        JSONObject json = super._toJSON();
        if (!attachedCrossNetworkIps.isEmpty()) {
            json.put(ATTACHED_IPS, attachedCrossNetworkIps);
        }
        if (!detachedCrossNetworkIps.isEmpty()) {
            json.put(DETACHED_IPS, detachedCrossNetworkIps);
        }
        return json;
    }

    @Override
    protected ArrayCrossNetworkIPAddressResponse _fromJSON(JSONObject json) throws JSONException {
        if (json.has(ATTACHED_IPS)) {
            JSONArray attachedIps = json.getJSONArray(ATTACHED_IPS);
            attachedCrossNetworkIps = new HashSet<>();
            for (int i = 0; i < attachedIps.length(); i++) {
                attachedCrossNetworkIps.add(attachedIps.getString(i));
            }
        }
        if (json.has(DETACHED_IPS)) {
            JSONArray detachedIps = json.getJSONArray(DETACHED_IPS);
            detachedCrossNetworkIps = new HashSet<>();
            for (int i = 0; i < detachedIps.length(); i++) {
                detachedCrossNetworkIps.add(detachedIps.getString(i));
            }
        }
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy