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

com.finbourne.horizon.model.LusidField Maven / Gradle / Ivy

The newest version!
/*
 * FINBOURNE Horizon API
 *
 * Contact: [email protected]
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

package com.finbourne.horizon.model;

import java.util.Objects;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.openapitools.jackson.nullable.JsonNullable;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.finbourne.horizon.JSON;

/**
 * A field on a LUSID entity
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class LusidField {
  public static final String SERIALIZED_NAME_FIELD_NAME = "fieldName";
  @SerializedName(SERIALIZED_NAME_FIELD_NAME)
  private String fieldName;

  public static final String SERIALIZED_NAME_DEFAULT_VALUE = "defaultValue";
  @SerializedName(SERIALIZED_NAME_DEFAULT_VALUE)
  private String defaultValue;

  public static final String SERIALIZED_NAME_VENDOR_PACKAGES = "vendorPackages";
  @SerializedName(SERIALIZED_NAME_VENDOR_PACKAGES)
  private List vendorPackages = new ArrayList<>();

  public static final String SERIALIZED_NAME_VENDOR_NAMESPACES = "vendorNamespaces";
  @SerializedName(SERIALIZED_NAME_VENDOR_NAMESPACES)
  private List vendorNamespaces = new ArrayList<>();

  public static final String SERIALIZED_NAME_VENDOR_FIELDS = "vendorFields";
  @SerializedName(SERIALIZED_NAME_VENDOR_FIELDS)
  private List vendorFields = new ArrayList<>();

  public static final String SERIALIZED_NAME_TRANSFORMATION_DESCRIPTION = "transformationDescription";
  @SerializedName(SERIALIZED_NAME_TRANSFORMATION_DESCRIPTION)
  private String transformationDescription;

  public static final String SERIALIZED_NAME_ENTITY_TYPE = "entityType";
  @SerializedName(SERIALIZED_NAME_ENTITY_TYPE)
  private String entityType;

  public static final String SERIALIZED_NAME_ENTITY_SUB_TYPE = "entitySubType";
  @SerializedName(SERIALIZED_NAME_ENTITY_SUB_TYPE)
  private String entitySubType;

  public LusidField() {
  }

  public LusidField fieldName(String fieldName) {
    
    this.fieldName = fieldName;
    return this;
  }

   /**
   * The name of the LUSID field.
   * @return fieldName
  **/
  @jakarta.annotation.Nonnull
  public String getFieldName() {
    return fieldName;
  }


  public void setFieldName(String fieldName) {
    this.fieldName = fieldName;
  }


  public LusidField defaultValue(String defaultValue) {
    
    this.defaultValue = defaultValue;
    return this;
  }

   /**
   * The default value for the field.
   * @return defaultValue
  **/
  @jakarta.annotation.Nullable
  public String getDefaultValue() {
    return defaultValue;
  }


  public void setDefaultValue(String defaultValue) {
    this.defaultValue = defaultValue;
  }


  public LusidField vendorPackages(List vendorPackages) {
    
    this.vendorPackages = vendorPackages;
    return this;
  }

  public LusidField addVendorPackagesItem(String vendorPackagesItem) {
    if (this.vendorPackages == null) {
      this.vendorPackages = new ArrayList<>();
    }
    this.vendorPackages.add(vendorPackagesItem);
    return this;
  }

   /**
   * The vendor package that contributes to this LUSID field.
   * @return vendorPackages
  **/
  @jakarta.annotation.Nonnull
  public List getVendorPackages() {
    return vendorPackages;
  }


  public void setVendorPackages(List vendorPackages) {
    this.vendorPackages = vendorPackages;
  }


  public LusidField vendorNamespaces(List vendorNamespaces) {
    
    this.vendorNamespaces = vendorNamespaces;
    return this;
  }

  public LusidField addVendorNamespacesItem(String vendorNamespacesItem) {
    if (this.vendorNamespaces == null) {
      this.vendorNamespaces = new ArrayList<>();
    }
    this.vendorNamespaces.add(vendorNamespacesItem);
    return this;
  }

   /**
   * The vendor namespace that contributes to this LUSID field.
   * @return vendorNamespaces
  **/
  @jakarta.annotation.Nonnull
  public List getVendorNamespaces() {
    return vendorNamespaces;
  }


  public void setVendorNamespaces(List vendorNamespaces) {
    this.vendorNamespaces = vendorNamespaces;
  }


  public LusidField vendorFields(List vendorFields) {
    
    this.vendorFields = vendorFields;
    return this;
  }

  public LusidField addVendorFieldsItem(String vendorFieldsItem) {
    if (this.vendorFields == null) {
      this.vendorFields = new ArrayList<>();
    }
    this.vendorFields.add(vendorFieldsItem);
    return this;
  }

   /**
   * The underlying fields on the vendor package that contribute to this LUSID field
   * @return vendorFields
  **/
  @jakarta.annotation.Nonnull
  public List getVendorFields() {
    return vendorFields;
  }


  public void setVendorFields(List vendorFields) {
    this.vendorFields = vendorFields;
  }


  public LusidField transformationDescription(String transformationDescription) {
    
    this.transformationDescription = transformationDescription;
    return this;
  }

   /**
   * A description of how the vendor package's field(s) get mapped to the LUSID field
   * @return transformationDescription
  **/
  @jakarta.annotation.Nullable
  public String getTransformationDescription() {
    return transformationDescription;
  }


  public void setTransformationDescription(String transformationDescription) {
    this.transformationDescription = transformationDescription;
  }


  public LusidField entityType(String entityType) {
    
    this.entityType = entityType;
    return this;
  }

   /**
   * LUSID Entity this refers to (e.g. Instrument)
   * @return entityType
  **/
  @jakarta.annotation.Nonnull
  public String getEntityType() {
    return entityType;
  }


  public void setEntityType(String entityType) {
    this.entityType = entityType;
  }


  public LusidField entitySubType(String entitySubType) {
    
    this.entitySubType = entitySubType;
    return this;
  }

   /**
   * Sub-Entity this field refers to (e.g. Equity)
   * @return entitySubType
  **/
  @jakarta.annotation.Nullable
  public String getEntitySubType() {
    return entitySubType;
  }


  public void setEntitySubType(String entitySubType) {
    this.entitySubType = entitySubType;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    LusidField lusidField = (LusidField) o;
    return Objects.equals(this.fieldName, lusidField.fieldName) &&
        Objects.equals(this.defaultValue, lusidField.defaultValue) &&
        Objects.equals(this.vendorPackages, lusidField.vendorPackages) &&
        Objects.equals(this.vendorNamespaces, lusidField.vendorNamespaces) &&
        Objects.equals(this.vendorFields, lusidField.vendorFields) &&
        Objects.equals(this.transformationDescription, lusidField.transformationDescription) &&
        Objects.equals(this.entityType, lusidField.entityType) &&
        Objects.equals(this.entitySubType, lusidField.entitySubType);
  }

  private static  boolean equalsNullable(JsonNullable a, JsonNullable b) {
    return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
  }

  @Override
  public int hashCode() {
    return Objects.hash(fieldName, defaultValue, vendorPackages, vendorNamespaces, vendorFields, transformationDescription, entityType, entitySubType);
  }

  private static  int hashCodeNullable(JsonNullable a) {
    if (a == null) {
      return 1;
    }
    return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class LusidField {\n");
    sb.append("    fieldName: ").append(toIndentedString(fieldName)).append("\n");
    sb.append("    defaultValue: ").append(toIndentedString(defaultValue)).append("\n");
    sb.append("    vendorPackages: ").append(toIndentedString(vendorPackages)).append("\n");
    sb.append("    vendorNamespaces: ").append(toIndentedString(vendorNamespaces)).append("\n");
    sb.append("    vendorFields: ").append(toIndentedString(vendorFields)).append("\n");
    sb.append("    transformationDescription: ").append(toIndentedString(transformationDescription)).append("\n");
    sb.append("    entityType: ").append(toIndentedString(entityType)).append("\n");
    sb.append("    entitySubType: ").append(toIndentedString(entitySubType)).append("\n");
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }


  public static HashSet openapiFields;
  public static HashSet openapiRequiredFields;

  static {
    // a set of all properties/fields (JSON key names)
    openapiFields = new HashSet();
    openapiFields.add("fieldName");
    openapiFields.add("defaultValue");
    openapiFields.add("vendorPackages");
    openapiFields.add("vendorNamespaces");
    openapiFields.add("vendorFields");
    openapiFields.add("transformationDescription");
    openapiFields.add("entityType");
    openapiFields.add("entitySubType");

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet();
    openapiRequiredFields.add("fieldName");
    openapiRequiredFields.add("vendorPackages");
    openapiRequiredFields.add("vendorNamespaces");
    openapiRequiredFields.add("vendorFields");
    openapiRequiredFields.add("entityType");
  }

 /**
  * Validates the JSON Element and throws an exception if issues found
  *
  * @param jsonElement JSON Element
  * @throws IOException if the JSON Element is invalid with respect to LusidField
  */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!LusidField.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in LusidField is not found in the empty JSON string", LusidField.openapiRequiredFields.toString()));
        }
      }

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : LusidField.openapiRequiredFields) {
        if (jsonElement.getAsJsonObject().get(requiredField) == null) {
          throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      if (!jsonObj.get("fieldName").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `fieldName` to be a primitive type in the JSON string but got `%s`", jsonObj.get("fieldName").toString()));
      }
      if ((jsonObj.get("defaultValue") != null && !jsonObj.get("defaultValue").isJsonNull()) && !jsonObj.get("defaultValue").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `defaultValue` to be a primitive type in the JSON string but got `%s`", jsonObj.get("defaultValue").toString()));
      }
      // ensure the required json array is present
      if (jsonObj.get("vendorPackages") == null) {
        throw new IllegalArgumentException("Expected the field `linkedContent` to be an array in the JSON string but got `null`");
      } else if (!jsonObj.get("vendorPackages").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `vendorPackages` to be an array in the JSON string but got `%s`", jsonObj.get("vendorPackages").toString()));
      }
      // ensure the required json array is present
      if (jsonObj.get("vendorNamespaces") == null) {
        throw new IllegalArgumentException("Expected the field `linkedContent` to be an array in the JSON string but got `null`");
      } else if (!jsonObj.get("vendorNamespaces").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `vendorNamespaces` to be an array in the JSON string but got `%s`", jsonObj.get("vendorNamespaces").toString()));
      }
      // ensure the required json array is present
      if (jsonObj.get("vendorFields") == null) {
        throw new IllegalArgumentException("Expected the field `linkedContent` to be an array in the JSON string but got `null`");
      } else if (!jsonObj.get("vendorFields").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `vendorFields` to be an array in the JSON string but got `%s`", jsonObj.get("vendorFields").toString()));
      }
      if ((jsonObj.get("transformationDescription") != null && !jsonObj.get("transformationDescription").isJsonNull()) && !jsonObj.get("transformationDescription").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `transformationDescription` to be a primitive type in the JSON string but got `%s`", jsonObj.get("transformationDescription").toString()));
      }
      if (!jsonObj.get("entityType").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `entityType` to be a primitive type in the JSON string but got `%s`", jsonObj.get("entityType").toString()));
      }
      if ((jsonObj.get("entitySubType") != null && !jsonObj.get("entitySubType").isJsonNull()) && !jsonObj.get("entitySubType").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `entitySubType` to be a primitive type in the JSON string but got `%s`", jsonObj.get("entitySubType").toString()));
      }
  }

  public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
    @SuppressWarnings("unchecked")
    @Override
    public  TypeAdapter create(Gson gson, TypeToken type) {
       if (!LusidField.class.isAssignableFrom(type.getRawType())) {
         return null; // this class only serializes 'LusidField' and its subtypes
       }
       final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
       final TypeAdapter thisAdapter
                        = gson.getDelegateAdapter(this, TypeToken.get(LusidField.class));

       return (TypeAdapter) new TypeAdapter() {
           @Override
           public void write(JsonWriter out, LusidField value) throws IOException {
             JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
             elementAdapter.write(out, obj);
           }

           @Override
           public LusidField read(JsonReader in) throws IOException {
             JsonElement jsonElement = elementAdapter.read(in);
             validateJsonElement(jsonElement);
             return thisAdapter.fromJsonTree(jsonElement);
           }

       }.nullSafe();
    }
  }

 /**
  * Create an instance of LusidField given an JSON string
  *
  * @param jsonString JSON string
  * @return An instance of LusidField
  * @throws IOException if the JSON string is invalid with respect to LusidField
  */
  public static LusidField fromJson(String jsonString) throws IOException {
    return JSON.getGson().fromJson(jsonString, LusidField.class);
  }

 /**
  * Convert an instance of LusidField to an JSON string
  *
  * @return JSON string
  */
  public String toJson() {
    return JSON.getGson().toJson(this);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy