From e473bf62f32cb4a685974da095833cc19a61d80a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 7 Sep 2016 18:05:26 +0200 Subject: [PATCH] Continued a bit: - added copyAll() + used it to copy only values --- .../jphone/phonenumbers/fax/FaxNumber.java | 8 +++++++- .../phonenumbers/landline/LandLineNumber.java | 8 +++++++- .../phonenumbers/mobile/MobileNumber.java | 8 +++++++- .../mobileprovider/CellphoneProvider.java | 17 +++++++++++++++++ .../mobileprovider/MobileProvider.java | 7 +++++++ 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java b/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java index e9774de..0e2cf05 100644 --- a/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java @@ -127,9 +127,15 @@ public class FaxNumber implements DialableFaxNumber { @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.setPhoneCountry(sourceNumber.getPhoneCountry()); + this.getPhoneCountry().copyAll(sourceNumber.getPhoneCountry()); this.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated()); this.setPhoneId(sourceNumber.getPhoneId()); this.setPhoneNumber(sourceNumber.getPhoneNumber()); diff --git a/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java b/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java index 7411cf5..b9ca58c 100644 --- a/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java @@ -127,9 +127,15 @@ public class LandLineNumber implements DialableLandLineNumber { @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.setPhoneCountry(sourceNumber.getPhoneCountry()); + this.getPhoneCountry().copyAll(sourceNumber.getPhoneCountry()); this.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated()); this.setPhoneId(sourceNumber.getPhoneId()); this.setPhoneNumber(sourceNumber.getPhoneNumber()); diff --git a/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumber.java b/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumber.java index ac2a0c2..d553c94 100644 --- a/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/mobile/MobileNumber.java @@ -119,8 +119,14 @@ public class MobileNumber implements DialableMobileNumber { @Override public void copyAll (final DialableMobileNumber sourceNumber) { + // Validate instance + if (null == sourceNumber) { + // Throw NPE + throw new NullPointerException("sourceNumber is null"); //NOI18N + } + // Copy all - this.setMobileProvider(sourceNumber.getMobileProvider()); + this.getMobileProvider().copyAll(sourceNumber.getMobileProvider()); this.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated()); this.setPhoneId(sourceNumber.getPhoneId()); this.setPhoneNumber(sourceNumber.getPhoneNumber()); diff --git a/src/org/mxchange/jphone/phonenumbers/mobileprovider/CellphoneProvider.java b/src/org/mxchange/jphone/phonenumbers/mobileprovider/CellphoneProvider.java index dc20772..b31ce49 100644 --- a/src/org/mxchange/jphone/phonenumbers/mobileprovider/CellphoneProvider.java +++ b/src/org/mxchange/jphone/phonenumbers/mobileprovider/CellphoneProvider.java @@ -123,6 +123,23 @@ 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 77fe960..687ddb7 100644 --- a/src/org/mxchange/jphone/phonenumbers/mobileprovider/MobileProvider.java +++ b/src/org/mxchange/jphone/phonenumbers/mobileprovider/MobileProvider.java @@ -27,6 +27,13 @@ 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 *

-- 2.39.5