From 04c88634335885e35fd64035eab2d532fe525392 Mon Sep 17 00:00:00 2001 From: junwon <67488973+wjdwnsdnjs13@users.noreply.github.com> Date: Sat, 3 Aug 2024 21:31:43 +0900 Subject: [PATCH] [NO_JIRA] immutable map fix (#104) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor : 레벨업 조건 알고리즘 수정 * build : 사용되지 않는 구아바 의존성 제거 * refactor : Map을 사용해서 ImmutableMap 구현하도록 변경 --- domain/build.gradle.kts | 3 -- .../depromeet/spot/domain/member/Level.java | 53 +++++++++---------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index a1f81ae0..a4997d22 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -1,8 +1,5 @@ dependencies { implementation(project(":common")) - - // ImmutableMap을 위한 구아바 사용 - implementation("com.google.guava:guava:31.0.1-jre") } tasks.jar { enabled = true } diff --git a/domain/src/main/java/org/depromeet/spot/domain/member/Level.java b/domain/src/main/java/org/depromeet/spot/domain/member/Level.java index 8a8620f8..cb19a3de 100644 --- a/domain/src/main/java/org/depromeet/spot/domain/member/Level.java +++ b/domain/src/main/java/org/depromeet/spot/domain/member/Level.java @@ -1,8 +1,7 @@ package org.depromeet.spot.domain.member; import java.time.LocalDateTime; - -import com.google.common.collect.ImmutableMap; +import java.util.Map; import lombok.AllArgsConstructor; import lombok.Getter; @@ -11,26 +10,26 @@ @AllArgsConstructor public class Level { - private static final ImmutableMap LEVEL_MINIMUM_CONDITIONS = - ImmutableMap.builder() - .put(0, 0) - .put(1, 1) - .put(2, 3) - .put(3, 5) - .put(4, 8) - .put(5, 14) - .put(6, 21) - .build(); + // of는 오버로딩으로 파라미터 수에 따라 사용됨. 10개 이상은 오버로딩 없어서 오류가 발생하니 주의! + private static final Map LEVEL_MINIMUM_CONDITIONS = + Map.of( + 0, 0, + 1, 1, + 2, 3, + 3, 5, + 4, 8, + 5, 14, + 6, 21); + + private static final Map LEVEL_MAXIMUM_CONDITIONS = + Map.of( + 0, 0, + 1, 2, + 2, 4, + 3, 7, + 4, 13, + 5, 20); - private static final ImmutableMap LEVEL_MAXIMUM_CONDITIONS = - ImmutableMap.builder() - .put(0, 0) - .put(1, 2) - .put(2, 4) - .put(3, 7) - .put(4, 13) - .put(5, 20) - .build(); private final Long id; private final int value; private final String title; @@ -40,17 +39,17 @@ public class Level { private final LocalDateTime deletedAt; public static int calculateLevel(final long reviewCnt) { - if (reviewCnt > LEVEL_MINIMUM_CONDITIONS.get(6)) { + if (reviewCnt >= LEVEL_MINIMUM_CONDITIONS.get(6)) { return 6; - } else if (reviewCnt > LEVEL_MAXIMUM_CONDITIONS.get(5)) { + } else if (reviewCnt >= LEVEL_MINIMUM_CONDITIONS.get(5)) { return 5; - } else if (reviewCnt > LEVEL_MAXIMUM_CONDITIONS.get(4)) { + } else if (reviewCnt >= LEVEL_MINIMUM_CONDITIONS.get(4)) { return 4; - } else if (reviewCnt > LEVEL_MAXIMUM_CONDITIONS.get(3)) { + } else if (reviewCnt >= LEVEL_MINIMUM_CONDITIONS.get(3)) { return 3; - } else if (reviewCnt > LEVEL_MAXIMUM_CONDITIONS.get(2)) { + } else if (reviewCnt >= LEVEL_MINIMUM_CONDITIONS.get(2)) { return 2; - } else if (reviewCnt > LEVEL_MAXIMUM_CONDITIONS.get(1)) { + } else if (reviewCnt >= LEVEL_MINIMUM_CONDITIONS.get(1)) { return 1; } return 0;