-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit ec9be00
Showing
19 changed files
with
1,152 additions
and
0 deletions.
There are no files selected for viewing
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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.1 KB
VapeStore/out/production/VapeStore/VapeStore/DateValidatorUsingDateTimeFormatter.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,84 @@ | ||
package VapeStore; | ||
|
||
import java.util.Objects; | ||
import java.util.Scanner; | ||
|
||
public class Category { | ||
|
||
private String catName, catDescription; | ||
private Category catParent; | ||
|
||
public Category() { | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println("Saisir le nom de la catégorie : "); | ||
this.catName = sc.nextLine(); | ||
System.out.println("Saisir la description de la catégorie : "); | ||
this.catDescription = sc.nextLine(); | ||
this.catParent = null; | ||
} | ||
|
||
public Category(String catName, String catDescription, Category parentCat) { | ||
this.catName = catName; | ||
this.catDescription = catDescription; | ||
this.catParent = parentCat; | ||
} | ||
|
||
//deep cloning | ||
public Category(Category catCopy) { | ||
this.catName = catCopy.catName; | ||
this.catDescription = catCopy.catDescription; | ||
this.catParent = catCopy.catParent; | ||
} | ||
|
||
public String getCatName() { | ||
return catName; | ||
} | ||
|
||
public String getCatDescription() { | ||
return catDescription; | ||
} | ||
|
||
public Category getCatParent() { | ||
return catParent; | ||
} | ||
|
||
public void setCatParent(Category catParent) { | ||
this.catParent = catParent; | ||
} | ||
|
||
//check on category name only | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Category category = (Category) o; | ||
return Objects.equals(catName, category.catName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(catName); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
|
||
return "Nom de la catégorie : " + catName + "\nDescription : " + catDescription; | ||
} | ||
|
||
|
||
public String saisie(String regex, String message) { | ||
Scanner sc = new Scanner(System.in); | ||
boolean check = false; | ||
String phrase; | ||
do { | ||
phrase = sc.nextLine(); | ||
if (phrase.matches(regex)) { | ||
check = true; | ||
} else { | ||
System.out.println(message); | ||
} | ||
} while (!check); | ||
return phrase; | ||
} | ||
} |
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 VapeStore; | ||
|
||
public interface DateValidator { | ||
boolean isValid(String dateStr); | ||
} |
30 changes: 30 additions & 0 deletions
30
VapeStore/src/VapeStore/DateValidatorUsingDateTimeFormatter.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,30 @@ | ||
package VapeStore; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
|
||
public class DateValidatorUsingDateTimeFormatter implements DateValidator { | ||
private DateTimeFormatter dateFormatter; | ||
|
||
//https://www.baeldung.com/java-string-valid-date | ||
|
||
//constructor , no attribute, takes the same pattern of the orders' dates | ||
public DateValidatorUsingDateTimeFormatter(){ | ||
this.dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); | ||
} | ||
|
||
public DateValidatorUsingDateTimeFormatter(DateTimeFormatter dateFormatter) { | ||
this.dateFormatter = dateFormatter; | ||
} | ||
|
||
@Override | ||
public boolean isValid(String dateStr) { | ||
try { | ||
this.dateFormatter.parse(dateStr); | ||
} catch (DateTimeParseException e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.