Package com.cedarsoft.business.calc

Source Code of com.cedarsoft.business.calc.Rent

package com.cedarsoft.business.calc;

import com.cedarsoft.business.Money;
import com.cedarsoft.business.MutableMoney;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.joda.time.LocalDate;
import org.joda.time.Period;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Represents the rent information about an amount
*/
public class Rent {
  @NonNls
  public static final String PROPERTY_UNTIL = "until";
  @NonNls
  public static final String PROPERTY_VALUE_DATE = "valueDate";
  @NonNls
  public static final String PROPERTY_INTEREST = "interest";
  @NonNls
  public static final String PROPERTY_SUM = "sum";
  @NonNls
  public static final String PROPERTY_DURATION = "duration";
  @NonNls
  public static final String PROPERTY_AMOUNT = "amount";
  @NonNls
  public static final String PROPERTY_INTEREST_DETAILS = "interestDetails";
  @NotNull
  protected final List<? extends InterestDetails> interestDetails;

  @NotNull
  protected final Money amount;
  @NotNull
  protected final Money interest;
  @NotNull
  protected final LocalDate until;
  @NotNull
  protected final LocalDate valueDate;

  /**
   * Creates a new rent information
   *
   * @param amount          the amount
   * @param valueDate       the value date of the amount
   * @param until           the date the interest is calculated until
   * @param interestDetails the interest details
   */
  public Rent( @NotNull Money amount, @NotNull LocalDate valueDate, @NotNull LocalDate until, @NotNull List<? extends InterestDetails> interestDetails ) {
    this.amount = amount;
    this.until = until;
    this.valueDate = valueDate;
    this.interestDetails = new ArrayList<InterestDetails>( interestDetails );

    //Sum up
    MutableMoney interestSummer = new MutableMoney();
    for ( InterestDetails interestDetail : interestDetails ) {
      interestSummer.plus( interestDetail.getInterest() );
    }
    this.interest = interestSummer.immutable();
  }

  @NotNull
  public Period getDuration() {
    return new Period( valueDate, until );
  }

  @NotNull
  public Money getAmount() {
    return amount;
  }

  @NotNull
  public Money getSum() {
    return amount.plus( interest );
  }

  @NotNull
  public LocalDate getUntil() {
    return until;
  }

  @NotNull
  public List<? extends InterestDetails> getInterestDetails() {
    return Collections.unmodifiableList( interestDetails );
  }

  @NotNull
  public LocalDate getValueDate() {
    return valueDate;
  }

  @NotNull
  public Money getInterest() {
    return interest;
  }


  @Override
  public String toString() {
    return "Rent{" +
        "amount=" + amount +
        ", interest=" + interest +
        ", until=" + until +
        ", valueDate=" + valueDate +
        '}';
  }
}
TOP

Related Classes of com.cedarsoft.business.calc.Rent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.