cdc.mf.model.MfDependency Maven / Gradle / Ivy
package cdc.mf.model;
import cdc.util.lang.Checks;
import cdc.util.lang.Introspection;
public final class MfDependency extends MfLink {
public static final Class PARENT_CLASS =
MfDependencyOwner.class;
public static final Class> BUILDER_CLASS =
Introspection.uncheckedCast(Builder.class);
public static final MfElementFeatures FEATURES =
MfElementFeatures.NONE;
private final MfElementRef targetRef;
protected MfDependency(Builder extends MfDependencyOwner> builder) {
super(builder,
FEATURES);
this.targetRef = Checks.isNotNull(builder.targetRef, MfNames.TARGET_REF);
addToParent(FEATURES);
addToModel();
}
@Override
public MfDependency duplicate(MfDependencyOwner tgtParent) {
return tgtParent.dependency()
.set(this)
.build();
}
@Override
public MfDependencyOwner getSource() {
return getParent();
}
@Override
public MfElementRef getTargetRef() {
return targetRef;
}
@Override
public MfDocumentation.Builder documentation() {
return MfDocumentation.builder(this);
}
@Override
public MfTag.Builder tag() {
return MfTag.builder(this);
}
static Builder
builder(P parent) {
return new Builder<>(parent);
}
/**
* Builder of dependencies.
*
* @author Damien Carbonne
*
* @param
The concrete parent type.
*/
public static final class Builder
extends MfLink.Builder, MfDependency, P> {
private MfElementRef targetRef;
protected Builder(P parent) {
super(parent);
}
@Override
public Builder set(MfDependency element) {
return super.set(element).targetRef(toLazy(element.getTargetRef()));
}
@Override
public Class getElementClass() {
return MfDependency.class;
}
public MfElementRef getTargetRef() {
return targetRef;
}
public Builder targetRef(MfElementRef targetRef) {
this.targetRef = targetRef;
return self();
}
public Builder target(MfElement target) {
this.targetRef = MfElementRef.of(target);
return self();
}
public Builder
targetId(String targetId) {
return targetRef(MfElementRef.of(getModel(), MfElement.class, targetId));
}
@Override
public MfDependency build() {
return new MfDependency(this);
}
}
}