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

com.symphony.oss.models.fundmental.canon.SequenceHashesEntity Maven / Gradle / Ivy

/**
 * GENERATED CODE - DO NOT EDIT OR CHECK IN TO SOURCE CODE CONTROL
 *
 * Copyright 2020 Symphony Communication Services, LLC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *----------------------------------------------------------------------------------------------------
 * Generated from
 *    Input source         file:/Users/bruce/symphony/git-SymphonyOSF/oss-models/target/checkout/fundamental-model/src/main/resources/canon/fundamental.json
 *    Template groupId     org.symphonyoss.s2.canon
 *           artifactId    canon-template-java
 *    Template name        template/java/Object/_Entity.java.ftl
 *    At                   2020-01-28 16:55:36 GMT
 *----------------------------------------------------------------------------------------------------
 */

package com.symphony.oss.models.fundmental.canon;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import org.symphonyoss.s2.common.immutable.ImmutableByteArray;

import org.symphonyoss.s2.canon.runtime.IEntity;
import org.symphonyoss.s2.canon.runtime.IModelRegistry;
import org.symphonyoss.s2.canon.runtime.CanonRuntime;
import org.symphonyoss.s2.canon.runtime.Entity;
import org.symphonyoss.s2.canon.runtime.EntityBuilder;
import org.symphonyoss.s2.canon.runtime.EntityFactory;
import org.symphonyoss.s2.canon.runtime.IBuilderFactory;

import org.symphonyoss.s2.common.type.provider.IBooleanProvider;
import org.symphonyoss.s2.common.type.provider.IStringProvider;
import org.symphonyoss.s2.common.type.provider.IIntegerProvider;
import org.symphonyoss.s2.common.type.provider.ILongProvider;
import org.symphonyoss.s2.common.type.provider.IFloatProvider;
import org.symphonyoss.s2.common.type.provider.IDoubleProvider;
import org.symphonyoss.s2.common.type.provider.IImmutableByteArrayProvider;
import org.symphonyoss.s2.common.dom.json.IJsonDomNode;
import org.symphonyoss.s2.common.dom.json.IImmutableJsonDomNode;
import org.symphonyoss.s2.common.dom.json.ImmutableJsonList;
import org.symphonyoss.s2.common.dom.json.ImmutableJsonSet;
import org.symphonyoss.s2.common.dom.json.ImmutableJsonObject;
import org.symphonyoss.s2.common.dom.json.MutableJsonList;
import org.symphonyoss.s2.common.dom.json.MutableJsonSet;
import org.symphonyoss.s2.common.dom.json.MutableJsonObject;
import org.symphonyoss.s2.common.dom.json.JsonArray;
import org.symphonyoss.s2.common.dom.json.JsonList;
import org.symphonyoss.s2.common.dom.json.JsonSet;

import java.util.HashSet;
import java.util.List;
import java.util.LinkedList;
import java.util.Set;
import java.util.Iterator;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.List;
import java.util.LinkedList;
import com.google.common.collect.ImmutableList;
import org.symphonyoss.s2.common.immutable.ImmutableByteArray;
import org.symphonyoss.s2.common.hash.Hash;
import com.symphony.oss.models.fundamental.canon.facade.*;
import com.symphony.oss.models.crypto.canon.facade.*;
import com.symphony.oss.models.crypto.canon.*;
import com.symphony.oss.models.core.canon.facade.*;
import com.symphony.oss.models.core.canon.*;

/**
 * Object ObjectSchema(SequenceHashes)
 * Generated from ObjectSchema(SequenceHashes) at #/components/schemas/SequenceHashes
 */
@Immutable
@SuppressWarnings("unused")
public abstract class SequenceHashesEntity extends Entity
 implements ISequenceHashes, IFundamentalModelEntity
{
  /** Type ID */
  public static final String  TYPE_ID = "com.symphony.s2.model.fundamental.SequenceHashes";
  /** Type version */
  public static final String  TYPE_VERSION = "1.0";
  /** Type major version */
  public static final Integer TYPE_MAJOR_VERSION = 1;
  /** Type minor version */
  public static final Integer TYPE_MINOR_VERSION = 0;
  /** Factory instance */
  public static final Factory FACTORY = new Factory();
  
  /**
   *  Builder factory instance
   *
   *  @deprecated use new SequenceHashes.Builder() or new SequenceHashes.Builder(ISequenceHashesEntity) 
   */
  @Deprecated
  public static final IBuilderFactory BUILDER = new BuilderFactory();

  private final ImmutableSet        unknownKeys_;
  private final List                 _absolute_;
  private final List                 _current_;
  private final List                 _hashCurrent_;

  /**
   * Constructor from builder.
   * 
   * @param builder A mutable builder containing all values.
   */
  public SequenceHashesEntity(SequenceHashes.AbstractSequenceHashesBuilder builder)
  {
    super(builder);
    
    _absolute_ = ImmutableList.copyOf(builder.getAbsolute());

 
    _current_ = ImmutableList.copyOf(builder.getCurrent());

 
    _hashCurrent_ = ImmutableList.copyOf(builder.getHashCurrent());

 


    unknownKeys_ = ImmutableSet.of();
  }
  
  /**
   * Set the _type attribute of the given mutable JSON object to the type ID of this type if it is null and
   * return an immutable copy.
   *
   * @param mutableJsonObject A mutable JSON Object.
   *
   * @return An immutable copy of the given object with the _type attribute set.
   */
  public static ImmutableJsonObject setType(MutableJsonObject mutableJsonObject)
  {
    if(mutableJsonObject.get(CanonRuntime.JSON_TYPE) == null)
      mutableJsonObject.addIfNotNull(CanonRuntime.JSON_TYPE, TYPE_ID);
    
    return mutableJsonObject.immutify();
  }
  
  /**
   * Constructor from mutable JSON object.
   * 
   * @param mutableJsonObject A mutable JSON object containing the serialized form of the object.
   * @param modelRegistry A model registry to use to deserialize any nested objects.
   */
  public SequenceHashesEntity(MutableJsonObject mutableJsonObject, IModelRegistry modelRegistry)
  {
    this(setType(mutableJsonObject), modelRegistry);
  }
   
  /**
   * Constructor from serialised form.
   * 
   * @param jsonObject An immutable JSON object containing the serialized form of the object.
   * @param modelRegistry A model registry to use to deserialize any nested objects.
   */
  public SequenceHashesEntity(ImmutableJsonObject jsonObject, IModelRegistry modelRegistry)
  {
    super(jsonObject, modelRegistry);
    
    if(jsonObject == null)
      throw new IllegalArgumentException("jsonObject is required");
  
    Set keySet = new HashSet<>(super.getCanonUnknownKeys());
    
    if(keySet.remove("absolute"))
    {
      IJsonDomNode  node = jsonObject.get("absolute");
      if(node instanceof JsonArray)
      {
    
      List list = new LinkedList<>();
    
      for(IJsonDomNode itemNode : ((JsonArray)node))
      {
        if(itemNode instanceof IImmutableByteArrayProvider)
        {
          ImmutableByteArray value = ((IImmutableByteArrayProvider)itemNode).asImmutableByteArray();
          list.add(Hash.build(value));
        }
      }
          _absolute_ = ImmutableList.copyOf(list);
      }
      else 
      {
        throw new IllegalArgumentException("absolute must be an array not " + node.getClass().getName());
      }
    }
    else
    {
      _absolute_ = null;
    }
    if(keySet.remove("current"))
    {
      IJsonDomNode  node = jsonObject.get("current");
      if(node instanceof JsonArray)
      {
    
      List list = new LinkedList<>();
    
      for(IJsonDomNode itemNode : ((JsonArray)node))
      {
        if(itemNode instanceof IImmutableByteArrayProvider)
        {
          ImmutableByteArray value = ((IImmutableByteArrayProvider)itemNode).asImmutableByteArray();
          list.add(Hash.build(value));
        }
      }
          _current_ = ImmutableList.copyOf(list);
      }
      else 
      {
        throw new IllegalArgumentException("current must be an array not " + node.getClass().getName());
      }
    }
    else
    {
      _current_ = null;
    }
    if(keySet.remove("hashCurrent"))
    {
      IJsonDomNode  node = jsonObject.get("hashCurrent");
      if(node instanceof JsonArray)
      {
    
      List list = new LinkedList<>();
    
      for(IJsonDomNode itemNode : ((JsonArray)node))
      {
        if(itemNode instanceof IImmutableByteArrayProvider)
        {
          ImmutableByteArray value = ((IImmutableByteArrayProvider)itemNode).asImmutableByteArray();
          list.add(Hash.build(value));
        }
      }
          _hashCurrent_ = ImmutableList.copyOf(list);
      }
      else 
      {
        throw new IllegalArgumentException("hashCurrent must be an array not " + node.getClass().getName());
      }
    }
    else
    {
      _hashCurrent_ = null;
    }

    unknownKeys_ = ImmutableSet.copyOf(keySet);
  }
   
  /**
   * Copy constructor.
   * 
   * @param other Another instance from which all attributes are to be copied.
   */
  public SequenceHashesEntity(ISequenceHashes other)
  {
    super(other);
    
    _absolute_ = other.getAbsolute();
    _current_ = other.getCurrent();
    _hashCurrent_ = other.getHashCurrent();

    unknownKeys_ = other.getCanonUnknownKeys();
  }
  
  @Override
  public ImmutableSet getCanonUnknownKeys()
  {
    return unknownKeys_;
  }
  
  @Override
  public List getAbsolute()
  {
    return _absolute_;
  }
    
  
  @Override
  public List getCurrent()
  {
    return _current_;
  }
    
  
  @Override
  public List getHashCurrent()
  {
    return _hashCurrent_;
  }
    


  @Override
  public boolean equals(Object obj)
  {
    if(obj instanceof SequenceHashesEntity)
      return toString().equals(((SequenceHashesEntity)obj).toString());
    
    return false;
  }
  

  
  /**
   * Factory class for SequenceHashes.
   */
  public static class Factory extends EntityFactory
  {
    protected Factory()
    {
      super(ISequenceHashes.class, ISequenceHashesEntity.class);
    }
    
    /**
     * Return the type identifier (_type JSON attribute) for entities created by this factory.
     * 
     * @return The type identifier for entities created by this factory.
     */
    @Override
    public String getCanonType()
    {
      return TYPE_ID;
    }
    
    /**
     * Return the type version (_version JSON attribute) for entities created by this factory.
     * 
     * @return The type version for entities created by this factory.
     */
    public String getCanonVersion()
    {
      return TYPE_VERSION;
    }
    
    /**
     * Return the major type version for entities created by this factory.
     * 
     * @return The major type version for entities created by this factory.
     */
    public @Nullable Integer getCanonMajorVersion()
    {
      return TYPE_MAJOR_VERSION;
    }
    
    /**
     * Return the minjor type version for entities created by this factory.
     * 
     * @return The minor type version for entities created by this factory.
     */
    public @Nullable Integer getCanonMinorVersion()
    {
      return TYPE_MINOR_VERSION;
    }
        
    /**
     * Return a new entity instance created from the given JSON serialization.
     * 
     * @param jsonObject The JSON serialized form of the required entity.
     * @param modelRegistry A model registry to use to deserialize any nested objects.
     * 
     * @return An instance of the entity represented by the given serialized form.
     * 
     * @throws IllegalArgumentException If the given JSON is not valid.
     */
    @Override
    public ISequenceHashes newInstance(ImmutableJsonObject jsonObject, IModelRegistry modelRegistry)
    {
      return new SequenceHashes(jsonObject, modelRegistry);
    }
    
    /**
     * Return a new entity instance created from the given builder instance.
     * This is used to construct an entity from its builder as the builder also
     * implements the interface of the entity.
     * 
     * @param builder a builder containing values of all fields for the required entity.
     * 
     * @return An instance of the entity represented by the given values.
     * 
     */
    public ISequenceHashes newInstance(Builder builder)
    {
      return new SequenceHashes(builder);
    }
  }
 
  
  /**
   *  Builder factory
   *
   *  @deprecated use new SequenceHashes.Builder() or new SequenceHashes.Builder(ISequenceHashesEntity) 
   */
  @Deprecated
  private static class BuilderFactory implements IBuilderFactory
  {
    /**
     *  @deprecated use new SequenceHashes.Builder() 
     */
    @Deprecated
    @Override
    public Builder newInstance()
    {
      return new Builder();
    }

    /**
     *  @deprecated use new SequenceHashes.Builder(ISequenceHashesEntity) 
     */
    @Deprecated
    @Override
    public Builder newInstance(ISequenceHashesEntity initial)
    {
      return new Builder(initial);
    }
  }
   
  /**
   * Builder for SequenceHashes
   * 
   * Created by calling BUILDER.newInstance();
   *
   */
  public static class Builder extends SequenceHashes.AbstractSequenceHashesBuilder
  {
    /**
     * Constructor.
     */
    public Builder()
    {
      super(Builder.class);
    }

    /**
     * Constructor initialised from another object instance.
     * 
     * @param initial An instance of the built type from which values are to be initialised.
     */
    public Builder(ISequenceHashesEntity initial)
    {
      super(Builder.class, initial);
    }

    @Override
    protected ISequenceHashes construct()
    {
      return new SequenceHashes(this);
    }
  }
  
  
  /**
   * Abstract builder for SequenceHashes. If there are sub-classes of this type then their builders sub-class this builder.
   *
   * @param  The concrete type of the builder, used for fluent methods.
   * @param  The concrete type of the built object.
   */
   public static abstract class AbstractSequenceHashesBuilder, T extends ISequenceHashesEntity>
    extends EntityBuilder
  {
    protected List                 _absolute_ = new LinkedList<>();
    protected List                 _current_ = new LinkedList<>();
    protected List                 _hashCurrent_ = new LinkedList<>();
  
    protected AbstractSequenceHashesBuilder(Class type)
    {
      super(type);
    }
    
    protected AbstractSequenceHashesBuilder(Class type, ISequenceHashesEntity initial)
    {
      super(type, initial);
      
      _absolute_.addAll(initial.getAbsolute());
      _current_.addAll(initial.getCurrent());
      _hashCurrent_.addAll(initial.getHashCurrent());
    }
    
    public B withValues(ImmutableJsonObject jsonObject, boolean ignoreValidation, IModelRegistry modelRegistry)
    {
      if(jsonObject.containsKey("absolute"))
      {
        IJsonDomNode  node = jsonObject.get("absolute");
        if(node instanceof JsonArray)
        {
    
        List list = new LinkedList<>();
    
        for(IJsonDomNode itemNode : ((JsonArray)node))
        {
          if(itemNode instanceof IImmutableByteArrayProvider)
          {
            ImmutableByteArray value = ((IImmutableByteArrayProvider)itemNode).asImmutableByteArray();
            list.add(Hash.build(value));
          }
        }
            _absolute_ = ImmutableList.copyOf(list);
        }
        else if(!ignoreValidation)
        {
          throw new IllegalArgumentException("absolute must be an array not " + node.getClass().getName());
        }
      }
      if(jsonObject.containsKey("current"))
      {
        IJsonDomNode  node = jsonObject.get("current");
        if(node instanceof JsonArray)
        {
    
        List list = new LinkedList<>();
    
        for(IJsonDomNode itemNode : ((JsonArray)node))
        {
          if(itemNode instanceof IImmutableByteArrayProvider)
          {
            ImmutableByteArray value = ((IImmutableByteArrayProvider)itemNode).asImmutableByteArray();
            list.add(Hash.build(value));
          }
        }
            _current_ = ImmutableList.copyOf(list);
        }
        else if(!ignoreValidation)
        {
          throw new IllegalArgumentException("current must be an array not " + node.getClass().getName());
        }
      }
      if(jsonObject.containsKey("hashCurrent"))
      {
        IJsonDomNode  node = jsonObject.get("hashCurrent");
        if(node instanceof JsonArray)
        {
    
        List list = new LinkedList<>();
    
        for(IJsonDomNode itemNode : ((JsonArray)node))
        {
          if(itemNode instanceof IImmutableByteArrayProvider)
          {
            ImmutableByteArray value = ((IImmutableByteArrayProvider)itemNode).asImmutableByteArray();
            list.add(Hash.build(value));
          }
        }
            _hashCurrent_ = ImmutableList.copyOf(list);
        }
        else if(!ignoreValidation)
        {
          throw new IllegalArgumentException("hashCurrent must be an array not " + node.getClass().getName());
        }
      }
      return self();
    }
    
    public void populateAllFields(List result)
    {
      result.add(_absolute_);
      result.add(_current_);
      result.add(_hashCurrent_);
    }
    
    public List getAbsolute()
    {
      return _absolute_;
    }
  
    public B withAbsolute(List value)
    {
      _absolute_.addAll(value);
      return self();
    }
  
    public B withAbsolute(Hash value)
    {
      _absolute_.add(value);
      return self();
    }
    
    public List getCurrent()
    {
      return _current_;
    }
  
    public B withCurrent(List value)
    {
      _current_.addAll(value);
      return self();
    }
  
    public B withCurrent(Hash value)
    {
      _current_.add(value);
      return self();
    }
    
    public List getHashCurrent()
    {
      return _hashCurrent_;
    }
  
    public B withHashCurrent(List value)
    {
      _hashCurrent_.addAll(value);
      return self();
    }
  
    public B withHashCurrent(Hash value)
    {
      _hashCurrent_.add(value);
      return self();
    }
  
    @Override 
    public ImmutableJsonObject getJsonObject()
    {
      MutableJsonObject jsonObject = new MutableJsonObject();
      
      jsonObject.addIfNotNull(CanonRuntime.JSON_TYPE, SequenceHashesEntity.TYPE_ID);
      jsonObject.addIfNotNull(CanonRuntime.JSON_VERSION, SequenceHashesEntity.TYPE_VERSION);

      getJsonObject(jsonObject);
  
      return jsonObject.immutify();
    }
    
    @Override 
    public void getJsonObject(MutableJsonObject jsonObject)
    {
      super.getJsonObject(jsonObject);
  
      if(getAbsolute() != null)
      {
          MutableJsonList  valueList = new MutableJsonList();

          for(Hash value : getAbsolute())
          {
            valueList.add(Hash.toImmutableByteArray(value));
          }
          jsonObject.add("absolute", valueList);
      }
  
      if(getCurrent() != null)
      {
          MutableJsonList  valueList = new MutableJsonList();

          for(Hash value : getCurrent())
          {
            valueList.add(Hash.toImmutableByteArray(value));
          }
          jsonObject.add("current", valueList);
      }
  
      if(getHashCurrent() != null)
      {
          MutableJsonList  valueList = new MutableJsonList();

          for(Hash value : getHashCurrent())
          {
            valueList.add(Hash.toImmutableByteArray(value));
          }
          jsonObject.add("hashCurrent", valueList);
      }
    }
        
    /**
     * Return the type id (_type JSON attribute) for this entity.
     * 
     * @return The type id for this entity.
     */
    @Override
    public String getCanonType()
    {
      return TYPE_ID;
    }
    
    /**
     * Return the type version (_version JSON attribute) for this entity.
     * 
     * @return The type version for this entity.
     */
    public String getCanonVersion()
    {
      return TYPE_VERSION;
    }
    
    /**
     * Return the major type version for entities created by this factory.
     * 
     * @return The major type version for entities created by this factory.
     */
    @Override
    public @Nullable Integer getCanonMajorVersion()
    {
      return TYPE_MAJOR_VERSION;
    }
    
    /**
     * Return the minjor type version for entities created by this factory.
     * 
     * @return The minor type version for entities created by this factory.
     */
    @Override
    public @Nullable Integer getCanonMinorVersion()
    {
      return TYPE_MINOR_VERSION;
    }
  }
}

/*----------------------------------------------------------------------------------------------------
 * End of template template/java/Object/_Entity.java.ftl
 * End of code generation
 *------------------------------------------------------------------------------------------------- */