Skip to content

Commit

Permalink
adding code for lab10 for feature models
Browse files Browse the repository at this point in the history
along with results
  • Loading branch information
bargemb committed Nov 25, 2018
1 parent 1effb9d commit efcdfe1
Show file tree
Hide file tree
Showing 40 changed files with 862 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lab10/GumballMachineV1/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="COINS50.aj|QTR50.aj" kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
40 changes: 40 additions & 0 deletions lab10/GumballMachineV1/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GumballMachineV1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>de.ovgu.featureide.core.extensibleFeatureProjectBuilder</name>
<arguments>
<dictionary>
<key>build</key>
<value>src</value>
</dictionary>
<dictionary>
<key>composer</key>
<value>de.ovgu.featureide.core.composer.aspectj</value>
</dictionary>
<dictionary>
<key>equations</key>
<value>configs</value>
</dictionary>
<dictionary>
<key>source</key>
<value>src</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>de.ovgu.featureide.core.featureProjectNature</nature>
</natures>
</projectDescription>
1 change: 1 addition & 0 deletions lab10/GumballMachineV1/configs/default.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
QTR25
45 changes: 45 additions & 0 deletions lab10/GumballMachineV1/model.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<featureModel>
<properties/>
<struct>
<or abstract="true" mandatory="true" name="GumballMachine">
<description>

</description>
<alt abstract="true" mandatory="true" name="Base">
<description>

</description>
<and abstract="true" mandatory="true" name="C25">
<description>

</description>
<feature mandatory="true" name="QTR25">
<description>

</description>
</feature>
</and>
<alt abstract="true" mandatory="true" name="C50">
<description>

</description>
<feature mandatory="true" name="QTR50">
<description>

</description>
</feature>
<feature mandatory="true" name="COINS50">
<description>

</description>
</feature>
</alt>
</alt>
</or>
</struct>
<constraints/>
<calculations Auto="true" Constraints="true" Features="true" Redundant="true" Tautology="true"/>
<comments/>
<featureOrder userDefined="false"/>
</featureModel>
47 changes: 47 additions & 0 deletions lab10/GumballMachineV1/src/COINS50.aj
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

public aspect COINS50 {

// implement advice for getTenant
Object around(GumballMachine m) : target(m) && call(String GumballMachine.getTenant(..)) {
return "COINS50" ;
}

// implement advice for insertQuarter
after(GumballMachine m): target(m) && call(void GumballMachine.insertQuarter(..)) {
if (m.getCoinValue() < 50) {
m.setCoinValue(m.getCoinValue() + 25);
System.out.println("A quarter has been inserted");
} else {
System.out.println("There are already quarters in the slot");
}
}


// implement advice for insertCoin
after(GumballMachine m): target(m) && call(void GumballMachine.insertCoin(..)) {
Object[] args = thisJoinPoint.getArgs();
int value = ((Integer) args[0]).intValue() ;
if (m.getCoinValue() < 50) {
m.setCoinValue(m.getCoinValue() + value);
System.out.println( value + " cents has been inserted");
} else {
System.out.println("There are already 50 cents in the slot");
}
}

// implement advice for turnTheCrank
after(GumballMachine m): target(m) && call(void GumballMachine.turnTheCrank(..)) {
if (m.getCoinValue() == 50) {
m.setCoinValue(0);
if (m.getCount() > 0) {
System.out.println("Here is your Gumball! Enjoy!");
m.setCount(m.getCount() - 1);
} else {
System.out.println("Sorry! We're out of Gumballs!");
}
} else {
System.out.println("Crank will not turn without enough Coins!");
}
}

}
68 changes: 68 additions & 0 deletions lab10/GumballMachineV1/src/GumballMachine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
public class GumballMachine {

private int cnt = 0;
private boolean quarterInSlot = false;
private int coinValue = 0;

public String getTenant() {
return null ;
}

public int getCoinValue() {
return coinValue;
}

public void setCoinValue(int v) {
this.coinValue = v;
}

public boolean isQuarterInSlot() {
return quarterInSlot;
}

public void setQuarterInSlot(boolean q) {
this.quarterInSlot = q;
}

public GumballMachine(int count) {
this.cnt = count;
}

public void insertQuarter() {
System.out.println( "==> Insert Quarter <==" ) ;
}

public void insertCoin(Integer value) {
System.out.println( "==> Insert Coin " + value.toString() + " <==" ) ;
}

public void turnTheCrank() {
System.out.println( "==> Turn Crank <==" ) ;
}

public int getCount() {
return cnt;
}

public void setCount(int c) {
cnt = c;
}

public static void main(String[] args) {
GumballMachine m = new GumballMachine(2);
System.out.println("*** Gumball Machine " + m.getTenant() + " *** ");
m.insertQuarter();
m.turnTheCrank(); // should eject for tenant #1
m.insertQuarter();
m.turnTheCrank(); // should eject for tenant #1, #2, and #3
m.insertCoin(10);
m.insertCoin(10);
m.insertCoin(5);
m.insertCoin(25);
m.turnTheCrank(); // should eject for tenant #3
m.insertCoin(10);
m.insertCoin(10);
m.turnTheCrank(); // should eject for tenant #3
}

}
33 changes: 33 additions & 0 deletions lab10/GumballMachineV1/src/QTR25.aj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public aspect QTR25 {

// implement advice for getTenant
Object around(GumballMachine m) : target(m) && call(String GumballMachine.getTenant(..)) {
return "QTR25" ;
}

// implement advice for insertQuarter
after(GumballMachine m): target(m) && call(void GumballMachine.insertQuarter(..)) {
if ( !m.isQuarterInSlot() ) {
m.setQuarterInSlot( true );
System.out.println("A quarter has been inserted");
} else {
System.out.println("There's already a quarter in the slot");
}
}

// implement advice for turnTheCrank
after(GumballMachine m): target(m) && call(void GumballMachine.turnTheCrank(..)) {
if (m.isQuarterInSlot()) {
m.setQuarterInSlot( false ) ;
if (m.getCount() > 0) {
System.out.println("Here is your Gumball! Enjoy!");
m.setCount(m.getCount()-1);
} else {
System.out.println("Sorry! We're out of Gumballs!");
}
} else {
System.out.println("Crank will not turn without a Quarter!");
}
}

}
33 changes: 33 additions & 0 deletions lab10/GumballMachineV1/src/QTR50.aj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public aspect QTR50 {

// implement advice for getTenant
Object around(GumballMachine m) : target(m) && call(String GumballMachine.getTenant(..)) {
return "QTR50" ;
}

// implement advice for insertQuarter
after(GumballMachine m): target(m) && call(void GumballMachine.insertQuarter(..)) {
if (m.getCoinValue() < 50) {
m.setCoinValue(m.getCoinValue() + 25);
System.out.println("A quarter has been inserted");
} else {
System.out.println("There are already quarters in the slot");
}
}

// implement advice for turnTheCrank
after(GumballMachine m): target(m) && call(void GumballMachine.turnTheCrank(..)) {
if (m.getCoinValue() == 50) {
m.setCoinValue(0);
if (m.getCount() > 0) {
System.out.println("Here is your Gumball! Enjoy!");
m.setCount(m.getCount() - 1);
} else {
System.out.println("Sorry! We're out of Gumballs!");
}
} else {
System.out.println("Crank will not turn without enough Quarters!");
}
}

}
Binary file added lab10/GumballMachineV1_C25_Q25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lab10/GumballMachineV1_C50_COINS50.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lab10/GumballMachineV1_C50_QTR50.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions lab10/GumballMachineV2/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="ONEQTR.aj|COST25.aj|TWOQTR.aj|CRANKMODEL.aj" kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
40 changes: 40 additions & 0 deletions lab10/GumballMachineV2/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GumballMachineV2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>de.ovgu.featureide.core.extensibleFeatureProjectBuilder</name>
<arguments>
<dictionary>
<key>build</key>
<value>src</value>
</dictionary>
<dictionary>
<key>composer</key>
<value>de.ovgu.featureide.core.composer.aspectj</value>
</dictionary>
<dictionary>
<key>equations</key>
<value>configs</value>
</dictionary>
<dictionary>
<key>source</key>
<value>src</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>de.ovgu.featureide.core.featureProjectNature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions lab10/GumballMachineV2/configs/default.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SLOTMODEL
COST50
Loading

0 comments on commit efcdfe1

Please sign in to comment.