From: Roland Häder Date: Mon, 26 Jun 2017 18:48:27 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3347f78e766f63e40d4d139e72591a15865af752;p=jphone-core.git Continued: - added utility classes which will be the homes for any non-getter/setter methods from POJOs as this is not recommended to have "complex" methods in POJOs (aka entity class) - moved copyAll() methods to newly added utilities classes Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jphone/phonenumbers/fax/DialableFaxNumber.java b/src/org/mxchange/jphone/phonenumbers/fax/DialableFaxNumber.java index 1e1226c..a8976c1 100644 --- a/src/org/mxchange/jphone/phonenumbers/fax/DialableFaxNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/fax/DialableFaxNumber.java @@ -25,16 +25,10 @@ import org.mxchange.jphone.phonenumbers.DialableNumber; */ public interface DialableFaxNumber extends DialableNumber { - /** - * Copy all fields from source object to this - *

- * @param sourceNumber Source number object - */ - void copyAll (final DialableFaxNumber sourceNumber); - @Override boolean equals (final Object object); @Override int hashCode (); + } diff --git a/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java b/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java index 40d1124..bcea5cb 100644 --- a/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java @@ -125,22 +125,6 @@ public class FaxNumber implements DialableFaxNumber { this.phoneNumber = faxNumber; } - @Override - public void copyAll (final DialableFaxNumber sourceNumber) { - // Validate instance - if (null == sourceNumber) { - // Throw NPE - throw new NullPointerException("sourceNumber is null"); //NOI18N - } - - // Copy all - this.setPhoneAreaCode(sourceNumber.getPhoneAreaCode()); - this.getPhoneCountry().copyAll(sourceNumber.getPhoneCountry()); - this.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated()); - this.setPhoneId(sourceNumber.getPhoneId()); - this.setPhoneNumber(sourceNumber.getPhoneNumber()); - } - @Override public boolean equals (final Object object) { if (null == object) { diff --git a/src/org/mxchange/jphone/phonenumbers/fax/FaxNumbers.java b/src/org/mxchange/jphone/phonenumbers/fax/FaxNumbers.java new file mode 100644 index 0000000..580f4df --- /dev/null +++ b/src/org/mxchange/jphone/phonenumbers/fax/FaxNumbers.java @@ -0,0 +1,63 @@ +/* + * 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.jphone.phonenumbers.fax; + +import java.io.Serializable; + +/** + * An utilities class for fax numbers + *

+ * @author Roland Häder + */ +public class FaxNumbers implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 1_948_653_672_761L; + + /** + * Copy all fields from source object to this + *

+ * @param sourceNumber Source number object + * @param targetNumber Target number object + */ + public static void copyAll (final DialableFaxNumber sourceNumber, final DialableFaxNumber targetNumber) { + // Validate instance + if (null == sourceNumber) { + // Throw NPE + throw new NullPointerException("sourceNumber is null"); //NOI18N + } else if (null == targetNumber) { + // Throw NPE + throw new NullPointerException("targetNumber is null"); //NOI18N + } + + // Copy all + targetNumber.setPhoneAreaCode(sourceNumber.getPhoneAreaCode()); + targetNumber.setPhoneCountry(sourceNumber.getPhoneCountry()); + targetNumber.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated()); + targetNumber.setPhoneId(sourceNumber.getPhoneId()); + targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber()); + } + + /** + * No constructor for utilities classes + */ + private FaxNumbers () { + } + +} diff --git a/src/org/mxchange/jphone/phonenumbers/landline/DialableLandLineNumber.java b/src/org/mxchange/jphone/phonenumbers/landline/DialableLandLineNumber.java index 10a2002..5b5a04b 100644 --- a/src/org/mxchange/jphone/phonenumbers/landline/DialableLandLineNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/landline/DialableLandLineNumber.java @@ -25,13 +25,6 @@ import org.mxchange.jphone.phonenumbers.DialableNumber; */ public interface DialableLandLineNumber extends DialableNumber { - /** - * Copy all fields from source object to this - *

- * @param sourceNumber Source number object - */ - void copyAll (final DialableLandLineNumber sourceNumber); - @Override boolean equals (final Object object); diff --git a/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java b/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java index 69ad3bc..f7c809b 100644 --- a/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java @@ -125,22 +125,6 @@ public class LandLineNumber implements DialableLandLineNumber { this.phoneNumber = phoneNumber; } - @Override - public void copyAll (final DialableLandLineNumber sourceNumber) { - // Validate instance - if (null == sourceNumber) { - // Throw NPE - throw new NullPointerException("sourceNumber is null"); //NOI18N - } - - // Copy all - this.setPhoneAreaCode(sourceNumber.getPhoneAreaCode()); - this.getPhoneCountry().copyAll(sourceNumber.getPhoneCountry()); - this.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated()); - this.setPhoneId(sourceNumber.getPhoneId()); - this.setPhoneNumber(sourceNumber.getPhoneNumber()); - } - @Override public boolean equals (final Object object) { if (null == object) { diff --git a/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumbers.java b/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumbers.java new file mode 100644 index 0000000..6f67f7a --- /dev/null +++ b/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumbers.java @@ -0,0 +1,63 @@ +/* + * 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 targetNumber program. If not, see . + */ +package org.mxchange.jphone.phonenumbers.landline; + +import java.io.Serializable; + +/** + * An utilities class for land-line numbers + *

+ * @author Roland Häder + */ +public class LandLineNumbers implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 18_698_467_372_167_561L; + + /** + * Copy all fields from source object to this + *

+ * @param sourceNumber Source number object + * @param targetNumber Target number object + */ + public static void copyAll (final DialableLandLineNumber sourceNumber, final DialableLandLineNumber targetNumber) { + // Validate instance + if (null == sourceNumber) { + // Throw NPE + throw new NullPointerException("sourceNumber is null"); //NOI18N + } else if (null == targetNumber) { + // Throw NPE + throw new NullPointerException("targetNumber is null"); //NOI18N + } + + // Copy all + targetNumber.setPhoneAreaCode(sourceNumber.getPhoneAreaCode()); + targetNumber.setPhoneCountry(sourceNumber.getPhoneCountry()); + targetNumber.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated()); + targetNumber.setPhoneId(sourceNumber.getPhoneId()); + targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber()); + } + + /** + * No constructor for utilities classes + */ + private LandLineNumbers () { + } + +} diff --git a/src/org/mxchange/jphone/phonenumbers/mobile/DialableMobileNumber.java b/src/org/mxchange/jphone/phonenumbers/mobile/DialableMobileNumber.java index 9c4fc7d..554b214 100644 --- a/src/org/mxchange/jphone/phonenumbers/mobile/DialableMobileNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/mobile/DialableMobileNumber.java @@ -40,13 +40,6 @@ public interface DialableMobileNumber extends DialableNumber { */ void setMobileProvider (final MobileProvider mobileProvider); - /** - * Copy all fields from source object to this - *

- * @param sourceNumber Source number object - */ - void copyAll (final DialableMobileNumber sourceNumber); - @Override boolean equals (final Object object); diff --git a/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumber.java b/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumber.java index e3cf83f..36e9e2a 100644 --- a/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumber.java @@ -34,7 +34,6 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import org.mxchange.jcountry.data.Country; -import org.mxchange.jphone.phonenumbers.mobileprovider.CellphoneProvider; import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; /** @@ -63,7 +62,7 @@ public class MobileNumber implements DialableMobileNumber { * Connection to table "mobile_provider" (for dial prefix and more data) */ @JoinColumn (name = "mobile_provider_id", nullable = false) - @OneToOne (targetEntity = CellphoneProvider.class, cascade = CascadeType.REFRESH, optional = false) + @OneToOne (targetEntity = MobileProvider.class, cascade = CascadeType.REFRESH, optional = false) private MobileProvider mobileProvider; /** @@ -117,21 +116,6 @@ public class MobileNumber implements DialableMobileNumber { this.phoneNumber = mobileNumber; } - @Override - public void copyAll (final DialableMobileNumber sourceNumber) { - // Validate instance - if (null == sourceNumber) { - // Throw NPE - throw new NullPointerException("sourceNumber is null"); //NOI18N - } - - // Copy all - this.getMobileProvider().copyAll(sourceNumber.getMobileProvider()); - this.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated()); - this.setPhoneId(sourceNumber.getPhoneId()); - this.setPhoneNumber(sourceNumber.getPhoneNumber()); - } - @Override public boolean equals (final Object object) { if (null == object) { @@ -166,13 +150,13 @@ public class MobileNumber implements DialableMobileNumber { @Override @Deprecated public Integer getPhoneAreaCode () { - throw new UnsupportedOperationException("Cellphone numbers don't have area codes. Please fix your code."); //NOI18N + throw new UnsupportedOperationException("Mobile numbers don't have area codes. Please fix your code."); //NOI18N } @Override @Deprecated public void setPhoneAreaCode (final Integer phoneAreaCode) { - throw new UnsupportedOperationException("Cellphone numbers don't have area codes. Please fix your code."); //NOI18N + throw new UnsupportedOperationException("Mobile numbers don't have area codes. Please fix your code."); //NOI18N } @Override diff --git a/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumbers.java b/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumbers.java new file mode 100644 index 0000000..89e57f8 --- /dev/null +++ b/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumbers.java @@ -0,0 +1,62 @@ +/* + * 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 targetNumber program. If not, see . + */ +package org.mxchange.jphone.phonenumbers.mobile; + +import java.io.Serializable; + +/** + * An utilities class for mobile numbers + *

+ * @author Roland Häder + */ +public class MobileNumbers implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 291_608_496_882_761L; + + /** + * Copy all fields from source object to this + *

+ * @param sourceNumber Source number object + * @param targetNumber Target number object + */ + public static void copyAll (final DialableMobileNumber sourceNumber, final DialableMobileNumber targetNumber) { + // Validate instance + if (null == sourceNumber) { + // Throw NPE + throw new NullPointerException("sourceNumber is null"); //NOI18N + } else if (null == targetNumber) { + // Throw NPE + throw new NullPointerException("targetNumber is null"); //NOI18N + } + + // Copy all fields + targetNumber.setMobileProvider(sourceNumber.getMobileProvider()); + targetNumber.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated()); + targetNumber.setPhoneId(sourceNumber.getPhoneId()); + targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber()); + } + + /** + * No constructor for utilities classes + */ + private MobileNumbers () { + } + +} diff --git a/src/org/mxchange/jphone/phonenumbers/mobileprovider/CellphoneProvider.java b/src/org/mxchange/jphone/phonenumbers/mobileprovider/CellphoneProvider.java index 1212ef5..431a945 100644 --- a/src/org/mxchange/jphone/phonenumbers/mobileprovider/CellphoneProvider.java +++ b/src/org/mxchange/jphone/phonenumbers/mobileprovider/CellphoneProvider.java @@ -123,23 +123,6 @@ public class CellphoneProvider implements MobileProvider { this.providerMailPattern = providerMailPattern; } - @Override - public void copyAll (final MobileProvider sourceMobileProvider) { - // Parameter should not be null - if (null == sourceMobileProvider) { - // Throw NPE - throw new NullPointerException("sourceMobileProvider is null"); //NOI18N - } - - // Copy all values - this.getProviderCountry().copyAll(sourceMobileProvider.getProviderCountry()); - this.setProviderDialPrefix(sourceMobileProvider.getProviderDialPrefix()); - this.setProviderEntryCreated(sourceMobileProvider.getProviderEntryCreated()); - this.setProviderId(sourceMobileProvider.getProviderId()); - this.setProviderMailPattern(sourceMobileProvider.getProviderMailPattern()); - this.setProviderName(sourceMobileProvider.getProviderName()); - } - @Override public boolean equals (final Object object) { if (null == object) { diff --git a/src/org/mxchange/jphone/phonenumbers/mobileprovider/MobileProvider.java b/src/org/mxchange/jphone/phonenumbers/mobileprovider/MobileProvider.java index 3f2c13e..a5b328d 100644 --- a/src/org/mxchange/jphone/phonenumbers/mobileprovider/MobileProvider.java +++ b/src/org/mxchange/jphone/phonenumbers/mobileprovider/MobileProvider.java @@ -27,13 +27,6 @@ import org.mxchange.jcountry.data.Country; */ public interface MobileProvider extends Serializable { - /** - * Copies all values from source mobile provider to this - *

- * @param sourceMobileProvider Source mobile provider - */ - void copyAll (final MobileProvider sourceMobileProvider); - /** * Getter for id number *

diff --git a/src/org/mxchange/jphone/phonenumbers/mobileprovider/MobileProviders.java b/src/org/mxchange/jphone/phonenumbers/mobileprovider/MobileProviders.java new file mode 100644 index 0000000..c2e0b1e --- /dev/null +++ b/src/org/mxchange/jphone/phonenumbers/mobileprovider/MobileProviders.java @@ -0,0 +1,65 @@ +/* + * 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 targetMobileProvider program. If not, see . + */ +package org.mxchange.jphone.phonenumbers.mobileprovider; + +import java.io.Serializable; + +/** + * An utilities class for mobile providers + *

+ * @author Roland Häder + */ +public class MobileProviders implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 15_468_608_721_651L; + + /** + * Copies all values from source mobile provider to this + *

+ * @param sourceMobileProvider Source mobile provider + * @param targetMobileProvider Target mobile provider + */ + public static void copyAll (final MobileProvider sourceMobileProvider, final MobileProvider targetMobileProvider) { + // Parameter should not be null + if (null == sourceMobileProvider) { + // Throw NPE + throw new NullPointerException("sourceMobileProvider is null"); //NOI18N + } else if (null == targetMobileProvider) { + // Throw NPE + throw new NullPointerException("targetMobileProvider is null"); //NOI18N + } + + // Copy all values + targetMobileProvider.getProviderCountry().copyAll(sourceMobileProvider.getProviderCountry()); + targetMobileProvider.setProviderDialPrefix(sourceMobileProvider.getProviderDialPrefix()); + targetMobileProvider.setProviderEntryCreated(sourceMobileProvider.getProviderEntryCreated()); + targetMobileProvider.setProviderId(sourceMobileProvider.getProviderId()); + targetMobileProvider.setProviderMailPattern(sourceMobileProvider.getProviderMailPattern()); + targetMobileProvider.setProviderName(sourceMobileProvider.getProviderName()); + } + + /** + * Private constructor, because there is no need for an instance of + * targetMobileProvider class. + */ + private MobileProviders () { + } + +}