- 
                Notifications
    You must be signed in to change notification settings 
- Fork 105
[5기 최정은] Shorten-URL 과제 제출합니다. #68
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
base: JeongeunChoi
Are you sure you want to change the base?
Changes from 1 commit
d7def34
              14f5576
              bb9a605
              37dc9c3
              06f74a8
              a59b5e4
              6cf971e
              be2d0e5
              4e624a2
              fee5af2
              2f35454
              bea61ca
              f510a9a
              c95d11f
              4f037a5
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { | ||
|  | ||
| private final String BASE62_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | ||
| private final int BASE62_CHARS_SIZE = 62; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BASE62_CHARS_SIZE와 BASE62_CHARS.length()가 별도로 관리되고 있는 것으로 보이는데 하나로 관리하는 걸 고려해봐주세요. 
 | ||
|  | ||
| public String encoding(long urlId) { | ||
| StringBuffer sb = new StringBuffer(); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StringBuilder, StringBuffer의 선택지가 있었을 것 같은데 StringBuffer를 사용한 이유는 뭔가요? | ||
| int charactersLength = BASE62_CHARS.length(); | ||
| while (urlId > 0) { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|  | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.