Created
January 19, 2012 14:39
-
-
Save simcap/1640371 to your computer and use it in GitHub Desktop.
TDD workshop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomList { | |
private boolean readOnly; | |
private Object[] elements; | |
private int size; | |
public CustomList() { | |
this.elements = new Object[0]; | |
this.size = 0; | |
this.readOnly = true; | |
} | |
public void add(Object element) { | |
if (!readOnly) { | |
int newSize = size + 1; | |
if (newSize > elements.length) { | |
Object[] newElements = new Object[elements.length + 10]; | |
for (int i = 0; i < size; i++) { | |
newElements[i] = elements[i]; | |
} | |
elements = newElements; | |
} | |
elements[size++] = element; | |
} | |
} | |
public int getSize() { | |
return size; | |
} | |
public Object getElement(int index) { | |
return elements[index]; | |
} | |
public void setReadOnly(boolean readOnly) { | |
this.readOnly = readOnly; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment