|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object MyString
public class MyString
Project #0 CS 2334, Section 010 Sep 10, 2008
This is an example class for CS 2334 that shows proper documentation. It is a class that doesn't do much of anything useful, which makes it hard to write a really great comment up here. It is however, properly documented.
Field Summary | |
---|---|
private char[] |
data
A private array to store the characters in the string. |
static int |
DEFAULT_SIZE
A constant that contains the standard number of characters in a string. |
private int |
size
The number of characters that are actually stored in the string. |
Constructor Summary | |
---|---|
MyString(int currentSize)
A constructor for an empty string of currentSize elements. |
Method Summary | |
---|---|
char[] |
getData()
The accessor for the character array data . |
int |
getLength()
An accessor for the variable size . |
void |
setData(char[] newData)
A mutator that changes the contents of the character array data . |
void |
setLength(int newLength)
A mutator that sets the size of the array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static int DEFAULT_SIZE
private char[] data
private int size
Constructor Detail |
---|
public MyString(int currentSize)
currentSize
elements.
currentSize
- The number of characters in the
string.
java.lang.IllegalArgumentException
- if currentSize < 0
currentSize
contains a non-negative
integer.
currentSize
.Method Detail |
---|
public int getLength()
size
.
public char[] getData()
data
.
data
.public void setLength(int newLength)
Algorithm:
1. Allocate more space.
2. Copy existing data into the new array.
3. Record changes in the instance variables.
newLength
- The desired length for the modified
string.
java.lang.IllegalArgumentException
- if newLength < 0
newLength
contains a non-negative
integer.
newLength
.public void setData(char[] newData)
data
.
newData
- A reference to the character array to be
used.
newData
.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |