Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cbb2580ce9 |
@ -1,10 +1,4 @@
|
||||
import net.itsthesky.projetbut2.dip.DIPClient;
|
||||
import net.itsthesky.projetbut2.ocp.OCPClient;
|
||||
|
||||
void main(String[] args) {
|
||||
if (args.length == 0) return;
|
||||
|
||||
if (args[0].equalsIgnoreCase("ocp")) OCPClient.main();
|
||||
else if (args[0].equalsIgnoreCase("dip")) DIPClient.main();
|
||||
else IO.println("Invalid argument: '" + args[0] + "'");
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
package net.itsthesky.projetbut2.dip;
|
||||
|
||||
public class BackEndDeveloper implements Developer {
|
||||
|
||||
@Override
|
||||
public void develop() {
|
||||
IO.println("I write Java code !");
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
package net.itsthesky.projetbut2.dip;
|
||||
|
||||
public final class DIPClient {
|
||||
|
||||
public static void main() {
|
||||
Project project = new Project();
|
||||
project.implement();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package net.itsthesky.projetbut2.dip;
|
||||
|
||||
public interface Developer {
|
||||
|
||||
void develop();
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package net.itsthesky.projetbut2.dip;
|
||||
|
||||
public class FrontEndDeveloper implements Developer{
|
||||
@Override
|
||||
public void develop() {
|
||||
IO.println("I write Javascript code !");
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package net.itsthesky.projetbut2.dip;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Project {
|
||||
|
||||
private final List<Developer> developers = new ArrayList<>();
|
||||
|
||||
public Project() {
|
||||
developers.add(new BackEndDeveloper());
|
||||
developers.add(new FrontEndDeveloper());
|
||||
}
|
||||
|
||||
public void implement() {
|
||||
for (var developer : developers) {
|
||||
developer.develop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package net.itsthesky.projetbut2.model.route;
|
||||
|
||||
public class SuivreAlizés implements SuivreRoute {
|
||||
|
||||
@Override
|
||||
public void suivreRoute() {
|
||||
System.out.println("Suivi de route par les alizés");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package net.itsthesky.projetbut2.model.route;
|
||||
|
||||
public class SuivreOrthodromie implements SuivreRoute {
|
||||
@Override
|
||||
public void suivreRoute() {
|
||||
IO.println("Suivi de route par orthodromie");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package net.itsthesky.projetbut2.model.route;
|
||||
|
||||
public interface SuivreRoute {
|
||||
|
||||
void suivreRoute();
|
||||
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package net.itsthesky.projetbut2.model.voilier;
|
||||
|
||||
public class Monocoque extends Voilier {
|
||||
|
||||
public Monocoque(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Monocoque{" + super.toString() + '}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package net.itsthesky.projetbut2.model.voilier;
|
||||
|
||||
public class Multicoque extends Voilier {
|
||||
|
||||
public Multicoque(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Multicoque{" + super.toString() + '}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package net.itsthesky.projetbut2.model.voilier;
|
||||
|
||||
import net.itsthesky.projetbut2.model.route.SuivreRoute;
|
||||
|
||||
public abstract class Voilier {
|
||||
|
||||
protected String nom;
|
||||
protected SuivreRoute suivreRoute;
|
||||
|
||||
public void appliquerSuivreRoute() {
|
||||
suivreRoute.suivreRoute();
|
||||
}
|
||||
|
||||
public void setSuivreRoute(SuivreRoute suivreRoute) {
|
||||
this.suivreRoute = suivreRoute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return nom;
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp;
|
||||
|
||||
import net.itsthesky.projetbut2.ocp.base.Color;
|
||||
import net.itsthesky.projetbut2.ocp.base.Product;
|
||||
|
||||
public class ColorCriteria implements Criteria<Product> {
|
||||
|
||||
private final Color color;
|
||||
public ColorCriteria(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfied(Product product) {
|
||||
return product.color == color;
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp;
|
||||
|
||||
public interface Criteria<Product> {
|
||||
|
||||
boolean isSatisfied(Product product);
|
||||
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp;
|
||||
|
||||
import net.itsthesky.projetbut2.ocp.base.Product;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class MultipleCriteria implements Criteria<Product> {
|
||||
|
||||
private final Criteria<Product>[] criteria;
|
||||
public MultipleCriteria(Criteria<Product>... criteria) {
|
||||
this.criteria = criteria;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfied(Product product) {
|
||||
return Stream.of(criteria).allMatch(c -> c.isSatisfied(product));
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp;
|
||||
|
||||
import net.itsthesky.projetbut2.ocp.base.Product;
|
||||
|
||||
public class NameCriteria implements Criteria<Product> {
|
||||
|
||||
private final String name;
|
||||
public NameCriteria(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfied(Product product) {
|
||||
return product.name.contains(name);
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp;
|
||||
|
||||
import net.itsthesky.projetbut2.ocp.base.Color;
|
||||
import net.itsthesky.projetbut2.ocp.base.Product;
|
||||
import net.itsthesky.projetbut2.ocp.base.Size;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class OCPClient {
|
||||
|
||||
public static void main() {
|
||||
Product apple = new Product("Apple", Color.GREEN, Size.SMALL);
|
||||
Product tree = new Product("Tree", Color.GREEN, Size.LARGE);
|
||||
Product house = new Product("House", Color.BLUE, Size.LARGE);
|
||||
|
||||
List<Product> products = List.of(apple, tree, house);
|
||||
|
||||
ProductFilter filter = new ProductFilter();
|
||||
System.out.println("Green products : ");
|
||||
filter.filter(products, new MultipleCriteria(new ColorCriteria(Color.GREEN), new SizeCriteria(Size.SMALL)))
|
||||
.forEach(product -> System.out.println(" - " + product.name + " is green and small"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp;
|
||||
|
||||
import net.itsthesky.projetbut2.ocp.base.Product;
|
||||
|
||||
public class PriceRangeCriteria implements Criteria<Product> {
|
||||
|
||||
private final double minPrice;
|
||||
private final double maxPrice;
|
||||
public PriceRangeCriteria(double minPrice, double maxPrice) {
|
||||
this.minPrice = minPrice;
|
||||
this.maxPrice = maxPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfied(Product product) {
|
||||
return product.price >= minPrice && product.price <= maxPrice;
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp;
|
||||
|
||||
import net.itsthesky.projetbut2.ocp.base.Product;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ProductFilter {
|
||||
|
||||
public Stream<Product> filter(List<Product> products, Criteria<Product> criteria) {
|
||||
return products.stream().filter(criteria::isSatisfied);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp;
|
||||
|
||||
import net.itsthesky.projetbut2.ocp.base.Product;
|
||||
import net.itsthesky.projetbut2.ocp.base.Size;
|
||||
|
||||
public class SizeCriteria implements Criteria<Product> {
|
||||
|
||||
private final Size size;
|
||||
public SizeCriteria(Size size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfied(Product product) {
|
||||
return product.size == size;
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp.base;
|
||||
|
||||
public enum Color {
|
||||
RED, GREEN, BLUE
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp.base;
|
||||
|
||||
public class Product {
|
||||
|
||||
public String name;
|
||||
public Color color;
|
||||
public Size size;
|
||||
public double price;
|
||||
|
||||
public Product(String name, Color color, Size size, double price) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.size = size;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Product(String name, Color color, Size size) {
|
||||
this(name, color, size, 0);
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package net.itsthesky.projetbut2.ocp.base;
|
||||
|
||||
public enum Size {
|
||||
SMALL, MEDIUM, LARGE, HUGE
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package net.itsthesky.projetbut2.model.voilier;
|
||||
|
||||
import net.itsthesky.projetbut2.model.route.SuivreAlizés;
|
||||
import net.itsthesky.projetbut2.model.route.SuivreOrthodromie;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class VoilierTest {
|
||||
|
||||
private Voilier monocoque;
|
||||
private Voilier multicoque;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
monocoque = new Monocoque("TestVoilier");
|
||||
multicoque = new Multicoque("TestVoilier");
|
||||
|
||||
monocoque.setSuivreRoute(new SuivreAlizés());
|
||||
multicoque.setSuivreRoute(new SuivreOrthodromie());
|
||||
}
|
||||
|
||||
@Test
|
||||
void appliquerSuivreRoute() {
|
||||
monocoque.appliquerSuivreRoute();
|
||||
multicoque.appliquerSuivreRoute();
|
||||
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setSuivreRoute() {
|
||||
monocoque.setSuivreRoute(new SuivreOrthodromie());
|
||||
multicoque.setSuivreRoute(new SuivreAlizés());
|
||||
|
||||
monocoque.appliquerSuivreRoute();
|
||||
multicoque.appliquerSuivreRoute();
|
||||
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("Monocoque{TestVoilier}", monocoque.toString());
|
||||
assertEquals("Multicoque{TestVoilier}", multicoque.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user