From c0a9da9a4f0444ecdc982d713ee0d679fb78502a Mon Sep 17 00:00:00 2001 From: Aleksey Kalenchukov Date: Fri, 5 Aug 2022 09:37:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20getLettersReverse()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphabet/AbstractAlphabet.java | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/main/java/dev/kalenchukov/alphabet/AbstractAlphabet.java b/src/main/java/dev/kalenchukov/alphabet/AbstractAlphabet.java index 20c313f..ed7bdfd 100644 --- a/src/main/java/dev/kalenchukov/alphabet/AbstractAlphabet.java +++ b/src/main/java/dev/kalenchukov/alphabet/AbstractAlphabet.java @@ -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 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); } /** @@ -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 alphabetReverse = new ArrayList<>(alphabet.size()); - - for (int i = alphabet.size() - 1; i >= 0; i--) { - alphabetReverse.add(alphabet.get(i)); - } - - return alphabetReverse; - } }