Skip to content
Snippets Groups Projects
Commit d36e246b authored by Yingjian Wang's avatar Yingjian Wang
Browse files

Upload New File

parent 4242e6bb
No related branches found
No related tags found
No related merge requests found
import java.util.*;
aspect Connectives{
uncache Term.eval();
syn int Term.eval();
eq Plus.eval(){
return this.getLeft().eval() + this.getRight().eval();
}
eq Minus.eval(){
return this.getLeft().eval() - this.getRight().eval();
}
eq Multi.eval(){
return this.getLeft().eval() * this.getRight().eval();
}
eq Divide.eval(){
return this.getLeft().eval() / this.getRight().eval();
}
eq Mod.eval(){
return this.getLeft().eval() % this.getRight().eval();
}
eq IfThenElse.eval(){
if(this.getIf().Satisfied()){
return this.getThen().eval();
}
return this.getElse().eval();
}
eq CompareFunction.eval(){
if(this.getLeft().eval() < this.getRight().eval()){
return 1;
}
return 0;
}
eq EqualFunction.eval(){
if(this.getLeft().eval() == this.getRight().eval()){
return 1;
}
return 0;
}
eq SubsetofFunction.eval(){
Set left=new HashSet<>();
for(String element : this.getLeft().Set()){
left.add(element);
}
Set right=new HashSet<>();
for(String element : this.getRight().Set()){
right.add(element);
}
if(right.containsAll(left)){
return 1;
}
return 0;
}
eq ConstantNum.eval(){
return this.getNum();
}
eq PillarID.eval(){
return this.getRel().ID();
}
eq TotalDiskAmount.eval(){
return this.getRel().AmountD();
}
eq DisksOnPillar.eval(){
return this.getRel().getNumDisk();
}
eq TopDiskSize.eval(){
return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize();
}
//customerized terms
eq Term1.eval(){//return the size of top disk
if(this.getRel().getNumDisk()>0){
//if the pillar is not empty, check if the top disk has size 1
return this.getRel().getDisk(this.getRel().getNumDisk()-1).getSize();
}else{
return -1;//no disk, the number is invalid, return -1
}
}
eq Term2.eval(){
return this.getRel().moveSeq();
}
eq Term3.eval(){
return this.getRel().ID();
}
uncache Condition.Satisfied();
syn boolean Condition.Satisfied();
eq CompareFunction.Satisfied(){
return this.getLeft().eval() < this.getRight().eval();
}
eq EqualFunction.Satisfied(){
return this.getLeft().eval() == this.getRight().eval();
}
eq SubsetofFunction.Satisfied(){
Set left=new HashSet<>();
for(String element : this.getLeft().Set()){
left.add(element);
}
Set right=new HashSet<>();
for(String element : this.getRight().Set()){
right.add(element);
}
return right.containsAll(left);
}
public String[] Term.Set(){
String[] str=new String[]{};
return str;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment