Java PrimerMethod Properties in Java

Listing 8. The "Name contextName()" method of AbstractName.


/**
 * Return context name of Name object.
 * @methodtype get
 */
public Name contextName() throws InvalidIndexException {
	int nc= noComponents()-1;
[1]	assertIsValidIndex(nc);

	if (nc == 0) {
[2]		return newName("");

	}

	StringBuffer sb= new StringBuffer();
	for (int i= 0; i < nc; i++) { 
[3]		sb.append(basicComponent(i));
[4]		sb.append(delimiterChar());

	}
	sb.setLength(sb.length()-1);
[5]	return newName(sb.toString());
}