public ConsPStack<E> plus(final E e) { return new ConsPStack<E>(e, this); }
public ConsPStack<E> plus(final E e) { return new ConsPStack<E>(e, this); }
public ConsPStack<E> with(final int i, final E e) { if(i<0 || i>=size) throw new IndexOutOfBoundsException(); if(i==0) { if(first.equals(e)) return this; return new ConsPStack<E>(e, rest); } ConsPStack<E> newRest = rest.with(i-1, e); if(newRest==rest) return this; return new ConsPStack<E>(first, newRest); }
public ConsPStack<E> with(final int i, final E e) { if(i<0 || i>=size) throw new IndexOutOfBoundsException(); if(i==0) { if(first.equals(e)) return this; return new ConsPStack<E>(e, rest); } ConsPStack<E> newRest = rest.with(i-1, e); if(newRest==rest) return this; return new ConsPStack<E>(first, newRest); }
public ConsPStack<E> minus(final int i) { if (i < 0 || i >= size) throw new IndexOutOfBoundsException("Index: " + i + "; size: " + size); else if (i == 0) return rest; else return new ConsPStack<E>(first, rest.minus(i-1)); }
public ConsPStack<E> minus(final Object e) { if(size==0) return this; if(first.equals(e)) // found it return rest; // don't recurse (only remove one) // otherwise keep looking: ConsPStack<E> newRest = rest.minus(e); if(newRest==rest) return this; return new ConsPStack<E>(first, newRest); }
public ConsPStack<E> minus(final int i) { if (i < 0 || i >= size) throw new IndexOutOfBoundsException("Index: " + i + "; size: " + size); else if (i == 0) return rest; else return new ConsPStack<E>(first, rest.minus(i-1)); }
public ConsPStack<E> minus(final Object e) { if(size==0) return this; if(first.equals(e)) // found it return rest; // don't recurse (only remove one) // otherwise keep looking: ConsPStack<E> newRest = rest.minus(e); if(newRest==rest) return this; return new ConsPStack<E>(first, newRest); }
public ConsPStack<E> plus(final int i, final E e) { if(i<0 || i>size) throw new IndexOutOfBoundsException(); if(i==0) // insert at beginning return plus(e); return new ConsPStack<E>(first, rest.plus(i-1, e)); }
public ConsPStack<E> plusAll(final int i, final Collection<? extends E> list) { // TODO inefficient if list.isEmpty() if(i<0 || i>size) throw new IndexOutOfBoundsException(); if(i==0) return plusAll(list); return new ConsPStack<E>(first, rest.plusAll(i-1, list)); }
public ConsPStack<E> plus(final int i, final E e) { if(i<0 || i>size) throw new IndexOutOfBoundsException(); if(i==0) // insert at beginning return plus(e); return new ConsPStack<E>(first, rest.plus(i-1, e)); }
public ConsPStack<E> minusAll(final Collection<?> list) { if(size==0) return this; if(list.contains(first)) // get rid of current element return rest.minusAll(list); // recursively delete all // either way keep looking: ConsPStack<E> newRest = rest.minusAll(list); if(newRest==rest) return this; return new ConsPStack<E>(first, newRest); }
public ConsPStack<E> plusAll(final int i, final Collection<? extends E> list) { // TODO inefficient if list.isEmpty() if(i<0 || i>size) throw new IndexOutOfBoundsException(); if(i==0) return plusAll(list); return new ConsPStack<E>(first, rest.plusAll(i-1, list)); }
public ConsPStack<E> minusAll(final Collection<?> list) { if(size==0) return this; if(list.contains(first)) // get rid of current element return rest.minusAll(list); // recursively delete all // either way keep looking: ConsPStack<E> newRest = rest.minusAll(list); if(newRest==rest) return this; return new ConsPStack<E>(first, newRest); }
@Override public ConsPStack<E> subList(final int start, final int end) { if(start<0 || end>size || start>end) throw new IndexOutOfBoundsException(); if(end==size) // want a substack return subList(start); // this is faster if(start==end) // want nothing return empty(); if(start==0) // want the current element return new ConsPStack<E>(first, rest.subList(0, end-1)); // otherwise, don't want the current element: return rest.subList(start-1, end-1); }
@Override public ConsPStack<E> subList(final int start, final int end) { if(start<0 || end>size || start>end) throw new IndexOutOfBoundsException(); if(end==size) // want a substack return subList(start); // this is faster if(start==end) // want nothing return empty(); if(start==0) // want the current element return new ConsPStack<E>(first, rest.subList(0, end-1)); // otherwise, don't want the current element: return rest.subList(start-1, end-1); }
public ConsPStack<E> minus(final int i) { if (i < 0 || i >= size) throw new IndexOutOfBoundsException("Index: " + i + "; size: " + size); else if (i == 0) return rest; else return new ConsPStack<E>(first, rest.minus(i-1)); }
public ConsPStack<E> plusAll(final int i, final Collection<? extends E> list) { // TODO inefficient if list.isEmpty() if(i<0 || i>size) throw new IndexOutOfBoundsException(); if(i==0) return plusAll(list); return new ConsPStack<E>(first, rest.plusAll(i-1, list)); }
public ConsPStack<E> minusAll(final Collection<?> list) { if (size == 0) return this; if (list.contains(first)) // get rid of current element return rest.minusAll(list); // recursively delete all // either way keep looking: ConsPStack<E> newRest = rest.minusAll(list); if (newRest == rest) return this; return new ConsPStack<E>(first, newRest); }
public ConsPStack<E> plusAll(final int i, final Collection<? extends E> list) { // TODO inefficient if list.isEmpty() if (i < 0 || i > size) throw new IndexOutOfBoundsException(); if (i == 0) return plusAll(list); return new ConsPStack<E>(first, rest.plusAll(i - 1, list)); }