Skip to content
Snippets Groups Projects
Verified Commit 6ddc7255 authored by Rico Bergmann's avatar Rico Bergmann
Browse files

Complete implementation of KeepSuperTypeExpression

This adds missing builder functionality as well as a complete JavaDoc
parent 90ecbada
No related branches found
No related tags found
1 merge request!4Include ModelJoin support in main development
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
package org.rosi_project.model_sync.model_join.representation.grammar;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nonnull;
import org.rosi_project.model_sync.model_join.representation.core.AttributePath;
import org.rosi_project.model_sync.model_join.representation.core.ClassResource;
import org.rosi_project.model_sync.model_join.representation.util.Assert;
// TODO add doc
/**
* A {@code KeepSuperTypeExpression} instructs the {@code ModelJoin} runtime to instantiate the a
* supertype of some class in a join along an instance of that class. The additional instance will
* be built according to the {@code KeepExpression keep statements} that it is constructed of.
*
* @author Rico Bergmann
*/
public class KeepSuperTypeExpression extends KeepExpression {
/**
* The {@code KeepSuperTypeBuilder} enables the construction of new {@code KeepSuperTypeExpression}
* instances through a nice and fluent interface.
*
* @author Rico Bergmann
*/
public static class KeepSuperTypeBuilder {
private ClassResource typeToKeep;
private ClassResource target;
private List<KeepExpression> keeps;
/**
* Default constructor.
*/
private KeepSuperTypeBuilder() {
this.keeps = new ArrayList<>();
}
/**
* Specifies the supertype that should be instantiated.
*/
@Nonnull
public KeepSuperTypeBuilder supertype(@Nonnull ClassResource type) {
this.typeToKeep = type;
return this;
}
/**
* Specifies the name of the class that should be generated for the subtype instances.
*/
@Nonnull
public KeepSuperTypeBuilder as(@Nonnull ClassResource target) {
this.target = target;
return this;
}
/**
* Adds a {@link KeepExpression keep statement} for the subtype-class. The described attribute
* will be initialized for each instantiated subtype element.
*/
@Nonnull
public KeepSuperTypeBuilder keep(@Nonnull KeepExpression keep) {
this.keeps.add(keep);
return this;
}
/**
* Finishes the construction process.
*/
@Nonnull
public KeepSuperTypeExpression buildExpression() {
Assert.noNullArguments("All components must be specified", typeToKeep, target, keeps);
return new KeepSuperTypeExpression(typeToKeep, target, keeps);
}
}
/**
* Starts the creation process for a new {@code KeepSuperTypeExpression}.
*/
@Nonnull
public static KeepSuperTypeBuilder keep() {
return new KeepSuperTypeBuilder();
}
@Nonnull
private final ClassResource typeToKeep;
@Nonnull
private final AttributePath target;
private final ClassResource target;
@Nonnull
private final List<KeepExpression> keeps;
/**
* Full constructor.
*
* @param typeToKeep the supertype that should be instantiated.
* @param target the name of the view that should be generated for all matching instances
* @param keeps the keep statements that should form the attributes of the generated view
* instances
*/
public KeepSuperTypeExpression(
@Nonnull ClassResource typeToKeep,
@Nonnull AttributePath target,
@Nonnull ClassResource target,
@Nonnull List<KeepExpression> keeps) {
this.typeToKeep = typeToKeep;
this.target = target;
this.keeps = keeps;
}
/**
* Provides the supertype that should be instantiated.
*/
@Nonnull
public ClassResource getType() {
return typeToKeep;
}
/**
* Provides the name of the view that should be generated for all matching instances.
*/
@Nonnull
public AttributePath getTarget() {
public ClassResource getTarget() {
return target;
}
/**
* Provides all {@code KeepExpression keep expressions} that should be used to build the Join for
* the instances of the superclass instances.
*/
@Nonnull
public List<KeepExpression> getKeeps() {
return keeps;
return new ArrayList<>(keeps);
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment