~ indentation or something

Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
Johannes Theiner 2019-10-10 10:03:00 +02:00
parent 2fb72180f9
commit 442ffc16bb
1 changed files with 93 additions and 93 deletions

View File

@ -5,116 +5,116 @@ import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
public class RingList<E> implements List<E> {
private class Wrapper {
E e;
Wrapper succ;
private class Wrapper {
E e;
Wrapper succ;
Wrapper(E e) {
this.e = e;
succ = null;
}
}
Wrapper(E e) {
this.e = e;
succ = null;
}
}
private Wrapper first;
private Wrapper last;
private int size;
private Wrapper first;
private Wrapper last;
private int size;
public RingList() {
first = new Wrapper(null);
last = first;
last.succ = first;
size = 0;
}
public RingList() {
first = new Wrapper(null);
last = first;
last.succ = first;
size = 0;
}
public boolean add(E e) {
Wrapper w = new Wrapper(e);
last.succ = w;
last = w;
last.succ = first;
size++;
return true;
}
public boolean add(E e) {
Wrapper w = new Wrapper(e);
last.succ = w;
last = w;
last.succ = first;
size++;
return true;
}
private Wrapper getWrapper(int index) {
if(index == -1) return first;
Wrapper wRun;
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException();
}
wRun = this.first.succ;
for (int iRun = 0; iRun < index; iRun++) {
wRun = wRun.succ;
}
return wRun;
}
private Wrapper getWrapper(int index) {
if (index == -1) return first;
Wrapper wRun;
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException();
}
wRun = this.first.succ;
for (int iRun = 0; iRun < index; iRun++) {
wRun = wRun.succ;
}
return wRun;
}
public E get(int index) {
return getWrapper(index).e;
}
public E get(int index) {
return getWrapper(index).e;
}
public int size() {
return size;
}
public int size() {
return size;
}
@Override
public E remove(int index) {
Wrapper wrapper = getWrapper(index - 1);
E result = wrapper.succ.e;
wrapper.succ = wrapper.succ.succ;
size--;
@Override
public E remove(int index) {
Wrapper wrapper = getWrapper(index - 1);
E result = wrapper.succ.e;
wrapper.succ = wrapper.succ.succ;
size--;
return result;
}
return result;
}
@Override
public boolean remove(Object o) {
try {
int index = indexOf((E) o);
if(index == -1) return false;
@Override
public boolean remove(Object o) {
try {
int index = indexOf((E) o);
if (index == -1) return false;
remove(index);
return true;
} catch (ClassCastException ex) {
ex.printStackTrace();
}
remove(index);
return true;
} catch (ClassCastException ex) {
ex.printStackTrace();
}
return false;
}
return false;
}
@Override
public int indexOf(E e) {
Wrapper wrapper = this.first.succ;
for (int i = 0; i < size; i++) {
if(wrapper.e.equals(e)) {
return i;
}else wrapper = wrapper.succ;
}
return -1;
}
@Override
public int indexOf(E e) {
Wrapper wrapper = this.first.succ;
for (int i = 0; i < size; i++) {
if (wrapper.e.equals(e)) {
return i;
} else wrapper = wrapper.succ;
}
return -1;
}
@NotNull
public Iterator<E> iterator() {
return new Iterator<E>() {
Wrapper next = first.succ;
Wrapper current;
@NotNull
public Iterator<E> iterator() {
return new Iterator<E>() {
Wrapper next = first.succ;
Wrapper current;
public boolean hasNext() {
return next != first;
}
public boolean hasNext() {
return next != first;
}
public E next() {
current = next;
if (next != first) {
next = next.succ;
}
return current.e;
}
public E next() {
current = next;
if (next != first) {
next = next.succ;
}
return current.e;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}