Skip to content

Commit

Permalink
refactor: 분기문 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyma-s committed Nov 4, 2023
1 parent 6121790 commit 0c55d25
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions backend/src/main/java/shook/shook/song/domain/InMemorySongs.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,8 @@ private void reorder(final Song updatedSong) {
return;
}

if (shouldMoveForward(updatedSong, currentSongIndex)) {
moveForward(updatedSong, currentSongIndex);
}

if (shouldMoveBackward(updatedSong, currentSongIndex)) {
moveBackward(updatedSong, currentSongIndex);
}
}

private boolean shouldMoveForward(final Song song, final int index) {
if (index <= 0) {
return false;
}

final Long prevSongId = sortedSongIds.get(index - 1);
final Song prevSong = songs.get(prevSongId);

return shouldSwapWithPrevious(song, prevSong);
}

private boolean shouldMoveBackward(final Song song, final int index) {
if (index >= sortedSongIds.size() - 1) {
return false;
}

final Long nextSongId = sortedSongIds.get(index + 1);
final Song nextSong = songs.get(nextSongId);

return shouldSwapWithNext(song, nextSong);
moveForward(updatedSong, currentSongIndex);
moveBackward(updatedSong, currentSongIndex);
}

private void moveForward(final Song changedSong, final int songIndex) {
Expand Down

0 comments on commit 0c55d25

Please sign in to comment.