Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
paulnguyen committed Feb 6, 2022
1 parent 245fe7a commit de80063
Show file tree
Hide file tree
Showing 351 changed files with 1,267 additions and 100 deletions.
37 changes: 37 additions & 0 deletions demos/demo9/command/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

public class Client {

private String helloMessage = "Hello!" ;
private Menu appMenu = new Menu() ;

public Menu getMenu() {
return appMenu ;
}

public void runSetup() {
String helloMessage = "Ciao!" ;
MenuItem hello = new MenuItem() ;
Command sayHello = new ConcreteCommand();
sayHello.setReceiver(
new Receiver() {
public void doAction() {
System.out.println( helloMessage );
}
}
);
hello.setCommand( sayHello );
appMenu.addMenuItem(hello, "hello");
}

public static void main( String [] args )
{
String helloMessage = "Bonjour!" ;
Client c = new Client() ;
c.runSetup() ;
Menu m = c.getMenu() ;
m.selectMenuItem("hello") ;
}


}

7 changes: 7 additions & 0 deletions demos/demo9/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

public interface Command {

public abstract void execute();
public abstract void setReceiver(Receiver target);
}

15 changes: 15 additions & 0 deletions demos/demo9/command/ConcreteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

public class ConcreteCommand implements Command {

private Receiver theReceiver ;

public void execute() {
theReceiver.doAction();
}

public void setReceiver(Receiver target) {
theReceiver = target ;
}

}

7 changes: 7 additions & 0 deletions demos/demo9/command/Invoker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

public interface Invoker {

public abstract void setCommand(Command cmd);
public abstract void invoke();
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ all: clean
clean:
find . -name "*.class" -exec rm -rf {} \;

compile:
javac *.java

run:
java -cp . Main
javac *.java
java Client

21 changes: 21 additions & 0 deletions demos/demo9/command/Menu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import java.util.HashMap;

public class Menu {

private HashMap<String, MenuItem> menuItems = new HashMap<String, MenuItem>() ;

public void addMenuItem( MenuItem item, String key ) {
menuItems.put( key, item ) ;
}

public void selectMenuItem( String key ) {
MenuItem item = menuItems.get(key) ;
if ( item != null )
item.invoke();
else
System.out.println( "Menu Item Not Found: " + key );
}

}

15 changes: 15 additions & 0 deletions demos/demo9/command/MenuItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

public class MenuItem implements Invoker {

private Command theCommand ;

public void setCommand(Command cmd) {
theCommand = cmd ;
}

public void invoke() {
theCommand.execute();
}

}

7 changes: 7 additions & 0 deletions demos/demo9/command/Receiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

public interface Receiver {

public void doAction() ;

}

39 changes: 0 additions & 39 deletions demos/demo9/lambda/8.higher-order/Main.java

This file was deleted.

46 changes: 0 additions & 46 deletions demos/demo9/lambda/9.currying/Main.java

This file was deleted.

11 changes: 0 additions & 11 deletions demos/demo9/lambda/9.currying/Makefile

This file was deleted.

25 changes: 25 additions & 0 deletions demos/gaspump/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
all: clean

clean:
find . -name "*.class" -exec rm -rf {} \;
rm -rf build/*
rm -f *.log

init:
gradle init
mkdir -p libs
mkdir -p src/main/java
mkdir -p src/test/java

compile:
gradle build -x test --warning-mode all

test:
gradle test

jar: compile
gradle shadowJar

run: jar
java -cp build/libs/gaspump-all.jar Main 2>debug.log

65 changes: 65 additions & 0 deletions demos/gaspump/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* This build file was auto generated by running the Gradle 'init' task
* by 'pnguyen' at '7/30/18 6:20 PM' with Gradle 3.2.1
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/3.2.1/userguide/tutorial_java_projects.html
*/

/*
// Apply the java plugin to add support for Java
apply plugin: 'java'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.21'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}
*/


buildscript {
dependencies {
classpath fileTree(dir: 'libs', include: '*.jar')
}
}

plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '2.0.4'
}

repositories {
jcenter()
}

dependencies {
runtime fileTree(dir: 'libs', include: '*.jar')
compile fileTree(dir: 'libs', include: '*.jar')
compile group: 'junit', name: 'junit', version: '4.+'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
testCompile group: 'junit', name: 'junit', version: '4.+'
}

shadowJar {
baseName = 'gaspump'
}





21 changes: 21 additions & 0 deletions demos/gaspump/debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# lines: 1
line # 01
line len: 23
pad size: 9
new line: Do you want a Car Wash?
new message: Do you want a Car Wash?

# lines: 1
line # 01
line len: 23
pad size: 9
new line: Select Car Wash Package
new message: Select Car Wash Package

# lines: 1
line # 01
line len: 16
pad size: 12
new line: Credit or Debit?
new message: Credit or Debit?

Binary file added demos/gaspump/gaspump-states.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 demos/gaspump/gaspump.asta
Binary file not shown.
Loading

0 comments on commit de80063

Please sign in to comment.