12.07.2015 Views

Podsumowanie wzorców projektowych GoF

Podsumowanie wzorców projektowych GoF

Podsumowanie wzorców projektowych GoF

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

private String[] titles;//Yes, it would be easier to do this whole example with ArrayList// and ListIterator, but it certainly wouldn't be as much fun!private int titleCount;//title count is always a real count of titles, but one ahead of//itself as a subscriptprivate int arraySize;public DvdList() {titles = new String[3];//using 3 to demonstrate array expansion more easily,// not for efficencytitleCount = 0;arraySize = 3;}public int count() {return titleCount;}public void append(String titleIn) {if (titleCount >= arraySize) {String[] tempArray = new String[arraySize];for (int i = 0; i < arraySize; i++){tempArray[i] = titles[i];}titles = null;arraySize = arraySize + 3;titles = new String[arraySize];for (int i = 0; i < (arraySize - 3); i++) {titles[i] = tempArray[i];}}titles[titleCount++] = titleIn;}public void delete(String titleIn) {boolean found = false;for (int i = 0; i < (titleCount -1); i++) {if (found == false) {if (titles[i].equals(titleIn)) {found = true;titles[i] = titles[i + 1];}} else {if (i < (titleCount -1)) {titles[i] = titles[i + 1];} else {titles[i] = null;}}}}if (found == true) {--titleCount;}public DvdListIterator createIterator() {return new InnerIterator();}65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!