Skip to content

Commit

Permalink
Изменён метод getLettersReverse()
Browse files Browse the repository at this point in the history
  • Loading branch information
kalenchukov committed Aug 5, 2022
1 parent 5f6d487 commit c0a9da9
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/main/java/dev/kalenchukov/alphabet/AbstractAlphabet.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ protected Integer getPosition(@NotNull final List<@NotNull Character> alphabet,
@Override
public List<@NotNull Character> getLettersReverse()
{
return Collections.unmodifiableList(this.getLettersReverse(this.letters));
List<Character> alphabetReverse = new ArrayList<>(this.letters.size());

for (int i = this.letters.size() - 1; i >= 0; i--) {
alphabetReverse.add(this.letters.get(i));
}

return Collections.unmodifiableList(alphabetReverse);
}

/**
Expand Down Expand Up @@ -190,22 +196,4 @@ protected Integer getPosition(@NotNull final List<@NotNull Character> alphabet,

return Collections.unmodifiableList(letters);
}

/**
* Возвращает буквы алфавита в обратном порядке.
*
* @param alphabet Алфавит.
* @return Коллекция букв алфавита.
*/
@NotNull
protected List<@NotNull Character> getLettersReverse(@NotNull final List<@NotNull Character> alphabet)
{
List<Character> alphabetReverse = new ArrayList<>(alphabet.size());

for (int i = alphabet.size() - 1; i >= 0; i--) {
alphabetReverse.add(alphabet.get(i));
}

return alphabetReverse;
}
}

0 comments on commit c0a9da9

Please sign in to comment.