From 17d960fd3b38f0be0aa90a72ef3d16d1e7dd7f1b Mon Sep 17 00:00:00 2001 From: ItsTheSky Date: Mon, 1 Dec 2025 09:39:29 +0100 Subject: [PATCH] Implement developer classes and criteria for product filtering --- .../java/net/itsthesky/projetbut2/Main.java | 4 +- .../projetbut2/dip/BackEndDeveloper.java | 9 ++ .../itsthesky/projetbut2/dip/DIPClient.java | 10 ++ .../itsthesky/projetbut2/dip/Developer.java | 7 ++ .../projetbut2/dip/FrontEndDeveloper.java | 9 ++ .../net/itsthesky/projetbut2/dip/Project.java | 21 ++++ .../projetbut2/ocp/ColorCriteria.java | 17 +++ .../itsthesky/projetbut2/ocp/Criteria.java | 7 ++ .../projetbut2/ocp/MultipleCriteria.java | 18 +++ .../projetbut2/ocp/NameCriteria.java | 16 +++ .../itsthesky/projetbut2/ocp/OCPClient.java | 24 ++++ .../projetbut2/ocp/PriceRangeCriteria.java | 18 +++ .../projetbut2/ocp/ProductFilter.java | 14 +++ .../projetbut2/ocp/SizeCriteria.java | 17 +++ .../itsthesky/projetbut2/ocp/base/Color.java | 5 + .../projetbut2/ocp/base/Product.java | 20 +++ .../itsthesky/projetbut2/ocp/base/Size.java | 5 + .../qualdev/FindInstrumentTester.java | 115 ------------------ .../projetbut2/qualdev/Inventory.java | 54 -------- .../projetbut2/qualdev/model/Instrument.java | 64 ---------- .../qualdev/model/InstrumentSpec.java | 69 ----------- .../qualdev/model/Specification.java | 19 --- .../qualdev/model/specs/Builder.java | 14 --- .../qualdev/model/specs/InstrumentType.java | 11 -- .../projetbut2/qualdev/model/specs/Style.java | 10 -- .../projetbut2/qualdev/model/specs/Type.java | 8 -- .../projetbut2/qualdev/model/specs/Wood.java | 17 --- 27 files changed, 219 insertions(+), 383 deletions(-) create mode 100644 src/main/java/net/itsthesky/projetbut2/dip/BackEndDeveloper.java create mode 100644 src/main/java/net/itsthesky/projetbut2/dip/DIPClient.java create mode 100644 src/main/java/net/itsthesky/projetbut2/dip/Developer.java create mode 100644 src/main/java/net/itsthesky/projetbut2/dip/FrontEndDeveloper.java create mode 100644 src/main/java/net/itsthesky/projetbut2/dip/Project.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/ColorCriteria.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/Criteria.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/MultipleCriteria.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/NameCriteria.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/OCPClient.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/PriceRangeCriteria.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/ProductFilter.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/SizeCriteria.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/base/Color.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/base/Product.java create mode 100644 src/main/java/net/itsthesky/projetbut2/ocp/base/Size.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/FindInstrumentTester.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/Inventory.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/model/Instrument.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/model/InstrumentSpec.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/model/Specification.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/model/specs/Builder.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/model/specs/InstrumentType.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/model/specs/Style.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/model/specs/Type.java delete mode 100644 src/main/java/net/itsthesky/projetbut2/qualdev/model/specs/Wood.java diff --git a/src/main/java/net/itsthesky/projetbut2/Main.java b/src/main/java/net/itsthesky/projetbut2/Main.java index cdd73e6..4320f24 100644 --- a/src/main/java/net/itsthesky/projetbut2/Main.java +++ b/src/main/java/net/itsthesky/projetbut2/Main.java @@ -1,5 +1,5 @@ -import net.itsthesky.projetbut2.qualdev.FindInstrumentTester; +import net.itsthesky.projetbut2.dip.DIPClient; void main() { - FindInstrumentTester.main(new String[]{}); + DIPClient.main(); } \ No newline at end of file diff --git a/src/main/java/net/itsthesky/projetbut2/dip/BackEndDeveloper.java b/src/main/java/net/itsthesky/projetbut2/dip/BackEndDeveloper.java new file mode 100644 index 0000000..c4b2e70 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/dip/BackEndDeveloper.java @@ -0,0 +1,9 @@ +package net.itsthesky.projetbut2.dip; + +public class BackEndDeveloper implements Developer { + + public void develop() { + IO.println("I write Java code !"); + } + +} diff --git a/src/main/java/net/itsthesky/projetbut2/dip/DIPClient.java b/src/main/java/net/itsthesky/projetbut2/dip/DIPClient.java new file mode 100644 index 0000000..1b77d60 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/dip/DIPClient.java @@ -0,0 +1,10 @@ +package net.itsthesky.projetbut2.dip; + +public final class DIPClient { + + public static void main() { + Project project = new Project(); + project.implement(); + } + +} diff --git a/src/main/java/net/itsthesky/projetbut2/dip/Developer.java b/src/main/java/net/itsthesky/projetbut2/dip/Developer.java new file mode 100644 index 0000000..794b876 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/dip/Developer.java @@ -0,0 +1,7 @@ +package net.itsthesky.projetbut2.dip; + +public interface Developer { + + void develop(); + +} diff --git a/src/main/java/net/itsthesky/projetbut2/dip/FrontEndDeveloper.java b/src/main/java/net/itsthesky/projetbut2/dip/FrontEndDeveloper.java new file mode 100644 index 0000000..e133b12 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/dip/FrontEndDeveloper.java @@ -0,0 +1,9 @@ +package net.itsthesky.projetbut2.dip; + +public class FrontEndDeveloper implements Developer{ + @Override + public void develop() { + IO.println("I write Javascript code !"); + } + +} diff --git a/src/main/java/net/itsthesky/projetbut2/dip/Project.java b/src/main/java/net/itsthesky/projetbut2/dip/Project.java new file mode 100644 index 0000000..44e881f --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/dip/Project.java @@ -0,0 +1,21 @@ +package net.itsthesky.projetbut2.dip; + +import java.util.ArrayList; +import java.util.List; + +public class Project { + + private final List developers = new ArrayList<>(); + + public Project() { + developers.add(new BackEndDeveloper()); + developers.add(new FrontEndDeveloper()); + } + + public void implement() { + for (var developer : developers) { + developer.develop(); + } + } + +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/ColorCriteria.java b/src/main/java/net/itsthesky/projetbut2/ocp/ColorCriteria.java new file mode 100644 index 0000000..4e6ef0f --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/ColorCriteria.java @@ -0,0 +1,17 @@ +package net.itsthesky.projetbut2.ocp; + +import net.itsthesky.projetbut2.ocp.base.Color; +import net.itsthesky.projetbut2.ocp.base.Product; + +public class ColorCriteria implements Criteria { + + private final Color color; + public ColorCriteria(Color color) { + this.color = color; + } + + @Override + public boolean isSatisfied(Product product) { + return product.color == color; + } +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/Criteria.java b/src/main/java/net/itsthesky/projetbut2/ocp/Criteria.java new file mode 100644 index 0000000..40282f3 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/Criteria.java @@ -0,0 +1,7 @@ +package net.itsthesky.projetbut2.ocp; + +public interface Criteria { + + boolean isSatisfied(Product product); + +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/MultipleCriteria.java b/src/main/java/net/itsthesky/projetbut2/ocp/MultipleCriteria.java new file mode 100644 index 0000000..0e9fc85 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/MultipleCriteria.java @@ -0,0 +1,18 @@ +package net.itsthesky.projetbut2.ocp; + +import net.itsthesky.projetbut2.ocp.base.Product; + +import java.util.stream.Stream; + +public class MultipleCriteria implements Criteria { + + private final Criteria[] criteria; + public MultipleCriteria(Criteria... criteria) { + this.criteria = criteria; + } + + @Override + public boolean isSatisfied(Product product) { + return Stream.of(criteria).allMatch(c -> c.isSatisfied(product)); + } +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/NameCriteria.java b/src/main/java/net/itsthesky/projetbut2/ocp/NameCriteria.java new file mode 100644 index 0000000..0525e25 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/NameCriteria.java @@ -0,0 +1,16 @@ +package net.itsthesky.projetbut2.ocp; + +import net.itsthesky.projetbut2.ocp.base.Product; + +public class NameCriteria implements Criteria { + + private final String name; + public NameCriteria(String name) { + this.name = name; + } + + @Override + public boolean isSatisfied(Product product) { + return product.name.contains(name); + } +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/OCPClient.java b/src/main/java/net/itsthesky/projetbut2/ocp/OCPClient.java new file mode 100644 index 0000000..b47b77a --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/OCPClient.java @@ -0,0 +1,24 @@ +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 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")); + } + +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/PriceRangeCriteria.java b/src/main/java/net/itsthesky/projetbut2/ocp/PriceRangeCriteria.java new file mode 100644 index 0000000..fa624c1 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/PriceRangeCriteria.java @@ -0,0 +1,18 @@ +package net.itsthesky.projetbut2.ocp; + +import net.itsthesky.projetbut2.ocp.base.Product; + +public class PriceRangeCriteria implements Criteria { + + 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; + } +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/ProductFilter.java b/src/main/java/net/itsthesky/projetbut2/ocp/ProductFilter.java new file mode 100644 index 0000000..d35a907 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/ProductFilter.java @@ -0,0 +1,14 @@ +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 filter(List products, Criteria criteria) { + return products.stream().filter(criteria::isSatisfied); + } + +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/SizeCriteria.java b/src/main/java/net/itsthesky/projetbut2/ocp/SizeCriteria.java new file mode 100644 index 0000000..5081260 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/SizeCriteria.java @@ -0,0 +1,17 @@ +package net.itsthesky.projetbut2.ocp; + +import net.itsthesky.projetbut2.ocp.base.Product; +import net.itsthesky.projetbut2.ocp.base.Size; + +public class SizeCriteria implements Criteria { + + private final Size size; + public SizeCriteria(Size size) { + this.size = size; + } + + @Override + public boolean isSatisfied(Product product) { + return product.size == size; + } +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/base/Color.java b/src/main/java/net/itsthesky/projetbut2/ocp/base/Color.java new file mode 100644 index 0000000..c007937 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/base/Color.java @@ -0,0 +1,5 @@ +package net.itsthesky.projetbut2.ocp.base; + +public enum Color { + RED, GREEN, BLUE +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/base/Product.java b/src/main/java/net/itsthesky/projetbut2/ocp/base/Product.java new file mode 100644 index 0000000..b5f10f2 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/base/Product.java @@ -0,0 +1,20 @@ +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); + } +} diff --git a/src/main/java/net/itsthesky/projetbut2/ocp/base/Size.java b/src/main/java/net/itsthesky/projetbut2/ocp/base/Size.java new file mode 100644 index 0000000..9792976 --- /dev/null +++ b/src/main/java/net/itsthesky/projetbut2/ocp/base/Size.java @@ -0,0 +1,5 @@ +package net.itsthesky.projetbut2.ocp.base; + +public enum Size { + SMALL, MEDIUM, LARGE, HUGE +} diff --git a/src/main/java/net/itsthesky/projetbut2/qualdev/FindInstrumentTester.java b/src/main/java/net/itsthesky/projetbut2/qualdev/FindInstrumentTester.java deleted file mode 100644 index ded9398..0000000 --- a/src/main/java/net/itsthesky/projetbut2/qualdev/FindInstrumentTester.java +++ /dev/null @@ -1,115 +0,0 @@ -package net.itsthesky.projetbut2.qualdev; - -import net.itsthesky.projetbut2.qualdev.model.Specification; -import net.itsthesky.projetbut2.qualdev.model.Instrument; -import net.itsthesky.projetbut2.qualdev.model.InstrumentSpec; -import net.itsthesky.projetbut2.qualdev.model.specs.*; - -import java.util.Arrays; -import java.util.List; - -public class FindInstrumentTester { - - public static void main(String[] args) { - // Set up Rick's inventory - Inventory inventory = new Inventory(); - initializeInventory(inventory); - - - InstrumentSpec whatBryanLikes = new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.MANDOLIN, - Specification.STYLE, Style.F)); - - whatBryanLikes = new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.BANJO)); - - List matchingInstruments = inventory.search(whatBryanLikes); - if (!matchingInstruments.isEmpty()) - System.out.println("Here's what we have for you:\n" + matchingInstruments); - else - System.out.println("Sorry, we have nothing for you."); - } - - - public static void initializeInventory(Inventory inventory) { - inventory.addInstrument(new Instrument("82765501", 1890.95, - new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.GUITAR, - Specification.TYPE, Type.ELECTRIC, - Specification.MODEL, "SG '61 Reissue", - Specification.BACKWOOD, Wood.MAHOGANY, - Specification.TOPWOOD, Wood.MAHOGANY)))); - - inventory.addInstrument(new Instrument("9019920", 5495.99, - new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.MANDOLIN, - Specification.TYPE, Type.ACOUSTIC, - Specification.MODEL, "DRSM-008 E", - Specification.BACKWOOD, Wood.MAPLE, - Specification.TOPWOOD, Wood.MAPLE, - Specification.BUILDER, Builder.PRS, - Specification.STYLE, Style.A - )))); - - inventory.addInstrument(new Instrument("7819920", 549, - new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.MANDOLIN, - Specification.TYPE, Type.ACOUSTIC, - Specification.MODEL, "F-5G", - Specification.BACKWOOD, Wood.MAPLE, - Specification.TOPWOOD, Wood.MAPLE, - Specification.BUILDER, Builder.GIBSON, - Specification.STYLE, Style.F - )))); - inventory.addInstrument(new Instrument("8900231", 2945.95, - new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.BANJO, - Specification.MODEL, "RB-3 Wreath", - Specification.YEAR_OF_MANUFACTURE, 1967 - )))); - inventory.addInstrument(new Instrument("70108276", 2295.95, - new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.GUITAR, - Specification.BUILDER, Builder.GIBSON, - Specification.MODEL, "Les Paul", - Specification.BACKWOOD, Wood.MAPLE, - Specification.TOPWOOD, Wood.MAPLE - )))); - inventory.addInstrument(new Instrument("V95693", 1499.95, - new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.GUITAR, - Specification.BUILDER, Builder.FENDER, - Specification.MODEL, "Stratocastor", - Specification.BACKWOOD, Wood.ALDER, - Specification.TOPWOOD, Wood.ALDER, - Specification.TYPE, Type.ELECTRIC - )))); - inventory.addInstrument(new Instrument("V9512", 1549.95, - new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.GUITAR, - Specification.BUILDER, Builder.FENDER, - Specification.MODEL, "Stratocastor", - Specification.BACKWOOD, Wood.ALDER, - Specification.TOPWOOD, Wood.ALDER, - Specification.TYPE, Type.ELECTRIC - )))); - inventory.addInstrument(new Instrument("122784", 5495.95, - new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.GUITAR, - Specification.BUILDER, Builder.MARTIN, - Specification.MODEL, "D-18", - Specification.BACKWOOD, Wood.MAHOGANY, - Specification.TOPWOOD, Wood.ADIRONDACK - )))); - inventory.addInstrument(new Instrument("11277", 3999.95, - new InstrumentSpec(Arrays.asList( - Specification.INSTRUMENT_TYPE, InstrumentType.GUITAR, - Specification.BUILDER, Builder.COLLINGS, - Specification.MODEL, "CJ", - Specification.BACKWOOD, Wood.INDIAN_ROSEWOOD, - Specification.TOPWOOD, Wood.SITKA, - Specification.TYPE, Type.ACOUSTIC, - Specification.NUMBER_OF_STRINGS, 6 - )))); - } -} \ No newline at end of file diff --git a/src/main/java/net/itsthesky/projetbut2/qualdev/Inventory.java b/src/main/java/net/itsthesky/projetbut2/qualdev/Inventory.java deleted file mode 100644 index 125aff0..0000000 --- a/src/main/java/net/itsthesky/projetbut2/qualdev/Inventory.java +++ /dev/null @@ -1,54 +0,0 @@ -package net.itsthesky.projetbut2.qualdev; - -import net.itsthesky.projetbut2.qualdev.model.Instrument; -import net.itsthesky.projetbut2.qualdev.model.InstrumentSpec; - -import java.util.ArrayList; -import java.util.List; - -/** - * Gère l'inventaire des instruments - */ -public class Inventory { - - private final List instruments = new ArrayList<>(); - - /** - * Rajoute un instrument à cet inventaire, basé sur son serial number, - * prix et spécifications. - * @param instrument l'instrument à ajouter - * @see InstrumentSpec - */ - public void addInstrument(Instrument instrument) { - instruments.add(instrument); - } - - /** - * Récupère un instrument de cet instrument basé sur son numéro de série. - * @param serialNumber le numéro de série à chercher - * @return l'instrument trouvé avec le même numéro de série fourni, sinon null - */ - public Instrument getInstrument(String serialNumber) { - return instruments.stream() - .filter(instrument -> instrument.getSerialNumber().equals(serialNumber)) - .findFirst() - .orElse(null); - } - - /** - * Recherche tous les instruments correspondant aux spécifications fournies. - * @param instrumentSpec les spécifications à rechercher - * @return une liste d'instruments correspondant aux spécifications - */ - public List search(InstrumentSpec instrumentSpec) { - final var result = new ArrayList(); - - for (Instrument instrument : instruments) { - if (instrumentSpec.matches(instrument.getInstrumentSpec())) - result.add(instrument); - } - - return result; - } - -} diff --git a/src/main/java/net/itsthesky/projetbut2/qualdev/model/Instrument.java b/src/main/java/net/itsthesky/projetbut2/qualdev/model/Instrument.java deleted file mode 100644 index b4effd1..0000000 --- a/src/main/java/net/itsthesky/projetbut2/qualdev/model/Instrument.java +++ /dev/null @@ -1,64 +0,0 @@ -package net.itsthesky.projetbut2.qualdev.model; - -/** - * Classe abstraite représentant un instrument de musique. - */ -public class Instrument { - - private final String serialNumber; - private final InstrumentSpec instrumentSpec; - private double price; - - /** - * Constructeur d'un instrument. - * @param serialNumber le numéro de série de l'instrument - * @param price le prix de l'instrument - * @param instrumentSpec les spécifications de l'instrument - */ - public Instrument(String serialNumber, double price, InstrumentSpec instrumentSpec) { - this.serialNumber = serialNumber; - this.instrumentSpec = instrumentSpec; - this.price = price; - } - - /** - * Récupère le numéro de série de l'instrument. - * @return le numéro de série - */ - public String getSerialNumber() { - return serialNumber; - } - - /** - * Récupère les spécifications de l'instrument. - * @return les spécifications - */ - public InstrumentSpec getInstrumentSpec() { - return instrumentSpec; - } - - /** - * Récupère le prix de l'instrument. - * @return le prix - */ - public double getPrice() { - return price; - } - - /** - * Modifie le prix de l'instrument. - * @param price le nouveau prix - */ - public void setPrice(double price) { - this.price = price; - } - - @Override - public String toString() { - return "Instrument{" + - "serialNumber='" + serialNumber + '\'' + - ", instrumentSpec=" + instrumentSpec + - ", price=" + price + - '}'; - } -} diff --git a/src/main/java/net/itsthesky/projetbut2/qualdev/model/InstrumentSpec.java b/src/main/java/net/itsthesky/projetbut2/qualdev/model/InstrumentSpec.java deleted file mode 100644 index 1f60273..0000000 --- a/src/main/java/net/itsthesky/projetbut2/qualdev/model/InstrumentSpec.java +++ /dev/null @@ -1,69 +0,0 @@ -package net.itsthesky.projetbut2.qualdev.model; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Classe abstraite représentant les spécifications d'un instrument de musique. - */ -public class InstrumentSpec { - - private final Map, Object> caracteristiques; - - /** - * Constructeur des spécifications de l'instrument. - */ - public InstrumentSpec() { - this.caracteristiques = new HashMap<>(); - } - - public InstrumentSpec(List specs) { - this.caracteristiques = new HashMap<>(); - for (int i = 0; i < specs.size(); i += 2) { - Specification key = (Specification) specs.get(i); - Object value = specs.get(i + 1); - - if (value.getClass() != key.type()) - throw new IllegalArgumentException("Type de valeur incorrect pour la caractéristique " + key.label()); - - this.caracteristiques.put(key, value); - } - } - - /** - * Vérifie si ces spécifications correspondent à d'autres spécifications. - * @param otherSpec les spécifications à comparer - * @return true si les spécifications correspondent, false sinon - */ - public boolean matches(InstrumentSpec otherSpec) { - if (otherSpec == null) return false; - for (var caracteristique : caracteristiques.entrySet()) { - var otherValue = otherSpec.caracteristiques.get(caracteristique.getKey()); - if (otherValue == null || !caracteristique.getValue().equals(otherValue)) { - return false; - } - } - return true; - } - - public Map, ?> getCaracteristiques() { - return caracteristiques; - } - - public T getCaracteristique(Specification specification) { - return (T) caracteristiques.get(specification); - } - - public InstrumentSpec addCaracteristique(Specification specification, T value) { - this.caracteristiques.put(specification, value); - return this; - } - - @Override - public String toString() { - return "InstrumentSpec{" + - "caracteristiques=" + caracteristiques + - '}'; - } -} diff --git a/src/main/java/net/itsthesky/projetbut2/qualdev/model/Specification.java b/src/main/java/net/itsthesky/projetbut2/qualdev/model/Specification.java deleted file mode 100644 index ecc662a..0000000 --- a/src/main/java/net/itsthesky/projetbut2/qualdev/model/Specification.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.itsthesky.projetbut2.qualdev.model; - -import net.itsthesky.projetbut2.qualdev.model.specs.*; - -public record Specification(Class type, String label) { - - public static Specification BUILDER = new Specification<>(Builder.class, "Fabricantt"); - public static Specification MODEL = new Specification<>(String.class, "Modèle"); - public static Specification NUMBER_OF_STRINGS = new Specification<>(Integer.class, "Nombre de cordes"); - public static Specification TYPE = new Specification<>(Type.class, "Type"); - public static Specification