From 67c19b48cc6d3f90ad424c68d3cc27effc395a37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 8 Oct 2017 00:17:52 +0200 Subject: [PATCH] Continued (renaming-season has started): - renamed OpeningTimes -> OpeningTime as it is a single entity anyway - also renamed package opening_times -> opening_time - add event for when an opening time has been added MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../ObservableOpeningTimeAddedEvent.java | 36 ++++++++++ .../added/OpeningTimeAddedEvent.java | 67 +++++++++++++++++++ .../OpeningTimeNotFoundException.java} | 8 +-- .../model/branchoffice/BranchOffice.java | 6 +- .../branchoffice/CompanyBranchOffice.java | 14 ++-- .../BusinessOpeningTime.java} | 12 ++-- .../OpeningTime.java} | 6 +- .../dayofweek/DayOfTheWeek.java | 2 +- 8 files changed, 128 insertions(+), 23 deletions(-) create mode 100644 src/org/mxchange/jcontactsbusiness/events/opening_time/added/ObservableOpeningTimeAddedEvent.java create mode 100644 src/org/mxchange/jcontactsbusiness/events/opening_time/added/OpeningTimeAddedEvent.java rename src/org/mxchange/jcontactsbusiness/exceptions/{opening_times/OpeningTimesNotFoundException.java => opening_time/OpeningTimeNotFoundException.java} (84%) rename src/org/mxchange/jcontactsbusiness/model/{opening_times/BusinessOpeningTimes.java => opening_time/BusinessOpeningTime.java} (93%) rename src/org/mxchange/jcontactsbusiness/model/{opening_times/OpeningTimes.java => opening_time/OpeningTime.java} (92%) rename src/org/mxchange/jcontactsbusiness/model/{opening_times => opening_time}/dayofweek/DayOfTheWeek.java (97%) diff --git a/src/org/mxchange/jcontactsbusiness/events/opening_time/added/ObservableOpeningTimeAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/opening_time/added/ObservableOpeningTimeAddedEvent.java new file mode 100644 index 0000000..116ed21 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/events/opening_time/added/ObservableOpeningTimeAddedEvent.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.events.opening_time.added; + +import java.io.Serializable; +import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; + +/** + * An interface for events being triggered when a opening time has been added. + *

+ * @author Roland Häder + */ +public interface ObservableOpeningTimeAddedEvent extends Serializable { + + /** + * Getter for opening time instance + *

+ * @return OpeningTime instance + */ + OpeningTime getOpeningTime (); + +} diff --git a/src/org/mxchange/jcontactsbusiness/events/opening_time/added/OpeningTimeAddedEvent.java b/src/org/mxchange/jcontactsbusiness/events/opening_time/added/OpeningTimeAddedEvent.java new file mode 100644 index 0000000..0d53faf --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/events/opening_time/added/OpeningTimeAddedEvent.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.events.opening_time.added; + +import java.text.MessageFormat; +import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; + +/** + * An event being fired when a openingTime has been added + *

+ * @author Roland Häder + */ +public class OpeningTimeAddedEvent implements ObservableOpeningTimeAddedEvent { + + /** + * Serial number + */ + private static final long serialVersionUID = 572_367_561_659_111L; + + /** + * Branch office instance being added + */ + private final OpeningTime openingTime; + + /** + * Constructor with opening time instance + *

+ * @param openingTime Branch office instance + * @throws NullPointerException If the parameter is null + */ + public OpeningTimeAddedEvent (final OpeningTime openingTime) { + // Check parameter + if (null == openingTime) { + // Throw NPE + throw new NullPointerException("openingTime is null"); //NOI18N + } else if (openingTime.getOpeningId() == null) { + // Throw NPE again + throw new NullPointerException("openingTime.openingId is null"); //NOI18N + } else if (openingTime.getOpeningId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("openingTime.openingId={0} is not valid", openingTime.getOpeningId())); //NOI18N + } + + // Set it + this.openingTime = openingTime; + } + + @Override + public OpeningTime getOpeningTime () { + return this.openingTime; + } + +} diff --git a/src/org/mxchange/jcontactsbusiness/exceptions/opening_times/OpeningTimesNotFoundException.java b/src/org/mxchange/jcontactsbusiness/exceptions/opening_time/OpeningTimeNotFoundException.java similarity index 84% rename from src/org/mxchange/jcontactsbusiness/exceptions/opening_times/OpeningTimesNotFoundException.java rename to src/org/mxchange/jcontactsbusiness/exceptions/opening_time/OpeningTimeNotFoundException.java index d232b27..7fc610b 100644 --- a/src/org/mxchange/jcontactsbusiness/exceptions/opening_times/OpeningTimesNotFoundException.java +++ b/src/org/mxchange/jcontactsbusiness/exceptions/opening_time/OpeningTimeNotFoundException.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jcontactsbusiness.exceptions.opening_times; +package org.mxchange.jcontactsbusiness.exceptions.opening_time; import java.text.MessageFormat; @@ -23,7 +23,7 @@ import java.text.MessageFormat; *

* @author Roland Häder */ -public class OpeningTimesNotFoundException extends Exception { +public class OpeningTimeNotFoundException extends Exception { /** * Serial number @@ -35,7 +35,7 @@ public class OpeningTimesNotFoundException extends Exception { *

* @param openingId Opening time id */ - public OpeningTimesNotFoundException (final Long openingId) { + public OpeningTimeNotFoundException (final Long openingId) { // Call super constructor with message and cause super(MessageFormat.format("Opening time with id {0} was not found.", openingId)); //NOI18N } @@ -46,7 +46,7 @@ public class OpeningTimesNotFoundException extends Exception { * @param openingId Opening time id * @param cause Causing exception */ - public OpeningTimesNotFoundException (final Long openingId, final Throwable cause) { + public OpeningTimeNotFoundException (final Long openingId, final Throwable cause) { // Call super constructor with message and cause super(MessageFormat.format("Opening time with id {0} was not found.", openingId), cause); //NOI18N } diff --git a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffice.java b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffice.java index 798316c..11eef96 100644 --- a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffice.java +++ b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffice.java @@ -21,11 +21,11 @@ import java.util.Date; import java.util.List; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.employee.Employee; -import org.mxchange.jcontactsbusiness.model.opening_times.OpeningTimes; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; /** * A POJI for branch offices @@ -165,14 +165,14 @@ public interface BranchOffice extends Serializable { *

* @return Opening times */ - List getBranchOpeningTimes (); + List getBranchOpeningTimes (); /** * Setter for opening times for this branch office *

* @param branchOpeningTimes Opening times */ - void setBranchOpeningTimes (final List branchOpeningTimes); + void setBranchOpeningTimes (final List branchOpeningTimes); /** * Getter for branch office owning employee diff --git a/src/org/mxchange/jcontactsbusiness/model/branchoffice/CompanyBranchOffice.java b/src/org/mxchange/jcontactsbusiness/model/branchoffice/CompanyBranchOffice.java index e747688..5db5c8d 100644 --- a/src/org/mxchange/jcontactsbusiness/model/branchoffice/CompanyBranchOffice.java +++ b/src/org/mxchange/jcontactsbusiness/model/branchoffice/CompanyBranchOffice.java @@ -41,8 +41,8 @@ import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData; import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployee; import org.mxchange.jcontactsbusiness.model.employee.Employee; -import org.mxchange.jcontactsbusiness.model.opening_times.BusinessOpeningTimes; -import org.mxchange.jcontactsbusiness.model.opening_times.OpeningTimes; +import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime; +import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountryData; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; @@ -155,8 +155,8 @@ public class CompanyBranchOffice implements BranchOffice { * Opening times for this branch office */ @JoinTable (name = "branch_opening_times", joinColumns = @JoinColumn(name = "branch_opening_id", referencedColumnName = "branch_id"), inverseJoinColumns = @JoinColumn(name = "opening_branch_id", referencedColumnName = "opening_times_id")) - @ManyToMany (targetEntity = BusinessOpeningTimes.class, cascade = CascadeType.REFRESH) - private List branchOpeningTimes; + @ManyToMany (targetEntity = BusinessOpeningTime.class, cascade = CascadeType.REFRESH) + private List branchOpeningTimes; /** * Reference to branch office owner (for example some franchise supermarkets @@ -421,12 +421,14 @@ public class CompanyBranchOffice implements BranchOffice { } @Override - public List getBranchOpeningTimes () { + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getBranchOpeningTimes () { return this.branchOpeningTimes; } @Override - public void setBranchOpeningTimes (final List branchOpeningTimes) { + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setBranchOpeningTimes (final List branchOpeningTimes) { this.branchOpeningTimes = branchOpeningTimes; } diff --git a/src/org/mxchange/jcontactsbusiness/model/opening_times/BusinessOpeningTimes.java b/src/org/mxchange/jcontactsbusiness/model/opening_time/BusinessOpeningTime.java similarity index 93% rename from src/org/mxchange/jcontactsbusiness/model/opening_times/BusinessOpeningTimes.java rename to src/org/mxchange/jcontactsbusiness/model/opening_time/BusinessOpeningTime.java index b14dd50..c794ea1 100644 --- a/src/org/mxchange/jcontactsbusiness/model/opening_times/BusinessOpeningTimes.java +++ b/src/org/mxchange/jcontactsbusiness/model/opening_time/BusinessOpeningTime.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jcontactsbusiness.model.opening_times; +package org.mxchange.jcontactsbusiness.model.opening_time; import java.util.Date; import java.util.Objects; @@ -32,7 +32,7 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; -import org.mxchange.jcontactsbusiness.model.opening_times.dayofweek.DayOfTheWeek; +import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek; /** * A POJO for business opening hours @@ -48,7 +48,7 @@ import org.mxchange.jcontactsbusiness.model.opening_times.dayofweek.DayOfTheWeek } ) @SuppressWarnings ("PersistenceUnitPresent") -public class BusinessOpeningTimes implements OpeningTimes { +public class BusinessOpeningTime implements OpeningTime { /** * Serial number @@ -107,7 +107,7 @@ public class BusinessOpeningTimes implements OpeningTimes { /** * Default constructor */ - public BusinessOpeningTimes () { + public BusinessOpeningTime () { } /** @@ -118,7 +118,7 @@ public class BusinessOpeningTimes implements OpeningTimes { * @param openingStartDay Start day * @param openingStartTime Start time */ - public BusinessOpeningTimes (final DayOfTheWeek openingEndDay, final Date openingEndTime, final DayOfTheWeek openingStartDay, final Date openingStartTime) { + public BusinessOpeningTime (final DayOfTheWeek openingEndDay, final Date openingEndTime, final DayOfTheWeek openingStartDay, final Date openingStartTime) { // Set all fields this.openingEndDay = openingEndDay; this.openingEndTime = openingEndTime; @@ -136,7 +136,7 @@ public class BusinessOpeningTimes implements OpeningTimes { return false; } - final OpeningTimes openingTimes = (OpeningTimes) obj; + final OpeningTime openingTimes = (OpeningTime) obj; if (!Objects.equals(this.getOpeningId(), openingTimes.getOpeningId())) { return false; diff --git a/src/org/mxchange/jcontactsbusiness/model/opening_times/OpeningTimes.java b/src/org/mxchange/jcontactsbusiness/model/opening_time/OpeningTime.java similarity index 92% rename from src/org/mxchange/jcontactsbusiness/model/opening_times/OpeningTimes.java rename to src/org/mxchange/jcontactsbusiness/model/opening_time/OpeningTime.java index 42c9f80..404c365 100644 --- a/src/org/mxchange/jcontactsbusiness/model/opening_times/OpeningTimes.java +++ b/src/org/mxchange/jcontactsbusiness/model/opening_time/OpeningTime.java @@ -14,18 +14,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jcontactsbusiness.model.opening_times; +package org.mxchange.jcontactsbusiness.model.opening_time; import java.io.Serializable; import java.util.Date; -import org.mxchange.jcontactsbusiness.model.opening_times.dayofweek.DayOfTheWeek; +import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek; /** * A POJI for opening times * * @author Roland Häder */ -public interface OpeningTimes extends Serializable { +public interface OpeningTime extends Serializable { /** * Getter for opening time created timestamp diff --git a/src/org/mxchange/jcontactsbusiness/model/opening_times/dayofweek/DayOfTheWeek.java b/src/org/mxchange/jcontactsbusiness/model/opening_time/dayofweek/DayOfTheWeek.java similarity index 97% rename from src/org/mxchange/jcontactsbusiness/model/opening_times/dayofweek/DayOfTheWeek.java rename to src/org/mxchange/jcontactsbusiness/model/opening_time/dayofweek/DayOfTheWeek.java index 74f45b9..d6a8f26 100644 --- a/src/org/mxchange/jcontactsbusiness/model/opening_times/dayofweek/DayOfTheWeek.java +++ b/src/org/mxchange/jcontactsbusiness/model/opening_time/dayofweek/DayOfTheWeek.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jcontactsbusiness.model.opening_times.dayofweek; +package org.mxchange.jcontactsbusiness.model.opening_time.dayofweek; import java.text.SimpleDateFormat; import java.util.Calendar; -- 2.39.5