*/
private final TreeMap<String, PackageRelationship> relationshipsByID = new TreeMap<>();
- /**
- * Package relationships ordered by type.
- */
- private final TreeMap<String, PackageRelationship> relationshipsByType = new TreeMap<>();
-
/**
* A lookup of internal relationships to avoid
*/
- private HashMap<String, PackageRelationship> internalRelationshipsByTargetName = new HashMap<>();
+ private final HashMap<String, PackageRelationship> internalRelationshipsByTargetName = new HashMap<>();
/**
(relPart == null ? "<null>" : relPart.getId()) + " for relationship: " + relPart);
}
relationshipsByID.put(relPart.getId(), relPart);
- relationshipsByType.put(relPart.getRelationshipType(), relPart);
}
/**
*/
public PackageRelationship addRelationship(URI targetUri,
TargetMode targetMode, String relationshipType, String id) {
- if (id == null || id.length() == 0) {
- // Generate a unique ID is id parameter is null.
+ if (id == null || id.isEmpty()) {
+ // Generate a unique ID if id parameter is null.
if (nextRelationshipId == -1) {
nextRelationshipId = size() + 1;
}
PackageRelationship rel = relationshipsByID.get(id);
if (rel != null) {
relationshipsByID.remove(rel.getId());
- relationshipsByType.values().remove(rel);
internalRelationshipsByTargetName.values().remove(rel);
}
}
* @return The package relationship identified by the specified id.
*/
public PackageRelationship getRelationshipByID(String id) {
+ if (id == null) {
+ throw new IllegalArgumentException("Cannot read relationship, provided ID is empty: " + id +
+ ", having relationships: " + relationshipsByID.keySet());
+ }
+
return relationshipsByID.get(id);
}
*/
public void clear() {
relationshipsByID.clear();
- relationshipsByType.clear();
internalRelationshipsByTargetName.clear();
}