From a96c15cbaacd79c9c0c66bc0dd85f71f168633f6 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sat, 2 Sep 2023 15:55:51 +0200 Subject: [PATCH] Added new class CollectionUtils and new method reverseList --- .../collections/CollectionUtils.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 power-collections/src/main/java/org/nanoboot/powerframework/collections/CollectionUtils.java diff --git a/power-collections/src/main/java/org/nanoboot/powerframework/collections/CollectionUtils.java b/power-collections/src/main/java/org/nanoboot/powerframework/collections/CollectionUtils.java new file mode 100644 index 0000000..123f93d --- /dev/null +++ b/power-collections/src/main/java/org/nanoboot/powerframework/collections/CollectionUtils.java @@ -0,0 +1,49 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// power-framework: Java library with many purposes of usage. +// Copyright (C) 2016-2022 the original author or authors. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; +// version 2.1 of the License only. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +/////////////////////////////////////////////////////////////////////////////////////////////// +package org.nanoboot.powerframework.collections; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; + +/** + * + * + * @author Robert Vokac + * @since 2.0.0 + */ +public class CollectionUtils { + + private CollectionUtils() { + //Not meant to be instantiated. + } + + public static List reverseList(List list) { + + List reversedList = new ArrayList<>(); + ListIterator listIterator + = list.listIterator(list.size()); + while (listIterator.hasPrevious()) { + T t = listIterator.previous(); + reversedList.add(t); + } + return reversedList; + + } +}