com.creditcloud.interestbearing.model.InterestBearingUserFundChange.java Source code

Java tutorial

Introduction

Here is the source code for com.creditcloud.interestbearing.model.InterestBearingUserFundChange.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.creditcloud.interestbearing.model;

import com.creditcloud.interestbearing.enums.InterestBearingUserFundChangeDirection;
import com.creditcloud.interestbearing.enums.InterestBearingUserFundChangeType;
import java.math.BigDecimal;
import java.util.Date;
import javax.validation.constraints.NotNull;
import lombok.Data;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * ???
 *
 * @author guohuazhang
 */
@Data
public class InterestBearingUserFundChange {

    /**
     * ???
     */
    private InterestBearingUserFundChangeType type;
    // ???ID
    @NotNull
    private String userId;
    // ?
    @NotNull
    private Date registrationTime;

    // ??
    @NotNull
    private BigDecimal changeAmount;

    public InterestBearingUserFundChangeDirection getChangeDirection() {
        if (changeAmount == null) {
            return InterestBearingUserFundChangeDirection.NO_CHANGE;
        }

        if (changeAmount.equals(BigDecimal.ZERO)) {
            return InterestBearingUserFundChangeDirection.NO_CHANGE;
        }

        InterestBearingUserFundChangeDirection direction = (changeAmount.compareTo(BigDecimal.ZERO) > 0)
                ? InterestBearingUserFundChangeDirection.INCREASED
                : InterestBearingUserFundChangeDirection.DECREASED;
        return direction;
    }

    public BigDecimal getAbsoluteChangeAmount() {
        if (changeAmount == null) {
            return BigDecimal.ZERO;
        }

        return changeAmount.abs();
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE, false, false);
    }
}