@Test public void testEndMappings() { assertEquals(DEV_ROB.length() - 1, collectionList.childEndingIndex(0)); assertEquals(DEV_ROB.length() + DEV_JESSE.length() - 1, collectionList.childEndingIndex(1)); assertEquals(DEV_ROB.length() + DEV_JESSE.length() + DEV_KEVIN.length() - 1, collectionList.childEndingIndex(2)); assertEquals(DEV_ROB.length() + DEV_JESSE.length() + DEV_KEVIN.length() + DEV_JAMES.length() - 1, collectionList.childEndingIndex(3)); try { assertEquals(-1, collectionList.childEndingIndex(-1)); fail("Expected IndexOutOfBoundsException"); } catch(IndexOutOfBoundsException e) { } try { assertEquals(-1, collectionList.childEndingIndex(4)); fail("Expected IndexOutOfBoundsException"); } catch(IndexOutOfBoundsException e) { } parentList.add(1, DEV_EMPTY); assertEquals(-1, collectionList.childEndingIndex(1)); parentList.add(5, DEV_EMPTY); assertEquals(-1, collectionList.childEndingIndex(5)); }
public int childEndingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int nextParentFullIndex = (parentIndex == barcode.blackSize() - 1) ? barcode.size() : barcode.getIndex(parentIndex + 1, Barcode.BLACK); final int lastWhiteBeforeNextParent = nextParentFullIndex - 1; if(barcode.get(lastWhiteBeforeNextParent) == Barcode.BLACK) return -1; final int childIndex = lastWhiteBeforeNextParent - (parentIndex+1); assert(barcode.getWhiteIndex(lastWhiteBeforeNextParent) == childIndex); return childIndex; }
CollectionList extends TransformedList<S, E> implements ListEventListener<S> { public int childEndingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int nextParentFullIndex = (parentIndex == barcode.blackSize() - 1) ? barcode.size() : barcode.getIndex(parentIndex + 1, Barcode.BLACK); final int lastWhiteBeforeNextParent = nextParentFullIndex - 1; if(barcode.get(lastWhiteBeforeNextParent) == Barcode.BLACK) return -1; final int childIndex = lastWhiteBeforeNextParent - (parentIndex+1); assert(barcode.getWhiteIndex(lastWhiteBeforeNextParent) == childIndex); return childIndex; } }
CollectionList extends TransformedList<S, E> implements ListEventListener<S> { public int childEndingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int nextParentFullIndex = (parentIndex == barcode.blackSize() - 1) ? barcode.size() : barcode.getIndex(parentIndex + 1, Barcode.BLACK); final int lastWhiteBeforeNextParent = nextParentFullIndex - 1; if(barcode.get(lastWhiteBeforeNextParent) == Barcode.BLACK) return -1; final int childIndex = lastWhiteBeforeNextParent - (parentIndex+1); assert(barcode.getWhiteIndex(lastWhiteBeforeNextParent) == childIndex); return childIndex; } CollectionList(EventList<S> source, Model<S, E> model); }
CollectionList extends TransformedList<S, E> implements ListEventListener<S> { public int childEndingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int nextParentFullIndex = (parentIndex == barcode.blackSize() - 1) ? barcode.size() : barcode.getIndex(parentIndex + 1, Barcode.BLACK); final int lastWhiteBeforeNextParent = nextParentFullIndex - 1; if(barcode.get(lastWhiteBeforeNextParent) == Barcode.BLACK) return -1; final int childIndex = lastWhiteBeforeNextParent - (parentIndex+1); assert(barcode.getWhiteIndex(lastWhiteBeforeNextParent) == 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 childEndingIndex(int parentIndex) { if(parentIndex < 0) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); if(parentIndex >= source.size()) throw new IndexOutOfBoundsException("Invalid index: " + parentIndex); final int nextParentFullIndex = (parentIndex == barcode.blackSize() - 1) ? barcode.size() : barcode.getIndex(parentIndex + 1, Barcode.BLACK); final int lastWhiteBeforeNextParent = nextParentFullIndex - 1; if(barcode.get(lastWhiteBeforeNextParent) == Barcode.BLACK) return -1; final int childIndex = lastWhiteBeforeNextParent - (parentIndex+1); assert(barcode.getWhiteIndex(lastWhiteBeforeNextParent) == 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();  }