feat: binding custom linked list to Java's default List interface

This commit is contained in:
Václav Přibík
2025-10-18 15:10:39 +02:00
parent d29d8b156e
commit e6a56444db

View File

@@ -0,0 +1,157 @@
package appointmentplanner.customlist;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import appointmentplanner.customlist.api.*;
public class CustomListToJavaBinding<T> implements List<T> {
private CustomLinkedList<T> list;
public CustomListToJavaBinding(CustomLinkedList<T> list) {
this.list = list;
}
@Override
public boolean add(T arg0) {
list.add(arg0);
return true;
}
@Override
public void add(int arg0, T arg1) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Cannot add to exact index in linked list");
}
@Override
public boolean addAll(Collection<? extends T> c) {
c.stream().forEach(list::add);
return true;
}
@Override
public boolean addAll(int index, Collection<? extends T> c) {
throw new UnsupportedOperationException("Cannot add to exact index in linked list");
}
@Override
public void clear() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'clear'");
}
@Override
public boolean containsAll(Collection<?> c) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'containsAll'");
}
@Override
public T get(int index) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'get'");
}
@Override
public int indexOf(Object o) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'indexOf'");
}
@Override
public boolean isEmpty() {
return list.size() == 0;
}
@Override
public Iterator<T> iterator() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'iterator'");
}
@Override
public int lastIndexOf(Object o) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'lastIndexOf'");
}
@Override
public ListIterator<T> listIterator() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'listIterator'");
}
@Override
public ListIterator<T> listIterator(int index) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'listIterator'");
}
@Override
public boolean remove(Object o) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'remove'");
}
@Override
public T remove(int index) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'remove'");
}
@Override
public boolean removeAll(Collection<?> c) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'removeAll'");
}
@Override
public boolean retainAll(Collection<?> c) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'retainAll'");
}
@Override
public T set(int arg0, T arg1) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'set'");
}
@Override
public int size() {
return list.size();
}
@Override
public List<T> subList(int fromIndex, int toIndex) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'subList'");
}
@Override
public Object[] toArray() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'toArray'");
}
@Override
public <T> T[] toArray(T[] arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'toArray'");
}
@Override
public boolean contains(Object o) {
try {
T bal = (T) o;
return list.contains(bal);
} catch (Exception e) {
return false;
}
}
}