Skip to content

Commit

Permalink
[style] 코드 정리 (#452)
Browse files Browse the repository at this point in the history
* feat: Portfolio의 LocalDate 모킹

* feat: StockDividend 필드에 isDeleted 컬럼 추가

* feat: DividendDates 임베디드 클래스 추가

* feat: StockDividendParser 추가

* feat: 생성자 압축

* refactor: 객체지향적으로 변경

* refactor: Stock 필드에 LocalDateTimeService 추가

* refactor: StockParser 추가 및 분리

* style: 코드 정리

* fix: HashTable 변경

* style: equals 재정의

* refactor: 불필요한 메서드 인수 제거

* Refactor: file.delete 개선

* style: 코드 정리

* style: sonarLint에 따른 코드 정리

* fix: 테스트 실패 해결

* style:: 코드 정리

* test: 테스트 해결

* style: 코드 정리

* [feat] �배당금 엔티티에 필드 추가 및 포트폴리오 필드 추가 (#451)

* feat: Portfolio의 LocalDate 모킹

* feat: StockDividend 필드에 isDeleted 컬럼 추가
  • Loading branch information
yonghwankim-dev authored Aug 30, 2024
1 parent 4ff3f23 commit 6e06a15
Show file tree
Hide file tree
Showing 113 changed files with 816 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean isZero() {
public Expression division(Money numerator) {
return numerator.divide(value);
}

@Override
public boolean equals(Object object) {
if (this == object) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package codesquad.fineants.domain.common.money;

import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public final class Bank {

private static Bank instance;
private final Hashtable<Pair, Double> rates = new Hashtable<>();
private final Map<Pair, Double> rates = new ConcurrentHashMap<>();

Bank() {
}
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/codesquad/fineants/domain/common/money/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Money won(long amount) {
}

public static Money won(double amount) {
return won(new BigDecimal(amount));
return won(BigDecimal.valueOf(amount));
}

public static Money zero() {
Expand All @@ -70,7 +70,7 @@ public static Expression wonZero() {
@Override
public Money reduce(Bank bank, Currency to) {
double rate = bank.rate(currency, to);
return new Money(amount.divide(new BigDecimal(rate), 4, RoundingMode.HALF_UP), to);
return new Money(amount.divide(BigDecimal.valueOf(rate), 4, RoundingMode.HALF_UP), to);
}

@Override
Expand Down Expand Up @@ -155,14 +155,7 @@ public int compareTo(@NotNull Expression expression) {
Money m2 = bank.reduce(expression, currency);
return m1.amount.compareTo(m2.amount);
}

public int compareTo(Money money) {
if (this.currency.equals(money.currency)) {
return this.amount.compareTo(money.amount);
}
throw new IllegalArgumentException("Not match currency");
}


@Override
public boolean equals(Object object) {
if (this == object) {
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/codesquad/fineants/domain/common/money/Pair.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package codesquad.fineants.domain.common.money;

import java.util.Objects;

public class Pair {
private final Currency from;
private final Currency to;
Expand All @@ -11,12 +13,18 @@ public Pair(Currency from, Currency to) {

@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null || getClass() != object.getClass()) {
return false;
}
Pair pair = (Pair)object;
return from.equals(pair.from) && to.equals(pair.to);
return from == pair.from && to == pair.to;
}

@Override
public int hashCode() {
return 0;
return Objects.hash(from, to);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Percentage zero() {
}

public static Percentage from(double value) {
return from(new BigDecimal(value));
return from(BigDecimal.valueOf(value));
}

public static Percentage from(BigDecimal value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package codesquad.fineants.domain.dividend.domain.entity;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import org.apache.logging.log4j.util.Strings;

import codesquad.fineants.domain.dividend.domain.calculator.ExDividendDateCalculator;
import codesquad.fineants.domain.dividend.domain.reader.HolidayFileReader;
import codesquad.fineants.domain.kis.repository.HolidayRepository;
import codesquad.fineants.domain.purchasehistory.domain.entity.PurchaseHistory;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Embeddable
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode(of = "recordDate")
public class DividendDates {
@Column(name = "record_date", nullable = false)
private LocalDate recordDate;
@Column(name = "ex_dividend_date", nullable = false)
private LocalDate exDividendDate;
@Column(name = "payment_date")
private LocalDate paymentDate;

private static final ExDividendDateCalculator EX_DIVIDEND_DATE_CALCULATOR = new ExDividendDateCalculator(
new HolidayRepository(new HolidayFileReader()));

public static DividendDates withRecordDateOnly(LocalDate recordDate) {
LocalDate exDividendDate = EX_DIVIDEND_DATE_CALCULATOR.calculate(recordDate);
return new DividendDates(recordDate, exDividendDate, null);
}

public static DividendDates withPaymentDate(LocalDate recordDate, LocalDate paymentDate) {
LocalDate exDividendDate = EX_DIVIDEND_DATE_CALCULATOR.calculate(recordDate);
return new DividendDates(recordDate, exDividendDate, paymentDate);
}

public static DividendDates of(LocalDate recordDate, LocalDate exDividendDate, LocalDate paymentDate) {
return new DividendDates(recordDate, exDividendDate, paymentDate);
}

public boolean canReceiveDividendOn(LocalDate purchaseDate) {
if (paymentDate == null) {
return false;
}
return purchaseDate.isBefore(exDividendDate);
}

public Integer getPaymentDateMonth() {
return paymentDate.getMonthValue();
}

public boolean isCurrentYearRecordDate(LocalDate localDate) {
return localDate.getYear() == recordDate.getYear();
}

public boolean isLastYearPaymentDate(LocalDate lastYearLocalDate) {
if (paymentDate == null) {
return false;
}
return lastYearLocalDate.getYear() == paymentDate.getYear();
}

public Integer getQuarterWithRecordDate() {
return recordDate.getMonthValue() / 4 + 1;
}

public boolean isCurrentYearPaymentDate(LocalDate today) {
if (paymentDate == null) {
return false;
}
return today.getYear() == paymentDate.getYear();
}

public boolean equalRecordDate(LocalDate recordDate) {
return this.recordDate.equals(recordDate);
}

public boolean hasPaymentDate() {
return paymentDate != null;
}

public String parse() {
return String.format("%s:%s:%s", recordDate, exDividendDate, paymentDate);
}

public boolean isPaymentInCurrentYear(LocalDate localDate) {
if (paymentDate == null) {
return false;
}
return localDate.getYear() == paymentDate.getYear();
}

public boolean hasInRangeForRecordDate(LocalDate from, LocalDate to) {
return recordDate.isAfter(from) && recordDate.isBefore(to);
}

public boolean equalPaymentDate(LocalDate paymentDate) {
if (this.paymentDate == null) {
return false;
}
return this.paymentDate.equals(paymentDate);
}

public String basicIsoForRecordDate() {
return basicIso(recordDate);
}

public String basicIsoForPaymentDate() {
return basicIso(paymentDate);
}

private String basicIso(LocalDate localDate) {
if (localDate == null) {
return Strings.EMPTY;
}
return localDate.format(DateTimeFormatter.BASIC_ISO_DATE);
}

public boolean isSatisfiedBy(PurchaseHistory history) {
return history.isSatisfiedDividend(exDividendDate);
}

public boolean isPurchaseDateBeforeExDividendDate(PurchaseHistory history) {
return history.isPurchaseDateBeforeExDividendDate(exDividendDate.atStartOfDay());
}
}
Loading

0 comments on commit 6e06a15

Please sign in to comment.