Add initial project structure with instrument classes and Gradle setup
This commit is contained in:
20
build.gradle
Normal file
20
build.gradle
Normal file
@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'net.itsthesky.projetbut2'
|
||||
version = '1.0-SNAPSHOT'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
234
gradlew
vendored
Normal file
234
gradlew
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
1
settings.gradle
Normal file
1
settings.gradle
Normal file
@ -0,0 +1 @@
|
||||
rootProject.name = 'ProjetBUT2'
|
||||
5
src/main/java/net/itsthesky/projetbut2/Main.java
Normal file
5
src/main/java/net/itsthesky/projetbut2/Main.java
Normal file
@ -0,0 +1,5 @@
|
||||
import net.itsthesky.projetbut2.qualdev.FindInstrumentTester_v_Et;
|
||||
|
||||
void main() {
|
||||
FindInstrumentTester_v_Et.main(new String[]{});
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package net.itsthesky.projetbut2.qualdev;
|
||||
|
||||
/**
|
||||
* Classe représentant un client de guitare.
|
||||
*/
|
||||
public class ClientGuitar {
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package net.itsthesky.projetbut2.qualdev;
|
||||
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Builder;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Style;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Type;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Wood;
|
||||
import net.itsthesky.projetbut2.qualdev.model.guitar.GuitarSpec;
|
||||
import net.itsthesky.projetbut2.qualdev.model.mandoline.MandolineSpec;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Classe de test pour rechercher des instruments dans l'inventaire.
|
||||
*/
|
||||
public class FindInstrumentTester_v_Et {
|
||||
|
||||
/**
|
||||
* Point d'entrée principal du programme de test.
|
||||
* @param args arguments de ligne de commande
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// Set up Rick's guitar inventory
|
||||
Inventory inventory = new Inventory();
|
||||
initializeInventory(inventory);
|
||||
|
||||
GuitarSpec whatErinLikes= new GuitarSpec( Builder.FENDER, "Stratocastor", Type.ELECTRIC,
|
||||
Wood.ALDER, Wood.ALDER, 6);
|
||||
MandolineSpec whatErinLikes2 = new MandolineSpec(Builder.PRS, "F-5G", Type.ACOUSTIC, Wood.MAPLE,
|
||||
Wood.MAPLE, Style.A);
|
||||
List matchingInstruments = inventory.search (whatErinLikes);
|
||||
|
||||
if (!matchingInstruments.isEmpty()) {
|
||||
System.out.println( matchingInstruments);
|
||||
}
|
||||
else {
|
||||
System.out.println("Sorry, Erin, we have nothing for you.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise l'inventaire avec des guitares et mandolines de test.
|
||||
* @param inventory l'inventaire à initialiser
|
||||
*/
|
||||
public static void initializeInventory(Inventory inventory) {
|
||||
|
||||
// Ajout des guitares à l'inventaire
|
||||
inventory.addInstrument("11277", 3999.95,
|
||||
new GuitarSpec(Builder.COLLINGS, "CJ", Type.ACOUSTIC,
|
||||
Wood.INDIAN_ROSEWOOD, Wood.SITKA, 6));
|
||||
inventory.addInstrument("V95693", 1499.95,
|
||||
new GuitarSpec(Builder.FENDER, "Stratocastor",Type.ELECTRIC,
|
||||
Wood.ALDER, Wood.ALDER, 12));
|
||||
inventory.addInstrument("V9512", 1549.95,
|
||||
new GuitarSpec(Builder.FENDER, "Stratocastor", Type.ELECTRIC,
|
||||
Wood.ALDER, Wood.ALDER, 6));
|
||||
inventory.addInstrument("122784", 5495.95,
|
||||
new GuitarSpec(Builder.MARTIN, "D-18", Type.ACOUSTIC,
|
||||
Wood.MAHOGANY, Wood.ADIRONDACK, 6));
|
||||
inventory.addInstrument("76531", 6295.95,
|
||||
new GuitarSpec(Builder.MARTIN, "OM-28", Type.ACOUSTIC,
|
||||
Wood.BRAZILIAN_ROSEWOOD, Wood.ADIRONDACK, 6));
|
||||
inventory.addInstrument("70108276", 2295.95,
|
||||
new GuitarSpec(Builder.GIBSON, "Les Paul", Type.ELECTRIC,
|
||||
Wood.MAHOGANY, Wood.MAHOGANY, 6));
|
||||
inventory.addInstrument("82765501", 1890.95,
|
||||
new GuitarSpec(Builder.GIBSON, "SG '61 Reissue", Type.ELECTRIC,
|
||||
Wood.MAHOGANY, Wood.MAHOGANY, 6));
|
||||
inventory.addInstrument("77023", 6275.95,
|
||||
new GuitarSpec(Builder.MARTIN, "D-28", Type.ACOUSTIC,
|
||||
Wood.BRAZILIAN_ROSEWOOD, Wood.ADIRONDACK, 6));
|
||||
inventory.addInstrument("1092", 12995.95,
|
||||
new GuitarSpec(Builder.OLSON, "SJ", Type.ACOUSTIC,
|
||||
Wood.INDIAN_ROSEWOOD, Wood.CEDAR, 12));
|
||||
inventory.addInstrument("566-62", 8999.95,
|
||||
new GuitarSpec(Builder.RYAN, "Cathedral", Type.ACOUSTIC,
|
||||
Wood.COCOBOLO, Wood.CEDAR, 12));
|
||||
inventory.addInstrument("6 29584", 2100.95,
|
||||
new GuitarSpec(Builder.PRS, "Dave Navarro Signature", Type.ELECTRIC,
|
||||
Wood.MAHOGANY, Wood.MAPLE, 6));
|
||||
|
||||
// Ajout des mandolines à l'inventaire
|
||||
inventory.addInstrument("8819920", 5495.99 ,
|
||||
new MandolineSpec(Builder.PRS, "F-5G", Type.ACOUSTIC,
|
||||
Wood.MAPLE, Wood.MAPLE, Style.F));
|
||||
inventory.addInstrument("9019920", 745.99 ,
|
||||
new MandolineSpec (Builder.PRS, "F-5G", Type.ACOUSTIC,
|
||||
Wood.MAPLE, Wood.MAPLE, Style.A));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package net.itsthesky.projetbut2.qualdev;
|
||||
|
||||
import net.itsthesky.projetbut2.qualdev.model.Instrument;
|
||||
import net.itsthesky.projetbut2.qualdev.model.InstrumentSpec;
|
||||
import net.itsthesky.projetbut2.qualdev.model.guitar.Guitar;
|
||||
import net.itsthesky.projetbut2.qualdev.model.guitar.GuitarSpec;
|
||||
import net.itsthesky.projetbut2.qualdev.model.mandoline.Mandoline;
|
||||
import net.itsthesky.projetbut2.qualdev.model.mandoline.MandolineSpec;
|
||||
|
||||
/**
|
||||
* Factory permettant de créer des instruments de musique en fonction de leurs spécifications.
|
||||
*/
|
||||
public class InstrumentFactory {
|
||||
|
||||
/**
|
||||
* Crée un instrument basé sur son numéro de série, son prix et ses spécifications.
|
||||
* @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
|
||||
* @return l'instrument créé, ou <code>null</code> si le type de spécification n'est pas reconnu
|
||||
*/
|
||||
public static Instrument createInstrument(String serialNumber, double price, InstrumentSpec instrumentSpec) {
|
||||
if (instrumentSpec instanceof GuitarSpec guitarSpec)
|
||||
return new Guitar(serialNumber, price, guitarSpec);
|
||||
if (instrumentSpec instanceof MandolineSpec mandolineSpec)
|
||||
return new Mandoline(serialNumber, price, mandolineSpec);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
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 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
|
||||
* @see InstrumentFactory
|
||||
* @see InstrumentSpec
|
||||
*/
|
||||
public void addInstrument(String serialNumber, double price, InstrumentSpec instrumentSpec) {
|
||||
final var instrument = InstrumentFactory.createInstrument(serialNumber, price, instrumentSpec);
|
||||
if (instrument != null)
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model;
|
||||
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Builder;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Style;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Type;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Wood;
|
||||
|
||||
public class Caracteristique<T> {
|
||||
|
||||
public static Caracteristique<Builder> BUILDER = new Caracteristique<>(Builder.class);
|
||||
public static Caracteristique<String> MODEL = new Caracteristique<>(String.class);
|
||||
public static Caracteristique<Integer> NUMBER_OF_STRINGS = new Caracteristique<>(Integer.class);
|
||||
public static Caracteristique<Type> TYPE = new Caracteristique<>(Type.class);
|
||||
public static Caracteristique<Wood> WOOD = new Caracteristique<>(Wood.class);
|
||||
public static Caracteristique<Style> STYLE = new Caracteristique<>(Style.class);
|
||||
|
||||
private final Class<T> type;
|
||||
|
||||
public Caracteristique(Class<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model;
|
||||
|
||||
/**
|
||||
* Classe abstraite représentant un instrument de musique.
|
||||
*/
|
||||
public abstract 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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model;
|
||||
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Wood;
|
||||
|
||||
/**
|
||||
* Classe abstraite représentant les spécifications d'un instrument de musique.
|
||||
*/
|
||||
public abstract class InstrumentSpec {
|
||||
|
||||
private final Wood topWood;
|
||||
private final Wood backWood;
|
||||
|
||||
/**
|
||||
* Constructeur des spécifications de l'instrument.
|
||||
* @param topWood le type de bois de la face supérieure
|
||||
* @param backWood le type de bois de la face arrière
|
||||
*/
|
||||
protected InstrumentSpec(Wood topWood, Wood backWood) {
|
||||
this.topWood = topWood;
|
||||
this.backWood = backWood;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
if (topWood != otherSpec.topWood) return false;
|
||||
if (backWood != otherSpec.backWood) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le type de bois de la face supérieure.
|
||||
* @return le type de bois supérieur
|
||||
*/
|
||||
public Wood getTopWood() {
|
||||
return topWood;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le type de bois de la face arrière.
|
||||
* @return le type de bois arrière
|
||||
*/
|
||||
public Wood getBackWood() {
|
||||
return backWood;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.common;
|
||||
|
||||
/**
|
||||
* Représente un constructeur d'instrument de musique.
|
||||
*/
|
||||
public enum Builder {
|
||||
COLLINGS,
|
||||
FENDER,
|
||||
GIBSON,
|
||||
MARTIN,
|
||||
OLSON,
|
||||
RYAN,
|
||||
PRS
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.common;
|
||||
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.common;
|
||||
|
||||
/**
|
||||
* Représent le type d'une {@link net.itsthesky.projetbut2.qualdev.model.guitar.GuitarSpec guitar}.
|
||||
*/
|
||||
public enum Type {
|
||||
ACOUSTIC, ELECTRIC
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.common;
|
||||
|
||||
/**
|
||||
* 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,20 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.guitar;
|
||||
|
||||
import net.itsthesky.projetbut2.qualdev.model.Instrument;
|
||||
|
||||
/**
|
||||
* Représente une guitare, un type spécifique d'instrument de musique.
|
||||
*/
|
||||
public class Guitar extends Instrument {
|
||||
|
||||
/**
|
||||
* Constructeur d'une guitare.
|
||||
* @param serialNumber le numéro de série de la guitare
|
||||
* @param price le prix de la guitare
|
||||
* @param instrumentSpec les spécifications de la guitare
|
||||
*/
|
||||
public Guitar(String serialNumber, double price, GuitarSpec instrumentSpec) {
|
||||
super(serialNumber, price, instrumentSpec);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.guitar;
|
||||
|
||||
import net.itsthesky.projetbut2.qualdev.model.InstrumentSpec;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Builder;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Type;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Wood;
|
||||
|
||||
/**
|
||||
* Représente les spécifications d'une guitare.
|
||||
*/
|
||||
public class GuitarSpec extends InstrumentSpec {
|
||||
|
||||
private final Builder builder;
|
||||
private final int numStrings;
|
||||
private final String model;
|
||||
private final Type type;
|
||||
|
||||
/**
|
||||
* Constructeur des spécifications d'une guitare.
|
||||
* @param builder le constructeur de la guitare
|
||||
* @param model le modèle de la guitare
|
||||
* @param type le type de guitare (acoustique ou électrique)
|
||||
* @param topWood le type de bois de la face supérieure
|
||||
* @param backWood le type de bois de la face arrière
|
||||
* @param numStrings le nombre de cordes
|
||||
*/
|
||||
public GuitarSpec(Builder builder, String model, Type type, Wood topWood, Wood backWood, int numStrings) {
|
||||
super(topWood, backWood);
|
||||
this.builder = builder;
|
||||
this.numStrings = numStrings;
|
||||
this.model = model;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le constructeur de la guitare.
|
||||
* @return le constructeur
|
||||
*/
|
||||
public Builder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le nombre de cordes de la guitare.
|
||||
* @return le nombre de cordes
|
||||
*/
|
||||
public int getNumStrings() {
|
||||
return numStrings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le type de guitare.
|
||||
* @return le type (acoustique ou électrique)
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(InstrumentSpec otherSpec) {
|
||||
if (!super.matches(otherSpec)) return false;
|
||||
if (otherSpec instanceof GuitarSpec otherGuitarSpec) {
|
||||
if (builder != otherGuitarSpec.builder) return false;
|
||||
if (numStrings != otherGuitarSpec.numStrings) return false;
|
||||
if (type != otherGuitarSpec.type) return false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le modèle de la guitare.
|
||||
* @return le modèle
|
||||
*/
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GuitarSpec{" +
|
||||
"builder=" + builder +
|
||||
", numStrings=" + numStrings +
|
||||
", model='" + model + '\'' +
|
||||
", type=" + type +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.mandoline;
|
||||
|
||||
import net.itsthesky.projetbut2.qualdev.model.Instrument;
|
||||
import net.itsthesky.projetbut2.qualdev.model.InstrumentSpec;
|
||||
|
||||
/**
|
||||
* Représente une mandoline, un type spécifique d'instrument de musique.
|
||||
*/
|
||||
public class Mandoline extends Instrument {
|
||||
|
||||
/**
|
||||
* Constructeur d'une mandoline.
|
||||
* @param serialNumber le numéro de série de la mandoline
|
||||
* @param price le prix de la mandoline
|
||||
* @param instrumentSpec les spécifications de la mandoline
|
||||
*/
|
||||
public Mandoline(String serialNumber, double price, MandolineSpec instrumentSpec) {
|
||||
super(serialNumber, price, instrumentSpec);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
package net.itsthesky.projetbut2.qualdev.model.mandoline;
|
||||
|
||||
import net.itsthesky.projetbut2.qualdev.model.InstrumentSpec;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Builder;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Style;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Type;
|
||||
import net.itsthesky.projetbut2.qualdev.model.common.Wood;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Représente les spécifications d'une mandoline.
|
||||
*/
|
||||
public class MandolineSpec extends InstrumentSpec {
|
||||
|
||||
private final Style style;
|
||||
private final Builder builder;
|
||||
private final String model;
|
||||
private final Type type;
|
||||
|
||||
/**
|
||||
* Constructeur des spécifications d'une mandoline.
|
||||
* @param builder le constructeur de la mandoline
|
||||
* @param model le modèle de la mandoline
|
||||
* @param type le type de mandoline (acoustique ou électrique)
|
||||
* @param topWood le type de bois de la face supérieure
|
||||
* @param backWood le type de bois de la face arrière
|
||||
* @param style le style de la mandoline (A ou F)
|
||||
*/
|
||||
public MandolineSpec(Builder builder, String model, Type type, Wood topWood, Wood backWood, Style style) {
|
||||
super(topWood, backWood);
|
||||
this.style = style;
|
||||
this.builder = builder;
|
||||
this.model = model;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le style de la mandoline.
|
||||
* @return le style (A ou F)
|
||||
*/
|
||||
public Style getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le constructeur de la mandoline.
|
||||
* @return le constructeur
|
||||
*/
|
||||
public Builder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le modèle de la mandoline.
|
||||
* @return le modèle
|
||||
*/
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le type de mandoline.
|
||||
* @return le type (acoustique ou électrique)
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InstrumentSpec otherSpec) {
|
||||
if (!super.matches(otherSpec)) return false;
|
||||
if (otherSpec instanceof MandolineSpec otherMandolineSpec) {
|
||||
if (style != otherMandolineSpec.style) return false;
|
||||
if (builder != otherMandolineSpec.builder) return false;
|
||||
if (!Objects.equals(model, otherMandolineSpec.model)) return false;
|
||||
if (type != otherMandolineSpec.type) return false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MandolineSpec{" +
|
||||
"style=" + style +
|
||||
", builder=" + builder +
|
||||
", model='" + model + '\'' +
|
||||
", type=" + type +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user