@Test public void testStartMappings() { assertEquals(0, collectionList.childStartingIndex(0)); assertEquals(DEV_ROB.length(), collectionList.childStartingIndex(1)); assertEquals(DEV_ROB.length() + DEV_JESSE.length(), collectionList.childStartingIndex(2)); assertEquals(DEV_ROB.length() + DEV_JESSE.length() + DEV_KEVIN.length(), collectionList.childStartingIndex(3)); try { collectionList.childStartingIndex(-1); fail("Expected IndexOutOfBoundsException"); } catch(IndexOutOfBoundsException e) { } try { collectionList.childStartingIndex(4); fail("Expected IndexOutOfBoundsException"); } catch(IndexOutOfBoundsException e) { } parentList.add(1, DEV_EMPTY); assertEquals(-1, collectionList.childStartingIndex(1)); parentList.add(5, DEV_EMPTY); assertEquals(-1, collectionList.childStartingIndex(5)); }
public int childStartingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int parentFullIndex = barcode.getIndex(parentIndex, Barcode.BLACK); final int childFullIndex = parentFullIndex + 1; if(childFullIndex >= barcode.size()) return -1; if(barcode.get(childFullIndex) != Barcode.WHITE) return -1; final int childIndex = childFullIndex - (parentIndex+1); assert(barcode.getWhiteIndex(childFullIndex) == childIndex); return childIndex; }
CollectionList extends TransformedList<S, E> implements ListEventListener<S> { public int childStartingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int parentFullIndex = barcode.getIndex(parentIndex, Barcode.BLACK); final int childFullIndex = parentFullIndex + 1; if(childFullIndex >= barcode.size()) return -1; if(barcode.get(childFullIndex) != Barcode.WHITE) return -1; final int childIndex = childFullIndex - (parentIndex+1); assert(barcode.getWhiteIndex(childFullIndex) == childIndex); return childIndex; } }
CollectionList extends TransformedList<S, E> implements ListEventListener<S> { public int childStartingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int parentFullIndex = barcode.getIndex(parentIndex, Barcode.BLACK); final int childFullIndex = parentFullIndex + 1; if(childFullIndex >= barcode.size()) return -1; if(barcode.get(childFullIndex) != Barcode.WHITE) return -1; final int childIndex = childFullIndex - (parentIndex+1); assert(barcode.getWhiteIndex(childFullIndex) == childIndex); return childIndex; } CollectionList(EventList<S> source, Model<S, E> model); }
CollectionList extends TransformedList<S, E> implements ListEventListener<S> { public int childStartingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int parentFullIndex = barcode.getIndex(parentIndex, Barcode.BLACK); final int childFullIndex = parentFullIndex + 1; if(childFullIndex >= barcode.size()) return -1; if(barcode.get(childFullIndex) != Barcode.WHITE) return -1; final int childIndex = childFullIndex - (parentIndex+1); assert(barcode.getWhiteIndex(childFullIndex) == childIndex); return childIndex; } CollectionList(EventList<S> source, Model<S, E> model); @Override int size(); @Override E get(int index); @Override E set(int index, E value); @Override E remove(int index); int childStartingIndex(int parentIndex); int childEndingIndex(int parentIndex); @Override void listChanged(ListEvent<S> listChanges); @Override void dispose(); }
CollectionList extends TransformedList<S, E> implements ListEventListener<S> { public int childStartingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int parentFullIndex = barcode.getIndex(parentIndex, Barcode.BLACK); final int childFullIndex = parentFullIndex + 1; if(childFullIndex >= barcode.size()) return -1; if(barcode.get(childFullIndex) != Barcode.WHITE) return -1; final int childIndex = childFullIndex - (parentIndex+1); assert(barcode.getWhiteIndex(childFullIndex) == childIndex); return childIndex; } CollectionList(EventList<S> source, Model<S, E> model); @Override int size(); @Override E get(int index); @Override E set(int index, E value); @Override E remove(int index); int childStartingIndex(int parentIndex); int childEndingIndex(int parentIndex); @Override void listChanged(ListEvent<S> listChanges); @Override void dispose();  }