Refactor: Have only one implementation to resolve parent projects

Often the parent project for a project needs to be resolved. The
parent project can be retrieved from a project by invoking
Project#getParent(). The problem is that this method may return null
for child projects of the wild project. This special case has to be
handled by every caller (if getParent() returns null and it's not the
wild project, the wild project is the parent). Similar code to handle
this situation is repeated in several places.

This change makes one implementation to resolve the parent project
reusable and removes duplicate code.

Change-Id: Id3d8f19c0ea6fc168c2f5dbc15f9e21bc2246d94
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2011-12-28 14:36:06 +01:00
parent 17abbef1b7
commit 128381f984
5 changed files with 32 additions and 41 deletions

View File

@@ -184,10 +184,36 @@ public final class Project {
state = update.state;
}
/**
* Returns the name key of the parent project.
*
* @return name key of the parent project, <code>null</code> if this project
* is the wild project, <code>null</code> or the name key of the wild
* project if this project is a direct child of the wild project
*/
public Project.NameKey getParent() {
return parent;
}
/**
* Returns the name key of the parent project.
*
* @param allProjectsName name key of the wild project
* @return name key of the parent project, <code>null</code> if this project
* is the wild project
*/
public Project.NameKey getParent(final Project.NameKey allProjectsName) {
if (parent != null) {
return parent;
}
if (name.equals(allProjectsName)) {
return null;
}
return allProjectsName;
}
public String getParentName() {
return parent != null ? parent.get() : null;
}