Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cbb2580ce9 | |||
| 16d76d1c08 | |||
| 17d960fd3b |
@ -1,5 +1,4 @@
|
||||
import net.itsthesky.projetbut2.qualdev.FindInstrumentTester;
|
||||
|
||||
void main() {
|
||||
FindInstrumentTester.main(new String[]{});
|
||||
void main(String[] args) {
|
||||
if (args.length == 0) return;
|
||||
}
|
||||
@ -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,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
|
||||
))));
|
||||
}
|
||||
}
|
||||
@ -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<Instrument> 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 <code>null</code>
|
||||
*/
|
||||
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<Instrument> search(InstrumentSpec instrumentSpec) {
|
||||
final var result = new ArrayList<Instrument>();
|
||||
|
||||
for (Instrument instrument : instruments) {
|
||||
if (instrumentSpec.matches(instrument.getInstrumentSpec()))
|
||||
result.add(instrument);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -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<Specification<?>, Object> caracteristiques;
|
||||
|
||||
/**
|
||||
* Constructeur des spécifications de l'instrument.
|
||||
*/
|
||||
public InstrumentSpec() {
|
||||
this.caracteristiques = new HashMap<>();
|
||||
}
|
||||
|
||||
public InstrumentSpec(List<Object> 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 <code>true</code> si les spécifications correspondent, <code>false</code> 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<Specification<?>, ?> getCaracteristiques() {
|
||||
return caracteristiques;
|
||||
}
|
||||
|
||||
public <T> T getCaracteristique(Specification<T> specification) {
|
||||
return (T) caracteristiques.get(specification);
|
||||
}
|
||||
|
||||
public <T> InstrumentSpec addCaracteristique(Specification<T> specification, T value) {
|
||||
this.caracteristiques.put(specification, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InstrumentSpec{" +
|
||||
"caracteristiques=" + caracteristiques +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model;
|
||||
|
||||
import net.itsthesky.projetbut2.qualdev.model.specs.*;
|
||||
|
||||
public record Specification<T>(Class<T> type, String label) {
|
||||
|
||||
public static Specification<Builder> BUILDER = new Specification<>(Builder.class, "Fabricantt");
|
||||
public static Specification<String> MODEL = new Specification<>(String.class, "Modèle");
|
||||
public static Specification<Integer> NUMBER_OF_STRINGS = new Specification<>(Integer.class, "Nombre de cordes");
|
||||
public static Specification<Type> TYPE = new Specification<>(Type.class, "Type");
|
||||
public static Specification<Style> STYLE = new Specification<>(Style.class, "Style");
|
||||
public static Specification<Integer> YEAR_OF_MANUFACTURE = new Specification<>(Integer.class, "Année de fabrication");
|
||||
|
||||
public static Specification<Wood> TOPWOOD = new Specification<>(Wood.class, "Bois dessus");
|
||||
public static Specification<Wood> BACKWOOD = new Specification<>(Wood.class, "Bois dessous");
|
||||
|
||||
public static Specification<InstrumentType> INSTRUMENT_TYPE = new Specification<>(InstrumentType.class, "Type d'instrument");
|
||||
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.specs;
|
||||
|
||||
/**
|
||||
* Représente un constructeur d'instrument de musique.
|
||||
*/
|
||||
public enum Builder {
|
||||
COLLINGS,
|
||||
FENDER,
|
||||
GIBSON,
|
||||
MARTIN,
|
||||
OLSON,
|
||||
RYAN,
|
||||
PRS
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.specs;
|
||||
|
||||
public enum InstrumentType {
|
||||
|
||||
GUITAR, MANDOLIN, CELLO, BANJO, VIOLIN, DOBRO, FIDDLE, BASS, ;
|
||||
|
||||
public String toString () {
|
||||
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.specs;
|
||||
|
||||
/**
|
||||
* Représente le style d'une {@link net.itsthesky.projetbut2.qualdev.model.mandoline.MandolineSpec mandoline}; A pour
|
||||
* Acoustique et F pour Fender.
|
||||
*/
|
||||
public enum Style {
|
||||
A,
|
||||
F
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.specs;
|
||||
|
||||
/**
|
||||
* Représent le type d'une {@link net.itsthesky.projetbut2.qualdev.model.guitar.GuitarSpec guitar}.
|
||||
*/
|
||||
public enum Type {
|
||||
ACOUSTIC, ELECTRIC
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.specs;
|
||||
|
||||
/**
|
||||
* Représente le type de bois utilisé dans la confection
|
||||
* de l'{@link net.itsthesky.projetbut2.qualdev.model.Instrument instrument}.
|
||||
*/
|
||||
public enum Wood {
|
||||
ADIRONDACK,
|
||||
CEDAR,
|
||||
COCOBOLO,
|
||||
MAHOGANY,
|
||||
MAPLE,
|
||||
SITKA,
|
||||
ALDER,
|
||||
BRAZILIAN_ROSEWOOD,
|
||||
INDIAN_ROSEWOOD
|
||||
}
|
||||
@ -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