
lt.compiler.util.BindList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of latte-compiler Show documentation
Show all versions of latte-compiler Show documentation
The latte-lang compiler project, which contains compiler and runtime required library.
The newest version!
package lt.compiler.util;
import java.util.AbstractList;
import java.util.List;
/**
* bind 2 lists into one
*/
public class BindList extends AbstractList {
private final List list1;
private final List list2;
public BindList(List list1, List list2) {
this.list1 = list1;
this.list2 = list2;
}
@Override
public E get(int index) {
if (index < 0 || index >= list1.size() + list2.size())
throw new IndexOutOfBoundsException(String.valueOf(index));
if (index < list1.size()) return list1.get(index);
index -= list1.size();
return list2.get(index);
}
@Override
public E set(int index, E element) {
if (index < 0 || index >= list1.size() + list2.size())
throw new IndexOutOfBoundsException(String.valueOf(index));
if (index < list1.size()) return list1.set(index, element);
index -= list1.size();
return list2.set(index, element);
}
@Override
public int size() {
return list1.size() + list2.size();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy