From e851403482ead11f47bba95660ee086a06045867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 28 Aug 2020 14:49:46 +0200 Subject: [PATCH] Fix compilation --- .../net/sourceforge/pmd/util/ConsList.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/util/ConsList.java diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/ConsList.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/ConsList.java new file mode 100644 index 0000000000..3c3a40f4e0 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/ConsList.java @@ -0,0 +1,45 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.util; + +import java.util.AbstractList; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.lang3.Validate; + +import net.sourceforge.pmd.internal.util.IteratorUtil; + +final class ConsList extends AbstractList { + + private final List head; + private final List tail; + private final int size; + + ConsList(List head, List tail) { + this.head = head; + this.tail = tail; + this.size = head.size() + tail.size(); + } + + @Override + public T get(int index) { + Validate.validIndex(this, index); + if (index < head.size()) { + return head.get(index); + } + return tail.get(index - head.size()); + } + + @Override + public Iterator iterator() { + return IteratorUtil.concat(head.iterator(), tail.iterator()); + } + + @Override + public int size() { + return size; + } +}