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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user