-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
390 additions
and
15 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
code-samples/03-Design-Patterns/03-strategy/src/main/java/com/algogrit/java/App.java
This file was deleted.
Oops, something went wrong.
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
code-samples/03-Design-Patterns/06-bridge/src/main/java/com/algogrit/java/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.algogrit.java; | ||
|
||
/** | ||
* Hello world! | ||
* | ||
*/ | ||
public class App | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
// System.out.println( "Hello World!" ); | ||
|
||
Vehicle dieselCar = new Car(new DieselEngine()); | ||
|
||
dieselCar.runsOn(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
code-samples/03-Design-Patterns/06-bridge/src/main/java/com/algogrit/java/Car.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.algogrit.java; | ||
|
||
// PetrolEngine | ||
// DieselEngine | ||
// HybridEngine | ||
// ElectricEngine | ||
|
||
public class Car implements Vehicle { | ||
Engine engine; | ||
|
||
public Car() { | ||
this.engine = new ElectricEngine(); | ||
} | ||
|
||
public Car(Engine engine) { | ||
this.engine = engine; | ||
} | ||
|
||
public void runsOn() { | ||
System.out.println("Car runs on: " + engine.getFuelType()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
code-samples/03-Design-Patterns/06-bridge/src/main/java/com/algogrit/java/DieselEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.algogrit.java; | ||
|
||
public class DieselEngine implements Engine { | ||
public String getFuelType() { | ||
return "Diesel"; | ||
}; | ||
} |
7 changes: 7 additions & 0 deletions
7
...-samples/03-Design-Patterns/06-bridge/src/main/java/com/algogrit/java/ElectricEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.algogrit.java; | ||
|
||
public class ElectricEngine implements Engine { | ||
public String getFuelType() { | ||
return "Electricity"; | ||
}; | ||
} |
5 changes: 5 additions & 0 deletions
5
code-samples/03-Design-Patterns/06-bridge/src/main/java/com/algogrit/java/Engine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.algogrit.java; | ||
|
||
public interface Engine { | ||
String getFuelType(); | ||
} |
10 changes: 10 additions & 0 deletions
10
code-samples/03-Design-Patterns/06-bridge/src/main/java/com/algogrit/java/MotorCycle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.algogrit.java; | ||
|
||
// PetrolEngine | ||
// ElectricEngine | ||
|
||
public class MotorCycle implements Vehicle { | ||
public void runsOn() { | ||
System.out.println("MotorCycle runs on: "); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
code-samples/03-Design-Patterns/06-bridge/src/main/java/com/algogrit/java/Truck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.algogrit.java; | ||
|
||
// DieselEngine | ||
// ElectricEngine | ||
|
||
public class Truck implements Vehicle { | ||
Engine engine; | ||
|
||
public void runsOn() { | ||
System.out.println("Truck runs on: "); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
code-samples/03-Design-Patterns/06-bridge/src/main/java/com/algogrit/java/Vehicle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.algogrit.java; | ||
|
||
public interface Vehicle { | ||
void runsOn(); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.algogrit.java</groupId> | ||
<artifactId>template</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>template</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>3.7.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
code-samples/03-Design-Patterns/10-template/src/main/java/com/algogrit/java/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.algogrit.java; | ||
|
||
/** | ||
* Hello world! | ||
* | ||
*/ | ||
public class App | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
House glassHouse = new GlassHouse(); | ||
glassHouse.build(); | ||
|
||
House concreteHouse = new GlassHouse(); | ||
concreteHouse.build(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...samples/03-Design-Patterns/10-template/src/main/java/com/algogrit/java/ConcreteHouse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.algogrit.java; | ||
|
||
public class ConcreteHouse extends House { | ||
@Override | ||
public void layWalls() { | ||
System.out.println("Lay concrete walls"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
code-samples/03-Design-Patterns/10-template/src/main/java/com/algogrit/java/GlassHouse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.algogrit.java; | ||
|
||
public class GlassHouse extends House { | ||
@Override | ||
public void layWalls() { | ||
System.out.println("Lay glass walls"); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
code-samples/03-Design-Patterns/10-template/src/main/java/com/algogrit/java/House.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.algogrit.java; | ||
|
||
public abstract class House { | ||
public void build() { | ||
System.out.println("Laying foundation..."); | ||
this.layWalls(); | ||
System.out.println("Lay the roof"); | ||
System.out.println("Place windows and doors"); | ||
System.out.println("Finish with interiors"); | ||
}; | ||
|
||
abstract void layWalls(); | ||
} |
20 changes: 20 additions & 0 deletions
20
code-samples/03-Design-Patterns/10-template/src/test/java/com/algogrit/java/AppTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.algogrit.java; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
{ | ||
/** | ||
* Rigorous Test :-) | ||
*/ | ||
@Test | ||
public void shouldAnswerWithTrue() | ||
{ | ||
assertTrue( true ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="EclipseModuleManager"> | ||
<conelement value="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" /> | ||
<src_description expected_position="2"> | ||
<src_folder value="file://$MODULE_DIR$/src/main/java" expected_position="0" /> | ||
<src_folder value="file://$MODULE_DIR$/src/test/java" expected_position="1" /> | ||
<src_folder value="file://$MODULE_DIR$/target/generated-sources/annotations" expected_position="4" /> | ||
<src_folder value="file://$MODULE_DIR$/target/generated-test-sources/test-annotations" expected_position="5" /> | ||
</src_description> | ||
</component> | ||
<component name="NewModuleRootManager"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/annotations" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/target/generated-test-sources/test-annotations" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" /> | ||
<orderEntry type="library" name="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" level="application" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.algogrit.java</groupId> | ||
<artifactId>iterator</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>iterator</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>3.7.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
20 changes: 20 additions & 0 deletions
20
code-samples/03-Design-Patterns/11-iterator/src/main/java/com/algogrit/java/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.algogrit.java; | ||
|
||
/** | ||
* Hello world! | ||
* | ||
*/ | ||
public class App | ||
{ | ||
public static void main( String[] args ) | ||
{ | ||
IntegerBox box = new IntegerBox(); | ||
|
||
for (int i = 0; i < 10; i++) { | ||
box.add(i); | ||
} | ||
for (Integer value : box) { | ||
System.out.println(value); | ||
} | ||
} | ||
} |
Oops, something went wrong.