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

org.sackfix.fix50sp2modified.AllocsGroup.scala Maven / Gradle / Ivy

The newest version!
package org.sackfix.fix50sp2modified

import org.sackfix.field._
import org.sackfix.common.validated.fields.{SfFixGroup, SfGroupDecoder, SfFixFieldsToAscii, SfFixRenderable}
import org.sackfix.common.message.SfRepeatingGroupCountException
import scala.annotation.tailrec
import scala.collection.immutable.HashSet
import scala.collection.mutable.ArrayBuffer


/**
  * Generated by SackFix code generator on 20170404
  * Source specification was read from:
  *   /quickfixj1.6.0/FIX50SP2.modified.xml
  */
case class AllocsGroup(allocAccountField:Option[AllocAccountField]=None,
                       allocAcctIDSourceField:Option[AllocAcctIDSourceField]=None,
                       allocSettlCurrencyField:Option[AllocSettlCurrencyField]=None,
                       individualAllocIDField:Option[IndividualAllocIDField]=None,
                       nestedParties2Component:Option[NestedParties2Component]=None,
                       allocQtyField:Option[AllocQtyField]=None,
                       allocCustomerCapacityField:Option[AllocCustomerCapacityField]=None,
                       allocMethodField:Option[AllocMethodField]=None,
                       secondaryIndividualAllocIDField:Option[SecondaryIndividualAllocIDField]=None,
                       allocClearingFeeIndicatorField:Option[AllocClearingFeeIndicatorField]=None) extends SfFixGroup  with SfFixRenderable with SfFixFieldsToAscii {

  override lazy val fixStr : String = appendFixStr().toString
  override def appendFixStr(b:StringBuilder = new StringBuilder): StringBuilder = format(formatForFix, b)

  override def toString():String = appendStringBuilder().toString()
  def appendStringBuilder(b:StringBuilder = new StringBuilder) : StringBuilder = format(formatForToString, b)

  def format( fmt: ((StringBuilder,SfFixRenderable)=>Unit), b:StringBuilder = new StringBuilder()): StringBuilder = {
    allocAccountField.foreach(fmt(b,_))
    allocAcctIDSourceField.foreach(fmt(b,_))
    allocSettlCurrencyField.foreach(fmt(b,_))
    individualAllocIDField.foreach(fmt(b,_))
    nestedParties2Component.foreach(fmt(b,_))
    allocQtyField.foreach(fmt(b,_))
    allocCustomerCapacityField.foreach(fmt(b,_))
    allocMethodField.foreach(fmt(b,_))
    secondaryIndividualAllocIDField.foreach(fmt(b,_))
    allocClearingFeeIndicatorField.foreach(fmt(b,_))
    b
  }

}
     
object AllocsGroup extends SfGroupDecoder {

  override val MandatoryFields = HashSet[Int]()

  override def isMandatoryField(tagId:Int) : Boolean = {
    MandatoryFields.contains(tagId)  || 
    NestedParties2Component.isMandatoryField(tagId)
  }

  override val OptionalFields = HashSet[Int](
    AllocAccountField.TagId, AllocAcctIDSourceField.TagId, AllocSettlCurrencyField.TagId, IndividualAllocIDField.TagId, AllocQtyField.TagId, 
    AllocCustomerCapacityField.TagId, AllocMethodField.TagId, SecondaryIndividualAllocIDField.TagId, AllocClearingFeeIndicatorField.TagId)

  override def isOptionalField(tagId:Int) : Boolean = {
    OptionalFields.contains(tagId)  || 
    NestedParties2Component.isOptionalField(tagId)
  }

  override def isFieldOf(tagId:Int) : Boolean = isMandatoryField(tagId) || isOptionalField(tagId)  || 
    NestedParties2Component.isFieldOf(tagId)

   override lazy val RepeatingGroupsTags = HashSet[Int]()
  
      
  override def isFirstField(tagId:Int) : Boolean = tagId==AllocAccountField.TagId 

  // Group version, startPos is the index to the first element of the first repeating group
  @tailrec
  def decode(flds: Seq[Tuple2[Int, Any]], startPos:Int = 0, groups:ArrayBuffer[AllocsGroup]=ArrayBuffer.empty[AllocsGroup]):Option[List[AllocsGroup]] = {
    decodeSingle(flds, startPos) match {
      case (pos: Int, None) => if (groups.nonEmpty) Some(groups.toList) else None
      case (pos: Int, grp: Some[AllocsGroup]) => decode(flds, pos, groups += grp.get)
    }
  }

  /**
    * @param flds For groups in Fix ordering is VITAL.
    * @param startPos This index into the ordered fields. It HAS to contain the first field of the group
    * @return A Tuple2 holding the next position to read from the fields, and the newly created group
    */
  def decodeSingle(flds: Seq[Tuple2[Int, Any]], startPos:Int):Tuple2[Int,Option[AllocsGroup]] = {
    if (!isFirstField(flds(startPos)._1)) (startPos, None)
    else {
      val (pos, myFields, nextTagPosLookup) = extractMyFieldsAndPopulatePositions(true, flds, startPos)
      validateMandatoryFieldsPresent(myFields)

      if (myFields.nonEmpty) {
        (pos,Some(AllocsGroup(myFields.get(AllocAccountField.TagId).flatMap(f=>AllocAccountField.decode(f)),
          myFields.get(AllocAcctIDSourceField.TagId).flatMap(f=>AllocAcctIDSourceField.decode(f)),
          myFields.get(AllocSettlCurrencyField.TagId).flatMap(f=>AllocSettlCurrencyField.decode(f)),
          myFields.get(IndividualAllocIDField.TagId).flatMap(f=>IndividualAllocIDField.decode(f)),
          NestedParties2Component.decode(flds, startPos),
          myFields.get(AllocQtyField.TagId).flatMap(f=>AllocQtyField.decode(f)),
          myFields.get(AllocCustomerCapacityField.TagId).flatMap(f=>AllocCustomerCapacityField.decode(f)),
          myFields.get(AllocMethodField.TagId).flatMap(f=>AllocMethodField.decode(f)),
          myFields.get(SecondaryIndividualAllocIDField.TagId).flatMap(f=>SecondaryIndividualAllocIDField.decode(f)),
          myFields.get(AllocClearingFeeIndicatorField.TagId).flatMap(f=>AllocClearingFeeIndicatorField.decode(f)))))
      } else (startPos, None)
    }
  }
    
}
     




© 2015 - 2025 Weber Informatics LLC | Privacy Policy