@Override public E get(final int index) { if(index<0 || index>=size()) throw new IndexOutOfBoundsException(); return map.get(index); }
@Override public E get(final int index) { if(index<0 || index>=size()) throw new IndexOutOfBoundsException(); return map.get(index); }
public TreePVector<E> plusAll(int i, final Collection<? extends E> list) { if(i<0 || i>size()) throw new IndexOutOfBoundsException(); if(list.size()==0) return this; IntTreePMap<E> map = this.map.withKeysChangedAbove(i, list.size()); for(E e : list) map = map.plus(i++, e); return new TreePVector<E>( map ); }
public PVector<E> with(final int i, final E e) { if(i<0 || i>=size()) throw new IndexOutOfBoundsException(); IntTreePMap<E> map = this.map.plus(i, e); if(map==this.map) return this; return new TreePVector<E>( map ); } }
public PVector<E> with(final int i, final E e) { if(i<0 || i>=size()) throw new IndexOutOfBoundsException(); IntTreePMap<E> map = this.map.plus(i, e); if(map==this.map) return this; return new TreePVector<E>( map ); } }
public TreePVector<E> plusAll(int i, final Collection<? extends E> list) { if(i<0 || i>size()) throw new IndexOutOfBoundsException(); if(list.size()==0) return this; IntTreePMap<E> map = this.map.withKeysChangedAbove(i, list.size()); for(E e : list) map = map.plus(i++, e); return new TreePVector<E>( map ); }
public TreePVector<E> plus(final int i, final E e) { if(i<0 || i>size()) throw new IndexOutOfBoundsException(); return new TreePVector<E>( map.withKeysChangedAbove(i,1).plus(i,e) ); }
public TreePVector<E> plus(final E e) { return new TreePVector<E>( map.plus(size(), e) ); }
public TreePVector<E> minus(final int i) { if(i<0 || i>=size()) throw new IndexOutOfBoundsException(); return new TreePVector<E>( map.minus(i).withKeysChangedAbove(i,-1) ); }
public TreePVector<E> plus(final int i, final E e) { if(i<0 || i>size()) throw new IndexOutOfBoundsException(); return new TreePVector<E>( map.withKeysChangedAbove(i,1).plus(i,e) ); }
public TreePVector<E> plus(final E e) { return new TreePVector<E>( map.plus(size(), e) ); }
public TreePVector<E> minus(final int i) { if(i<0 || i>=size()) throw new IndexOutOfBoundsException(); return new TreePVector<E>( map.minus(i).withKeysChangedAbove(i,-1) ); }
@Override public TreePVector<E> subList(final int start, final int end) { final int size = size(); if(start<0 || end>size || start>end) throw new IndexOutOfBoundsException(); if(start==end) return empty(); if(start==0) { if(end==size) return this; // remove from end: return this.minus(size-1).subList(start, end); } // remove from start: return this.minus(0).subList(start-1,end-1); }
@Override public TreePVector<E> subList(final int start, final int end) { final int size = size(); if(start<0 || end>size || start>end) throw new IndexOutOfBoundsException(); if(start==end) return empty(); if(start==0) { if(end==size) return this; // remove from end: return this.minus(size-1).subList(start, end); } // remove from start: return this.minus(0).subList(start-1,end-1); }
@Override public E get(final int index) { if (index < 0 || index >= size()) throw new IndexOutOfBoundsException(); return map.get(index); }
public void testSerializationForTreePVector() { final TreePVector<String> initialTreePVector = TreePVector.from(Arrays.asList(ELEMENT1, ELEMENT2, ELEMENT3)); final byte[] serializedTreePVector = serializeToByteArray(initialTreePVector); assertNotNull(serializedTreePVector); assertTrue(serializedTreePVector.length > 0); @SuppressWarnings("unchecked") final TreePVector<String> deserializedTreePVector = deserializeFromByteArray(serializedTreePVector, TreePVector.class); assertNotNull(deserializedTreePVector); assertEquals(3, deserializedTreePVector.size()); assertNotSame(initialTreePVector, deserializedTreePVector); assertEquals(0, deserializedTreePVector.indexOf(ELEMENT1)); assertEquals(1, deserializedTreePVector.indexOf(ELEMENT2)); assertEquals(2, deserializedTreePVector.indexOf(ELEMENT3)); }
public TreePVector<E> plusAll(int i, final Collection<? extends E> list) { if (i < 0 || i > size()) throw new IndexOutOfBoundsException(); if (list.size() == 0) return this; IntTreePMap<E> map = this.map.withKeysChangedAbove(i, list.size()); for (E e : list) map = map.plus(i++, e); return new TreePVector<E>(map); }
public TreePVector<E> plusAll(int i, final Collection<? extends E> list) { if(i<0 || i>size()) throw new IndexOutOfBoundsException(); if(list.size()==0) return this; IntTreePMap<E> map = this.map.withKeysChangedAbove(i, list.size()); for(E e : list) map = map.plus(i++, e); return new TreePVector<E>( map ); }
public TreePVector<E> minus(final int i) { if(i<0 || i>=size()) throw new IndexOutOfBoundsException(); return new TreePVector<E>( map.minus(i).withKeysChangedAbove(i,-1) ); }
public TreePVector<E> minus(final int i) { if (i < 0 || i >= size()) throw new IndexOutOfBoundsException(); return new TreePVector<E>(map.minus(i).withKeysChangedAbove(i, -1)); }