001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.tools; 003 004import java.util.AbstractList; 005import java.util.List; 006 007/** 008 * Joined List build from two Lists (read-only). 009 * 010 * Extremely simple single-purpose implementation. 011 * @param <T> item type 012 * @since 7109 013 */ 014public class CompositeList<T> extends AbstractList<T> { 015 private final List<? extends T> a, b; 016 017 /** 018 * Constructs a new {@code CompositeList} from two lists. 019 * @param a First list 020 * @param b Second list 021 */ 022 public CompositeList(List<? extends T> a, List<? extends T> b) { 023 this.a = a; 024 this.b = b; 025 } 026 027 @Override 028 public T get(int index) { 029 return index < a.size() ? a.get(index) : b.get(index - a.size()); 030 } 031 032 @Override 033 public int size() { 034 return a.size() + b.size(); 035 } 036}