Skip to content

Commit

Permalink
Merge pull request #1618 from umple/ExampleUpdates
Browse files Browse the repository at this point in the history
Example updates Fixes #1605 Fixes #1604
  • Loading branch information
TimLethbridge committed Aug 2, 2020
2 parents 1e2e91f + d2eb9ef commit 60569f3
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 20 deletions.
2 changes: 1 addition & 1 deletion UmpleToJava/UmpleTLTemplates/class_MethodDeclaration.ump
Expand Up @@ -52,7 +52,7 @@ class UmpleToJava {

append(realSb,"\n {");

append(realSb,"\n Vector v = new Vector({0});", aMethod.numberOfMethodParameters());
append(realSb,"\n Vector<Object> v = new Vector<Object>({0});", aMethod.numberOfMethodParameters());
for ( int i=0; i < aMethod.numberOfMethodParameters(); i++)
{
append(realSb,"\n v.add({0}, {1});",i, aMethod.getMethodParameter(i).getName());
Expand Down
Expand Up @@ -66,7 +66,7 @@ class UmpleToJava {

if (!event.getArgs().equals(""))
{
append(realSb,"\n Vector v = new Vector({0});", event.getParams().size());
append(realSb,"\n Vector<Object> v = new Vector<Object>({0});", event.getParams().size());
for ( int i=0; i < event.getParams().size(); i++)
{
append(realSb,"\n v.add({0}, {1});",i, event.getParam(i).getName());
Expand Down Expand Up @@ -160,7 +160,7 @@ class UmpleToJava {
if (!e.getArgs().equals(""))
{
evList.add(e.getName());
append(realSb,"\n Vector v = new Vector({0});", e.getParams().size());
append(realSb,"\n Vector<Object> v = new Vector<Object>({0});", e.getParams().size());
for ( int i=0; i < e.getParams().size(); i++)
{
append(realSb,"\n v.add({0}, {1});",i, e.getParam(i).getName());
Expand Down
7 changes: 7 additions & 0 deletions cruise.umple/src/Main_Code.ump
Expand Up @@ -222,6 +222,13 @@ class UmpleConsoleMain
}

String successWord = compileSuccess ? "Success! " : "";

if(compileSuccess) {
for (UmpleClass mainClass: CodeCompiler.getMainClasses(model)) {
System.out.println(" Main method found. Run java "+mainClass.getName());
}
}

System.out.println(successWord + "Processed "+ cfg.getUmpleFile() + ".");
cfg.getLinkedFilesAsFile().stream()
.filter(File::exists)
Expand Down
Expand Up @@ -235,7 +235,7 @@ public class LightFixture implements Runnable

public void turnDimmer (Integer lightval)
{
Vector v = new Vector(1);
Vector<Object> v = new Vector<Object>(1);
v.add(0, lightval);
pool.put(new Message(MessageType.turnDimmer_M, v));
}
Expand Down
Expand Up @@ -207,7 +207,7 @@ public class LightFixture implements Runnable

public void turnDimmer (Integer lightval)
{
Vector v = new Vector(1);
Vector<Object> v = new Vector<Object>(1);
v.add(0, lightval);
queue.put(new Message(MessageType.turnDimmer_M, v));
}
Expand Down
Expand Up @@ -207,7 +207,7 @@ public class LightFixture implements Runnable

public void turnDimmer (Integer lightval,Double grade)
{
Vector v = new Vector(2);
Vector<Object> v = new Vector<Object>(2);
v.add(0, lightval);
v.add(1, grade);
queue.put(new Message(MessageType.turnDimmer_M, v));
Expand Down
10 changes: 5 additions & 5 deletions umpleonline/download_eclipse_umple_plugin.html
Expand Up @@ -136,10 +136,10 @@ <h3>C. Running UmpleOnline in your own computer's Docker installation</h3>
docker pull umple/umpleonline
</pre>

<li>In a terminal (console), invoke the image (you can change the 8000 to be another port both here and in the next instruction if you prefer):
<li>In a terminal (console), invoke the image (you can change the first 8000 to be another port both here and in the next instruction if you prefer):

<pre>
docker run --rm -ti -p 8000:80 umple/umpleonline >/dev/null
docker run --rm -ti -p 8000:8000 umple/umpleonline >/dev/null
</pre>

<li>In a web browser, go to the following link: <a href="http://localhost:8000/umple.php">http://localhost:8000/umple.php</a><br/>&nbsp;<br/>
Expand All @@ -155,9 +155,9 @@ <h3>C. Running UmpleOnline in your own computer's Docker installation</h3>
<ul>

<li> Run docker as:
docker run --rm -ti -p 8000:80 umple/umpleonline >/dev/null
docker run --rm -ti -p 8000:8000 umple/umpleonline >/dev/null
<pre>
docker run --rm -ti -p 8000:80 -v {dir}:{dir:t} umple/umpleonline >/dev/null
docker run --rm -ti -p 8000:8000 -v {dir}:{dir:t} umple/umpleonline >/dev/null
</pre>

<li> and open your browser to href="http://localhost:8000/umple.php">http://localhost:8000/umple.php?model={dir:t}
Expand Down Expand Up @@ -187,7 +187,7 @@ <h3>C. Running UmpleOnline in your own computer's Docker installation</h3>

</ul>

<p>The Docker UmpleOnline option is not designed for large-scale projects; for those use the command-line (A) or Eclipse (B) downloads above. However, the Docker option can
<p>More information about Umple in Docker can be found at <a href="http://docker.umple.org">http://docker.umple.org</a></p>



Expand Down
182 changes: 182 additions & 0 deletions umpleonline/ump/Dishwasher.ump
@@ -0,0 +1,182 @@
// This example illustrates a simple simulation of a Dishwasher
// Author: Timothy Lethbridge
// The simulation accepts input of a cycle to run,
// and also c to cancel and q to quit (see the main program)
// The commands do and dc can also be used to simulate
// door opening and closing
// These inputs are converted into methods that trigger events
// on state machines
//
// There are three state machines:
// core operates the cycles
// states: active (has substates), draining, idle and suspended
// timingSm runs a timer that updates the display
// doorSm tracks the door state and helps ensure pausing when open
// Note that the main program and the two state machines operate
// in separate threads.

class Dishwasher {
// This will be used to display the time remaining and
// track that time
// In a real system, this would be in minutes,
// but it will be seconds in this simulation
Integer minutesRemaining = 0;

// Time in cycle segments we are not timing yet
Integer subsequentTime = 0;

// Fixed times for various tasks
const Integer PrewashTime=5;
const Integer WashTime=10;
const Integer RinseTime=5;

// This will be set if a timed operation needs to not count down,
// e.g. when the door is open
Boolean paused = false;

queued doorSm {
closed {
openDoor / {paused = true;} -> open;
}
open {
closeDoor / {paused = false;}-> closed;
}
}

// Central state machine for system state
queued core {
idle {
// in this state the dishwasher can accept a cycle command
entry / {display("Enter cycle to run (n,f,r,c,q)");}
normal [!paused] / {minutesRemaining = PrewashTime;} -> active;
fast [!paused]
/ {minutesRemaining = WashTime;} -> mainWash; // skips prewash
rinse [!paused]
/ {minutesRemaining = RinseTime;}-> rinsing; // skips wash
}
active {
cancel
/ {display("CANCELLING");startTimer(1,0);} -> draining;
openDoor -> suspended;
preWash {
// The normal cycle starts with the use of pure water
// to get most of the dirt off
entry / {display("PREWASH");}
entry
/ {startTimer(minutesRemaining,WashTime+RinseTime);}
timerEnded [minutesRemaining == 0]
/ {minutesRemaining=WashTime;} -> mainWash;
}
mainWash {
entry / {display("MAIN WASH");}
entry / {startTimer(minutesRemaining,RinseTime);}
timerEnded [minutesRemaining == 0]
/ {minutesRemaining=RinseTime;} -> rinsing;
}
rinsing {
entry / {display("RINSING");}
entry / {startTimer(minutesRemaining,0);}
timerEnded [minutesRemaining == 0] -> draining;
}
}

draining {
entry / {display("DRAINING");}
after(1) -> idle;
}
suspended {
entry / {display("SUSPENDED - door open "
+(minutesRemaining+subsequentTime)+" left");}
closeDoor -> active.H;
exit / {display("RESUMING");}
}
}



queued timingSm {
idle {
startTimer(int numMins, int subsequentMins) -> countingDown;
}
countingDown {
startTimer(int numMins, int subsequentMins) -> countingDown;

after(1.0) [minutesRemaining >= 1 && ! paused] / {
displayTime();
minutesRemaining--;
} -> countingDown;

after(1.0) [minutesRemaining <= 0] -> idle;

openDoor -> idle;

exit / {timerEnded();}
}
}

before startTimer {
minutesRemaining = numMins;
subsequentTime = subsequentMins;
}

void display(String s) {
System.out.println(s);
}

void displayTime() {
System.out.println("DISPLAY: "+(minutesRemaining+subsequentTime));
}

// This main program allows the user to enter commands to change state
// The user can therefore operate the dishwasher in simulation
// with real timing
public static void main(String[] argv) {
Dishwasher dw = new Dishwasher();
System.out.println("c/q/do can interrupt to cancel/quit/door open");
System.out.println("dc to close door");
Scanner s = new Scanner(System.in);
String command ="";
while(true) {
while(!s.hasNextLine()) {
try { Thread.sleep(1000); }
catch (InterruptedException e) {
dw.display("Quitting due to end of input");
System.exit(0);
}
}
command = s.nextLine();

switch(command) {
case "q":
dw.display("Quitting due to q command");
System.exit(0);
case "n":
dw.normal();
break;
case "f":
dw.fast();
break;
case "r":
dw.rinse();
break;
case "c":
dw.cancel();
break;
case "dc":
dw.closeDoor();
break;
case "do":
dw.openDoor();
break;

default:
break;
}
}
}
}
//$?[End_of_model]$?
// @@@skipcppcompile - Contains Java Code
// @@@skipphpcompile - Contains Java Code
// @@@skiprubycompile - Contains Java Code

8 changes: 4 additions & 4 deletions umpleonline/ump/Phone.ump
Expand Up @@ -8,11 +8,11 @@ class PhoneSystemSimulation {
// lazy PhoneLine[] lines;
1 -- * PhoneLine lines;
after constructor {
addLine(new PhoneLine("line1","Bruce",this));
addLine(new PhoneLine("line2","Ralph",this));
addLine(new PhoneLine("line1","Alex",this));
addLine(new PhoneLine("line2","Thomas",this));
addLine(new PhoneLine("line3","Victoria",this));
addLine(new PhoneLine("line4","Vicki",this));
addLine(new PhoneLine("line5","Agnes",this));
addLine(new PhoneLine("line4","Samantha ",this));
addLine(new PhoneLine("line5","Karen",this));
}

static PhoneSystemSimulation s;
Expand Down

0 comments on commit 60569f3

Please sign in to comment.