private void validateParent(String type) { TimelineEntityType parentType = TimelineEntityType.valueOf(type); TimelineEntityType thisType = TimelineEntityType.valueOf(getType()); if (!thisType.isParent(parentType)) { throw new IllegalArgumentException( type + " is not the acceptable parent of " + this.getType()); } }
private void validateChild(Identifier child, TimelineEntityType thisType) { TimelineEntityType childType = TimelineEntityType.valueOf(child.getType()); if (!thisType.isChild(childType)) { throw new IllegalArgumentException( child.getType() + " is not the acceptable child of " + this.getType()); } } }
public void addChildren(Set<Identifier> children) { TimelineEntityType thisType = TimelineEntityType.valueOf(getType()); for (Identifier child : children) { validateChild(child, thisType); } Set<Identifier> existingChildren = getChildren(); existingChildren.addAll(children); setChildren(existingChildren); }
@SuppressWarnings("unchecked") public Set<Identifier> getChildren() { Object identifiers = getInfo().get(CHILDREN_INFO_KEY); if (identifiers == null) { return new HashSet<>(); } TimelineEntityType thisType = TimelineEntityType.valueOf(getType()); if (identifiers instanceof Set<?>) { for (Object identifier : (Set<?>) identifiers) { if (!(identifier instanceof Identifier)) { throw new YarnRuntimeException( "Children info contains invalid identifier object"); } else { validateChild((Identifier) identifier, thisType); } } } else { throw new YarnRuntimeException( "Children info is invalid identifier set"); } Set<Identifier> children = (Set<Identifier>) identifiers; return children; }