Skip to content

Commit

Permalink
[NO_JIRA] immutable map fix (#104)
Browse files Browse the repository at this point in the history
* refactor : 레벨업 조건 알고리즘 수정

* build : 사용되지 않는 구아바 의존성 제거

* refactor : Map을 사용해서 ImmutableMap 구현하도록 변경
  • Loading branch information
wjdwnsdnjs13 authored Aug 3, 2024
1 parent 01787da commit 04c8863
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
3 changes: 0 additions & 3 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
dependencies {
implementation(project(":common"))

// ImmutableMap을 위한 구아바 사용
implementation("com.google.guava:guava:31.0.1-jre")
}

tasks.jar { enabled = true }
Expand Down
53 changes: 26 additions & 27 deletions domain/src/main/java/org/depromeet/spot/domain/member/Level.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,26 +10,26 @@
@AllArgsConstructor
public class Level {

private static final ImmutableMap<Integer, Integer> LEVEL_MINIMUM_CONDITIONS =
ImmutableMap.<Integer, Integer>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<Integer, Integer> LEVEL_MINIMUM_CONDITIONS =
Map.of(
0, 0,
1, 1,
2, 3,
3, 5,
4, 8,
5, 14,
6, 21);

private static final Map<Integer, Integer> LEVEL_MAXIMUM_CONDITIONS =
Map.of(
0, 0,
1, 2,
2, 4,
3, 7,
4, 13,
5, 20);

private static final ImmutableMap<Integer, Integer> LEVEL_MAXIMUM_CONDITIONS =
ImmutableMap.<Integer, Integer>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;
Expand All @@ -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;
Expand Down

0 comments on commit 04c8863

Please sign in to comment.