/** * Constructs a new instance initialized with the values from the specified metadata object. * This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the * given object are not recursively copied. * * @param object the metadata to copy values from, or {@code null} if none. * * @see #castOrCopy(Telephone) */ public DefaultTelephone(final Telephone object) { super(object); if (object != null) { if (object instanceof DefaultTelephone) { number = ((DefaultTelephone) object).getNumber(); numberType = ((DefaultTelephone) object).numberType; } else { setVoices(object.getVoices()); setFacsimiles(object.getFacsimiles()); } } }
/** * Validates the given telephone information. * * @param object the object to validate, or {@code null}. * * @since 3.1 */ public void validate(final Telephone object) { if (object == null) { return; } mandatory("Telephone: shall have a number.", object.getNumber()); }
/** * Read and write a metadata object containing deprecated properties. * The metadata tested by this method is: * * {@preformat text * Telephone * ├─Number………………… 01.02.03.04 * └─Number type…… Voice * } * * The metadata should be stored in columns named {@code "number"} and {@code "numberType"} even if we * constructed the metadata using the deprecated {@code "voice"} property. Conversely, at reading time * the deprecated {@code "voice"} property should be converted in reading of non-deprecated properties. */ @SuppressWarnings("deprecation") private void readWriteDeprecated() throws MetadataStoreException { final DefaultTelephone tel = new DefaultTelephone(); tel.setVoices(Collections.singleton("01.02.03.04")); assertEquals("01.02.03.04", source.add(tel)); final Telephone check = source.lookup(Telephone.class, "01.02.03.04"); assertEquals("01.02.03.04", TestUtilities.getSingleton(check.getVoices())); } }
/** * Constructs a new instance initialized with the values from the specified metadata object. * This is a <cite>shallow</cite> copy constructor, since the other metadata contained in the * given object are not recursively copied. * * @param object the metadata to copy values from, or {@code null} if none. * * @see #castOrCopy(Telephone) */ public DefaultTelephone(final Telephone object) { super(object); if (object != null) { if (object instanceof DefaultTelephone) { number = ((DefaultTelephone) object).getNumber(); numberType = ((DefaultTelephone) object).numberType; } else { setVoices(object.getVoices()); setFacsimiles(object.getFacsimiles()); } } }
/** * Sets telephone numbers at which the organization or individual may be contacted. * This method delegates to {@link #setPhones(Collection)}. * * @param newValue the new telephone, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@link #setPhones(Collection)}. */ @Deprecated public void setPhone(Telephone newValue) { Collection<Telephone> newValues = null; if (newValue != null) { if (newValue instanceof DefaultTelephone) { newValues = ((DefaultTelephone) newValue).getOwner(); } else { newValues = new ArrayList<>(4); for (String number : newValue.getVoices()) { newValues.add(new DefaultTelephone(number, UnsupportedCodeList.VOICE)); } for (String number : newValue.getFacsimiles()) { newValues.add(new DefaultTelephone(number, UnsupportedCodeList.FACSIMILE)); } } } setPhones(newValues); }
/** * Sets telephone numbers at which the organization or individual may be contacted. * This method delegates to {@link #setPhones(Collection)}. * * @param newValue the new telephone, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@link #setPhones(Collection)}. */ @Deprecated public void setPhone(Telephone newValue) { Collection<Telephone> newValues = null; if (newValue != null) { if (newValue instanceof DefaultTelephone) { newValues = ((DefaultTelephone) newValue).getOwner(); } else { newValues = new ArrayList<>(4); for (String number : newValue.getVoices()) { newValues.add(new DefaultTelephone(number, UnsupportedCodeList.VOICE)); } for (String number : newValue.getFacsimiles()) { newValues.add(new DefaultTelephone(number, UnsupportedCodeList.FACSIMILE)); } } } setPhones(newValues); }
/** * Verify that the {@link DefaultTelephone#getVoices()} and {@link DefaultTelephone#getFacsimiles()} methods see * all numbers declared in the parent {@link DefaultContact}. This method presumes that each telephone contains: * * <ul> * <li>Two voice numbers: "00.02" and "00.04" in that order.</li> * <li>One facsimile number: "00.03".</li> * </ul> */ @SuppressWarnings("deprecation") private static void verifyLegacyLists(final Telephone... tels) { final String[] voices = {"00.02", "00.04"}; final String[] facsimiles = {"00.03"}; for (final Telephone tel : tels) { assertArrayEquals("getVoices", voices, tel.getVoices() .toArray()); assertArrayEquals("getFacsimiles", facsimiles, tel.getFacsimiles().toArray()); } }