Added:
/HybridAutomobileExample/.classpath
/HybridAutomobileExample/.project
/HybridAutomobileExample/.settings
/HybridAutomobileExample/.settings/org.eclipse.jdt.core.prefs
/HybridAutomobileExample/src
/HybridAutomobileExample/src/p
/HybridAutomobileExample/src/p/CarComponent.java
/HybridAutomobileExample/src/p/Current.java
/HybridAutomobileExample/src/p/Dashboard.java
/HybridAutomobileExample/src/p/DieselEngine.java
/HybridAutomobileExample/src/p/ElectricMotor.java
/HybridAutomobileExample/src/p/Energy.java
/HybridAutomobileExample/src/p/Fuel.java
/HybridAutomobileExample/src/p/FuelCell.java
/HybridAutomobileExample/src/p/Highway.java
/HybridAutomobileExample/src/p/HybridAutomobile.java
/HybridAutomobileExample/src/p/SpeedingViolationPrevention.aj
=======================================
--- /dev/null
+++ /HybridAutomobileExample/.classpath Sun Aug 1 21:51:12 2010
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con"
path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
=======================================
--- /dev/null
+++ /HybridAutomobileExample/.project Sun Aug 1 21:51:12 2010
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>HybridAutomobileExample</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <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>
+ </natures>
+</projectDescription>
=======================================
--- /dev/null
+++ /HybridAutomobileExample/.settings/org.eclipse.jdt.core.prefs Sun Aug
1 21:51:12 2010
@@ -0,0 +1,12 @@
+#Mon Jul 05 12:28:13 JST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/CarComponent.java Sun Aug 1 21:51:12
2010
@@ -0,0 +1,6 @@
+package p;
+
+public interface CarComponent {
+
+ HybridAutomobile getCar();
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/Current.java Sun Aug 1 21:51:12 2010
@@ -0,0 +1,5 @@
+package p;
+
+public interface Current extends Energy {
+
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/Dashboard.java Sun Aug 1 21:51:12 2010
@@ -0,0 +1,13 @@
+package p;
+
+public class Dashboard {
+
+ private HybridAutomobile car;
+
+ public void update() {
+ this.display(car.getOverallSpeed());
+ }
+
+ public void display(double d) {
+ }
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/DieselEngine.java Sun Aug 1 21:51:12
2010
@@ -0,0 +1,15 @@
+package p;
+
+public class DieselEngine implements CarComponent {
+
+ private HybridAutomobile car;
+
+ public HybridAutomobile getCar() {
+ return car;
+ }
+
+ public void increase(Fuel fuel) {
+ //...
+ this.car.notifyChangeIn(fuel);
+ }
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/ElectricMotor.java Sun Aug 1 21:51:12
2010
@@ -0,0 +1,15 @@
+package p;
+
+public class ElectricMotor implements CarComponent {
+
+ private HybridAutomobile car;
+
+ public void increase(Current current) {
+ //...
+ this.getCar().notifyChangeIn(current);
+ }
+
+ public HybridAutomobile getCar() {
+ return car;
+ }
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/Energy.java Sun Aug 1 21:51:12 2010
@@ -0,0 +1,7 @@
+package p;
+
+public interface Energy {
+
+ public double calculateDelta(HybridAutomobile hybridAutomobile);
+
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/Fuel.java Sun Aug 1 21:51:12 2010
@@ -0,0 +1,4 @@
+package p;
+
+public interface Fuel extends Energy {
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/FuelCell.java Sun Aug 1 21:51:12 2010
@@ -0,0 +1,12 @@
+package p;
+
+public class FuelCell {
+
+ private HybridAutomobile car;
+
+ public void increase(double mph) {
+ // ...
+ this.car.notifyChangeIn(mph);
+ }
+
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/Highway.java Sun Aug 1 21:51:12 2010
@@ -0,0 +1,7 @@
+package p;
+
+public class Highway {
+
+ static double getSpeedLimit() {return 0;};
+
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/HybridAutomobile.java Sun Aug 1
21:51:12 2010
@@ -0,0 +1,30 @@
+package p;
+
+public class HybridAutomobile {
+
+ private double overallSpeed;
+ //...
+ //Sets the new speed for changes in fuel.
+ public void notifyChangeIn(Fuel fuel) {
+ this.overallSpeed +=
+ fuel.calculateDelta(this);
+ /* Update attached observers ... */
+ }
+
+ //Sets the new speed for changes in electricity.
+ public void notifyChangeIn(Current current) {
+ this.overallSpeed +=
+ current.calculateDelta(this);
+ /* Update attached observers ... */
+ }
+
+ //Sets the new speed directly.
+ public void notifyChangeIn(double mph) {
+ this.overallSpeed += mph;
+ /* Update attached observers ... */
+ }
+
+ public double getOverallSpeed() {
+ return overallSpeed;
+ }
+}
=======================================
--- /dev/null
+++ /HybridAutomobileExample/src/p/SpeedingViolationPrevention.aj Sun Aug
1 21:51:12 2010
@@ -0,0 +1,24 @@
+package p;
+
+public aspect SpeedingViolationPrevention {
+ void around(CarComponent component, Energy energy) :
+ execution(void increase(Energy+)) && this(component) && args(energy) {
+
+ // get the current speed limit
+ double speedLimit = Highway.getSpeedLimit();
+
+ // get the car's current speed.
+ HybridAutomobile car = component.getCar();
+ double currentSpeed = car.getOverallSpeed();
+
+ //get the amount to add.
+ double changeInMPH = energy.calculateDelta(car);
+
+ double newSpeed = currentSpeed + changeInMPH;
+
+ if ( newSpeed <= speedLimit )
+ proceed(component, energy);
+ }
+
+ // execution(void increase(Energy+)) || execution(void increase(double)){
+}