@Test public void testFindSequenceOfMinimumSize() { barcode.addBlack(0, 10); barcode.addWhite(10, 3); barcode.addWhite(7, 3); barcode.addWhite(5, 5); barcode.addWhite(3, 7); barcode.addWhite(1, 3); assertEquals(0, barcode.findSequenceOfMinimumSize(1, Barcode.BLACK)); assertEquals(4, barcode.findSequenceOfMinimumSize(2, Barcode.BLACK)); assertEquals(-1, barcode.findSequenceOfMinimumSize(4, Barcode.BLACK)); assertEquals(1, barcode.findSequenceOfMinimumSize(1, Barcode.WHITE)); assertEquals(1, barcode.findSequenceOfMinimumSize(3, Barcode.WHITE)); assertEquals(6, barcode.findSequenceOfMinimumSize(5, Barcode.WHITE)); assertEquals(6, barcode.findSequenceOfMinimumSize(7, Barcode.WHITE)); assertEquals(-1, barcode.findSequenceOfMinimumSize(8, Barcode.WHITE)); }
public int findSequenceOfMinimumSize(int size, Object colour) { if(root == null) { if(colour == BLACK) return -1; else if(whiteSpace >= size) return 0; else return -1; } else if(colour == BLACK) { return root.findSequenceOfMinimumSize(size, colour); } else { int result = root.findSequenceOfMinimumSize(size, colour); if(result == -1 && whiteSpace >= size) result = treeSize; return result; } }
Barcode { public int findSequenceOfMinimumSize(int size, Object colour) { if(root == null) { if(colour == BLACK) return -1; else if(whiteSpace >= size) return 0; else return -1; } else if(colour == BLACK) { return root.findSequenceOfMinimumSize(size, colour); } else { int result = root.findSequenceOfMinimumSize(size, colour); if(result == -1 && whiteSpace >= size) result = treeSize; return result; } } }
Barcode { public int findSequenceOfMinimumSize(int size, Object colour) { if(root == null) { if(colour == BLACK) return -1; else if(whiteSpace >= size) return 0; else return -1; } else if(colour == BLACK) { return root.findSequenceOfMinimumSize(size, colour); } else { int result = root.findSequenceOfMinimumSize(size, colour); if(result == -1 && whiteSpace >= size) result = treeSize; return result; } }  }
Barcode { public int findSequenceOfMinimumSize(int size, Object colour) { if(root == null) { if(colour == BLACK) return -1; else if(whiteSpace >= size) return 0; else return -1; } else if(colour == BLACK) { return root.findSequenceOfMinimumSize(size, colour); } else { int result = root.findSequenceOfMinimumSize(size, colour); if(result == -1 && whiteSpace >= size) result = treeSize; return result; } }  void printDebug(); void validate(); int size(); boolean isEmpty(); int whiteSize(); int blackSize(); int colourSize(Object colour); void add(int index, Object colour, int length); void addWhite(int index, int length); void addBlack(int index, int length); Object get(int index); void set(int index, Object colour, int length); void setWhite(int index, int length); void setBlack(int index, int length); void remove(int index, int length); void clear(); int getIndex(int colourIndex, Object colour); int getColourIndex(int index, Object colour); int getWhiteIndex(int index); int getBlackIndex(int index); int getColourIndex(int index, boolean left, Object colour); int getWhiteIndex(int index, boolean left); int getBlackIndex(int index, boolean left); int getWhiteSequenceIndex(int whiteIndex); int getBlackBeforeWhite(int whiteIndex); int findSequenceOfMinimumSize(int size, Object colour); BarcodeIterator iterator(); @Override String toString(); }
Barcode { public int findSequenceOfMinimumSize(int size, Object colour) { if(root == null) { if(colour == BLACK) return -1; else if(whiteSpace >= size) return 0; else return -1; } else if(colour == BLACK) { return root.findSequenceOfMinimumSize(size, colour); } else { int result = root.findSequenceOfMinimumSize(size, colour); if(result == -1 && whiteSpace >= size) result = treeSize; return result; } }  void printDebug(); void validate(); int size(); boolean isEmpty(); int whiteSize(); int blackSize(); int colourSize(Object colour); void add(int index, Object colour, int length); void addWhite(int index, int length); void addBlack(int index, int length); Object get(int index); void set(int index, Object colour, int length); void setWhite(int index, int length); void setBlack(int index, int length); void remove(int index, int length); void clear(); int getIndex(int colourIndex, Object colour); int getColourIndex(int index, Object colour); int getWhiteIndex(int index); int getBlackIndex(int index); int getColourIndex(int index, boolean left, Object colour); int getWhiteIndex(int index, boolean left); int getBlackIndex(int index, boolean left); int getWhiteSequenceIndex(int whiteIndex); int getBlackBeforeWhite(int whiteIndex); int findSequenceOfMinimumSize(int size, Object colour); BarcodeIterator iterator(); @Override String toString(); static final Object WHITE; static final Object BLACK; }