Skip to content
Snippets Groups Projects

Include ModelJoin support in main development

Merged Rico Bergmann requested to merge feature/modeljoin-support into develop
1 file
+ 95
5
Compare changes
  • Side-by-side
  • Inline
package org.rosi_project.model_sync.model_join.representation.grammar;
package org.rosi_project.model_sync.model_join.representation.grammar;
 
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Objects;
import javax.annotation.Nonnull;
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.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
* @author Rico Bergmann
*/
*/
public class KeepSuperTypeExpression extends KeepExpression {
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
@Nonnull
private final ClassResource typeToKeep;
private final ClassResource typeToKeep;
@Nonnull
@Nonnull
private final AttributePath target;
private final ClassResource target;
@Nonnull
@Nonnull
private final List<KeepExpression> keeps;
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(
public KeepSuperTypeExpression(
@Nonnull ClassResource typeToKeep,
@Nonnull ClassResource typeToKeep,
@Nonnull AttributePath target,
@Nonnull ClassResource target,
@Nonnull List<KeepExpression> keeps) {
@Nonnull List<KeepExpression> keeps) {
this.typeToKeep = typeToKeep;
this.typeToKeep = typeToKeep;
this.target = target;
this.target = target;
this.keeps = keeps;
this.keeps = keeps;
}
}
 
/**
 
* Provides the supertype that should be instantiated.
 
*/
@Nonnull
@Nonnull
public ClassResource getType() {
public ClassResource getType() {
return typeToKeep;
return typeToKeep;
}
}
 
/**
 
* Provides the name of the view that should be generated for all matching instances.
 
*/
@Nonnull
@Nonnull
public AttributePath getTarget() {
public ClassResource getTarget() {
return target;
return target;
}
}
 
/**
 
* Provides all {@code KeepExpression keep expressions} that should be used to build the Join for
 
* the instances of the superclass instances.
 
*/
@Nonnull
@Nonnull
public List<KeepExpression> getKeeps() {
public List<KeepExpression> getKeeps() {
return keeps;
return new ArrayList<>(keeps);
}
}
@Override
@Override
Loading