-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from Gamegoo-repo/refactor/161
[Refactor/161] ์๋ฆผ ๋ชฉ๋ก ์กฐํ, ์น๊ตฌ ๋ชฉ๋ก ์กฐํ API ์์
- Loading branch information
Showing
8 changed files
with
67 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.gamegoo.util; | ||
|
||
import java.util.Comparator; | ||
|
||
public class SortUtil { | ||
|
||
public static Comparator<String> memberNameComparator = (s1, s2) -> { | ||
int length1 = s1.length(); | ||
int length2 = s2.length(); | ||
int minLength = Math.min(length1, length2); | ||
|
||
// ๊ฐ ๋ฌธ์ ๋น๊ต | ||
for (int i = 0; i < minLength; i++) { | ||
int result = compareChars(s1.charAt(i), s2.charAt(i)); | ||
if (result != 0) { | ||
return result; | ||
} | ||
} | ||
|
||
// ์๋ถ๋ถ์ด ๋์ผํ๋ฉด, ๊ธธ์ด๊ฐ ์งง์ ๊ฒ์ด ์์ผ๋ก ์ค๋๋ก ์ ๋ ฌ | ||
return Integer.compare(length1, length2); | ||
}; | ||
|
||
// ๋ฌธ์ ๋น๊ต ๋ฉ์๋: ํ๊ธ -> ์๋ฌธ์ -> ์ซ์ ์์ผ๋ก ์ฐ์ ์์ ์ง์ | ||
private static int compareChars(char c1, char c2) { | ||
if (Character.isDigit(c1) && Character.isDigit(c2)) { | ||
return Character.compare(c1, c2); | ||
} else if (Character.isDigit(c1)) { | ||
return 1; // ์ซ์๋ ํญ์ ๋ค๋ก | ||
} else if (Character.isDigit(c2)) { | ||
return -1; // ์ซ์๋ ํญ์ ๋ค๋ก | ||
} else if (Character.isAlphabetic(c1) && Character.isAlphabetic(c2)) { | ||
return Character.compare(c1, c2); | ||
} else if (Character.isAlphabetic(c1)) { | ||
return 1; // ์๋ฌธ์๋ ํ๊ธ๋ณด๋ค ๋ค | ||
} else if (Character.isAlphabetic(c2)) { | ||
return -1; // ์๋ฌธ์๋ ํ๊ธ๋ณด๋ค ๋ค | ||
} else { | ||
return Character.compare(c1, c2); // ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๋์ฝ๋ ๊ฐ ๋น๊ต | ||
} | ||
} | ||
} |