Record Class Operation

java.lang.Object
java.lang.Record
me.thiagorigonatti.capitalgains.core.Operation
Record Components:
operation - the type of operation, such as "buy" or "sell"
unitCost - the cost per unit of the asset
quantity - the number of units involved in the operation
ticker - the ticker symbol of the asset involved in the operation

public record Operation(String operation, BigDecimal unitCost, long quantity, String ticker) extends Record
Represents a single financial operation involving buying or selling assets.

This record is used to model input data for capital gains calculation. Each operation includes:

  • The type of operation (e.g., "buy" or "sell")
  • The unit cost of the asset
  • The quantity involved in the operation
  • The ticker symbol of the asset involved in the operation

The ticker field is now considered in the tax calculation logic to ensure operations are grouped and processed separately by their respective tickers, allowing for accurate tax calculations per asset.

This class is intended to be deserialized from JSON input using Jackson.

Since:
1.0
  • Constructor Details

    • Operation

      public Operation(String operation, BigDecimal unitCost, long quantity, String ticker)
      Creates an instance of a Operation record class.
      Parameters:
      operation - the value for the operation record component
      unitCost - the value for the unitCost record component
      quantity - the value for the quantity record component
      ticker - the value for the ticker record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • operation

      public String operation()
      Returns the value of the operation record component.
      Returns:
      the value of the operation record component
    • unitCost

      public BigDecimal unitCost()
      Returns the value of the unitCost record component.
      Returns:
      the value of the unitCost record component
    • quantity

      public long quantity()
      Returns the value of the quantity record component.
      Returns:
      the value of the quantity record component
    • ticker

      public String ticker()
      Returns the value of the ticker record component.
      Returns:
      the value of the ticker record component