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

Finish implementation of the KeepSubTypeExpression

This adds missing builder functionality as well as a complete JavaDoc
parent eb92aa35
No related branches found
No related tags found
1 merge request!4Include ModelJoin support in main development
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;
/**
* A {@code KeepSubTypeExpression} instructs the {@code ModelJoin} runtime to instantiate the most
* specific type that inherits from this type as well. The additional instance will be built
* according to the {@code KeepExpression keep statements} that it is constructed of.
* <p>
* In order to prevent ambiguities a {@code KeepSubTypeExpression} may only be specified on joins
* that do not participate in another {@link JoinExpression join statement}.
*
* @author Rico Bergmann
*/
public class KeepSubTypeExpression extends KeepExpression {
/**
* The {@code KeepSubTypeBuilder} enables the construction of new {@code KeepSubTypeExpression}
* instances through a nice and fluent interface.
*
* @author Rico Bergmann
*/
public static class KeepSubTypeBuilder {
private ClassResource typeToKeep;
private ClassResource target;
private List<KeepExpression> keeps;
/**
* Default constructor.
*/
private KeepSubTypeBuilder() {
this.keeps = new ArrayList<>();
}
/**
* Specifies the subtype that should be instantiated.
*/
@Nonnull
public KeepSubTypeBuilder subtype(@Nonnull ClassResource type) {
this.typeToKeep = type;
return this;
}
/**
* Specifies the name of the class that should be generated for the subtype instances.
*/
@Nonnull
public KeepSubTypeBuilder 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 KeepSubTypeBuilder keep(@Nonnull KeepExpression keep) {
this.keeps.add(keep);
return this;
}
/**
* Finishes the construction process.
*/
@Nonnull
public KeepSubTypeExpression buildExpression() {
Assert.noNullArguments("All components must be specified", typeToKeep, target, keeps);
return new KeepSubTypeExpression(typeToKeep, target, keeps);
}
}
/**
* Starts the creation process for a new {@code KeepSubTypeExpression}.
*/
@Nonnull
public static KeepSubTypeBuilder keep() {
return new KeepSubTypeBuilder();
}
@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 subtype 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 KeepSubTypeExpression(
@Nonnull ClassResource typeToKeep,
@Nonnull AttributePath target,
@Nonnull ClassResource target,
@Nonnull List<KeepExpression> keeps) {
this.typeToKeep = typeToKeep;
this.target = target;
this.keeps = keeps;
}
/**
* Provides the subtype 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 subclass 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