Last change
on this file since 13568 was 9078, checked in by Don-vip, 8 years ago |
sonar - Immutable Field
|
-
Property svn:eol-style
set to
native
|
File size:
847 bytes
|
Rev | Line | |
---|
[7937] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.tools;
|
---|
| 3 |
|
---|
| 4 | import java.util.AbstractList;
|
---|
| 5 | import java.util.List;
|
---|
| 6 |
|
---|
| 7 | /**
|
---|
| 8 | * Joined List build from two Lists (read-only).
|
---|
| 9 | *
|
---|
| 10 | * Extremely simple single-purpose implementation.
|
---|
[8470] | 11 | * @param <T> item type
|
---|
[7937] | 12 | * @since 7109
|
---|
| 13 | */
|
---|
| 14 | public class CompositeList<T> extends AbstractList<T> {
|
---|
[9078] | 15 | private final List<? extends T> a, b;
|
---|
[7937] | 16 |
|
---|
| 17 | /**
|
---|
| 18 | * Constructs a new {@code CompositeList} from two lists.
|
---|
| 19 | * @param a First list
|
---|
| 20 | * @param b Second list
|
---|
| 21 | */
|
---|
| 22 | public CompositeList(List<? extends T> a, List<? extends T> b) {
|
---|
| 23 | this.a = a;
|
---|
| 24 | this.b = b;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | @Override
|
---|
| 28 | public T get(int index) {
|
---|
| 29 | return index < a.size() ? a.get(index) : b.get(index - a.size());
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | @Override
|
---|
| 33 | public int size() {
|
---|
| 34 | return a.size() + b.size();
|
---|
| 35 | }
|
---|
[8290] | 36 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.