com.jelastic.api.system.persistence.CalculatingStrategyData Maven / Gradle / Ivy
The newest version!
/*Server class MD5: 4ff5833627f091d47bedecc60c3c152d*/
package com.jelastic.api.system.persistence;
import com.jelastic.api.billing.response.interfaces.ArrayItem;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.math.RoundingMode;
/**
* @name Jelastic API Client
* @version 8.11.2
* @copyright Jelastic, Inc.
*/
public class CalculatingStrategyData extends ArrayItem implements Serializable {
private final static String SCALE = "scale";
private final static String ROUNDING_MODE = "roundingMode";
private final static String DATA = "data";
private final static String SECONDARY = "secondary";
private final static String STRATEGY_MODE = "strategyMode";
private static final String NONE_ROUNDING = "NONE";
private static final String NULL_ROUNDING = "NULL";
private Resource secondary;
private String data;
private StrategyMode strategyMode;
private RoundingMode roundingMode;
private int scale = 0;
boolean roundingModeReceived = false;
public CalculatingStrategyData(Resource secondary) {
this.setSecondary(secondary);
}
public CalculatingStrategyData() {
}
public Resource getSecondary() {
return secondary;
}
public void setSecondary(Resource secondary) {
this.secondary = secondary;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
@Override
public CalculatingStrategyData _fromJSON(JSONObject json) throws JSONException {
if (json.has(SECONDARY)) {
Object object = json.get(SECONDARY);
if (object instanceof String) {
secondary = new Resource((String) object, null, null);
} else {
secondary = new Resource()._fromJSON(json.getJSONObject(SECONDARY));
}
}
if (json.has(DATA)) {
this.data = json.getString(DATA);
}
if (json.has(ROUNDING_MODE)) {
roundingModeReceived = true;
String mode = json.getString(ROUNDING_MODE).toUpperCase();
if (NONE_ROUNDING.equals(mode) || NULL_ROUNDING.equals(mode)) {
this.roundingMode = null;
} else {
this.roundingMode = RoundingMode.valueOf(mode);
}
}
if (json.has(SCALE)) {
this.scale = json.getInt(SCALE);
}
if (json.has(STRATEGY_MODE)) {
this.strategyMode = StrategyMode.valueOf(json.getString(STRATEGY_MODE).toUpperCase());
}
return this;
}
@Override
public JSONObject _toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("id", getId());
if (secondary != null) {
json.put(SECONDARY, secondary._toJSON());
}
if (data != null) {
json.put(DATA, data);
}
json.put(SCALE, scale);
json.put(ROUNDING_MODE, roundingMode == null ? NONE_ROUNDING : roundingMode);
json.put(STRATEGY_MODE, strategyMode);
return json;
}
@Override
public CalculatingStrategyData clone() {
CalculatingStrategyData data = new CalculatingStrategyData();
data.setData(this.data);
if (secondary != null) {
data.setSecondary(this.secondary.clone());
}
data.setRoundingMode(this.getRoundingMode());
data.setScale(this.getScale());
data.setStrategyMode(this.getStrategyMode());
return data;
}
public StrategyMode getStrategyMode() {
return strategyMode;
}
public void setStrategyMode(StrategyMode strategyMode) {
this.strategyMode = strategyMode;
}
public RoundingMode getRoundingMode() {
return roundingMode;
}
public void setRoundingMode(RoundingMode roundingMode) {
this.roundingMode = roundingMode;
}
public int getScale() {
return scale;
}
public void setScale(int scale) {
this.scale = scale;
}
public boolean isRoundingModeReceived() {
return roundingModeReceived;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy