Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5기 최정은] Shorten-URL 과제 제출합니다. #68

Open
wants to merge 15 commits into
base: JeongeunChoi
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.springboot.springbooturlshortner.util;

import org.springframework.stereotype.Component;

@Component
public class Base62Util {
Comment on lines +5 to +6

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 왜 Base64가 아닌 Base62를 선택했나요?
  • 유틸성 클래스가 꼭 스프링 빈으로 등록되어 관리되어야할까요?
  • Util성 클래스임에도 Base62로 인코딩/디코딩을 진행할때 long 값만 받을 수 있는 것 같아요. 관련해서 고민해봐주시면 좋을 것 같아요.
  • 여러개의 알고리즘을 지원해야한다면 어떻게 구현해볼 수 있을까요?


private final String BASE62_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
private final int BASE62_CHARS_SIZE = 62;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BASE62_CHARS_SIZE와 BASE62_CHARS.length()가 별도로 관리되고 있는 것으로 보이는데 하나로 관리하는 걸 고려해봐주세요.

  • 임의로 BASE62_CHARS가 변경되었을때 길이는 62로 고정되어있을 것 같아요.


public String encoding(long urlId) {
StringBuffer sb = new StringBuffer();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringBuilder, StringBuffer의 선택지가 있었을 것 같은데 StringBuffer를 사용한 이유는 뭔가요?

int charactersLength = BASE62_CHARS.length();
while (urlId > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urlId가 0이하인 값이 들어오면 어떻게 될까요?

sb.append(BASE62_CHARS.charAt((int) (urlId % charactersLength)));
urlId /= BASE62_CHARS_SIZE;
}
return sb.toString();
}

public long decoding(String uniqueKey) {
long urlId = 0, power = 1;
for (int i = 0; i < uniqueKey.length(); i++) {
urlId += BASE62_CHARS.indexOf(uniqueKey.charAt(i)) * power;
power *= BASE62_CHARS_SIZE;
}
return urlId;
}

}