/** * set the role or position of the responsible person Only one of * {@link #getIndividualName() individualName}, {@link #getOrganisationName() organisationName} * and {@code positionName} shall be provided. * * <p>This implementation sets the position name of the first {@code Individual} found in the collection of * {@linkplain #getParties() parties}, or create a new individual if no existing instance was found.</p> * * @param newValue the new position name, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@link DefaultIndividual#setPositionName(InternationalString)}. */ @Deprecated public void setPositionName(final InternationalString newValue) { if (!setName(DefaultIndividual.class, true, newValue)) { getParties().add(new DefaultIndividual(null, newValue, null)); } }
/** * Returns the name of the responsible organization. Only one of * {@link #getIndividualName() individualName}, {@code organisationName} * and {@link #getPositionName() positionName} shall be provided. * * <p>This implementation returns the name of the first {@code Organisation} * found in the collection of {@linkplain #getParties() parties}.</p> * * @return name of the responsible organization, or {@code null}. * * @deprecated As of ISO 19115:2014, replaced by {@code getName()} in {@link DefaultOrganisation}. */ @Override @Deprecated @XmlElement(name = "organisationName") @Dependencies("getParties") public InternationalString getOrganisationName() { return getName(getParties(), DefaultOrganisation.class, false); }
/** * Returns the name of the responsible organization. Only one of * {@link #getIndividualName() individualName}, {@code organisationName} * and {@link #getPositionName() positionName} shall be provided. * * <p>This implementation returns the name of the first {@code Organisation} * found in the collection of {@linkplain #getParties() parties}.</p> * * @return name of the responsible organization, or {@code null}. * * @deprecated As of ISO 19115:2014, replaced by {@code getName()} in {@link DefaultOrganisation}. */ @Override @Deprecated @XmlElement(name = "organisationName") @Dependencies("getParties") public InternationalString getOrganisationName() { return getName(getParties(), DefaultOrganisation.class, false); }
/** * set the role or position of the responsible person Only one of * {@link #getIndividualName() individualName}, {@link #getOrganisationName() organisationName} * and {@code positionName} shall be provided. * * <p>This implementation sets the position name of the first {@code Individual} found in the collection of * {@linkplain #getParties() parties}, or create a new individual if no existing instance was found.</p> * * @param newValue the new position name, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@link DefaultIndividual#setPositionName(InternationalString)}. */ @Deprecated public void setPositionName(final InternationalString newValue) { if (!setName(DefaultIndividual.class, true, newValue)) { getParties().add(new DefaultIndividual(null, newValue, null)); } }
/** * Sets the address of the responsible party. * * <p>This implementation sets the contact info in the first party found in the collection of * {@linkplain #getParties() parties}.</p> * * @param newValue the new contact info, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@link AbstractParty#setContactInfo(Collection)}. */ @Deprecated public void setContactInfo(final Contact newValue) { checkWritePermission(); final Iterator<AbstractParty> it = getParties().iterator(); while (it.hasNext()) { final AbstractParty party = it.next(); party.setContactInfo(newValue != null ? Collections.singleton(newValue) : null); if (party.isEmpty()) { it.remove(); } return; } /* * If no existing AbstractParty were found, add a new one. However there is no way to know if * it should be an individual or an organization. Arbitrarily choose an individual for now. */ if (newValue != null) { getParties().add(new DefaultIndividual(null, null, newValue)); } }
/** * Sets the name of the responsible organization. Only one of * {@link #getIndividualName() individualName}, {@code organisationName} * and {@link #getPositionName() positionName} shall be provided. * * <p>This implementation sets the name of the first {@code Organisation} found in the collection of * {@linkplain #getParties() parties}, or create a new organization if no existing instance was found.</p> * * @param newValue the new organization name, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@code setName(InternationalString)} in {@link DefaultOrganisation}. */ @Deprecated public void setOrganisationName(final InternationalString newValue) { if (!setName(DefaultOrganisation.class, false, Types.toInternationalString(newValue))) { getParties().add(new DefaultOrganisation(newValue, null, null, null)); } }
/** * Sets the name of the responsible organization. Only one of * {@link #getIndividualName() individualName}, {@code organisationName} * and {@link #getPositionName() positionName} shall be provided. * * <p>This implementation sets the name of the first {@code Organisation} found in the collection of * {@linkplain #getParties() parties}, or create a new organization if no existing instance was found.</p> * * @param newValue the new organization name, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@code setName(InternationalString)} in {@link DefaultOrganisation}. */ @Deprecated public void setOrganisationName(final InternationalString newValue) { if (!setName(DefaultOrganisation.class, false, Types.toInternationalString(newValue))) { getParties().add(new DefaultOrganisation(newValue, null, null, null)); } }
/** * Returns the address of the responsible party. * * <p>This implementation returns the first non-null contact found in the collection of * {@linkplain #getParties() parties}.</p> * * @return address of the responsible party, or {@code null}. * * @deprecated As of ISO 19115:2014, replaced by {@link AbstractParty#getContactInfo()}. */ @Override @Deprecated @XmlElement(name = "contactInfo") @Dependencies("getParties") public Contact getContactInfo() { final Collection<AbstractParty> parties = getParties(); if (parties != null) { // May be null on marshalling. for (final AbstractParty party : parties) { final Collection<? extends Contact> contacts = party.getContactInfo(); if (contacts != null) { // May be null on marshalling. for (final Contact contact : contacts) { if (contact != null) { // Paranoiac check. return contact; } } } } } return null; }
/** * Sets the name of the responsible person- surname, given name, title separated by a delimiter. * Only one of {@code individualName}, {@link #getOrganisationName() organisationName} * and {@link #getPositionName() positionName} shall be provided. * * <p>This implementation sets the name of the first {@code Individual} found in the collection of * {@linkplain #getParties() parties}, or create a new individual if no existing instance was found.</p> * * @param newValue the new individual name, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@code setName(InternationalString)} in {@link DefaultIndividual}. */ @Deprecated public void setIndividualName(final String newValue) { if (!setName(DefaultIndividual.class, false, Types.toInternationalString(newValue))) { getParties().add(new DefaultIndividual(newValue, null, null)); } }
/** * Returns the address of the responsible party. * * <p>This implementation returns the first non-null contact found in the collection of * {@linkplain #getParties() parties}.</p> * * @return address of the responsible party, or {@code null}. * * @deprecated As of ISO 19115:2014, replaced by {@link AbstractParty#getContactInfo()}. */ @Override @Deprecated @XmlElement(name = "contactInfo") @Dependencies("getParties") public Contact getContactInfo() { final Collection<AbstractParty> parties = getParties(); if (parties != null) { // May be null on marshalling. for (final AbstractParty party : parties) { final Collection<? extends Contact> contacts = party.getContactInfo(); if (contacts != null) { // May be null on marshalling. for (final Contact contact : contacts) { if (contact != null) { // Paranoiac check. return contact; } } } } } return null; }
/** * Sets the name of the responsible person- surname, given name, title separated by a delimiter. * Only one of {@code individualName}, {@link #getOrganisationName() organisationName} * and {@link #getPositionName() positionName} shall be provided. * * <p>This implementation sets the name of the first {@code Individual} found in the collection of * {@linkplain #getParties() parties}, or create a new individual if no existing instance was found.</p> * * @param newValue the new individual name, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@code setName(InternationalString)} in {@link DefaultIndividual}. */ @Deprecated public void setIndividualName(final String newValue) { if (!setName(DefaultIndividual.class, false, Types.toInternationalString(newValue))) { getParties().add(new DefaultIndividual(newValue, null, null)); } }
/** * Sets the address of the responsible party. * * <p>This implementation sets the contact info in the first party found in the collection of * {@linkplain #getParties() parties}.</p> * * @param newValue the new contact info, or {@code null} if none. * * @deprecated As of ISO 19115:2014, replaced by {@link AbstractParty#setContactInfo(Collection)}. */ @Deprecated public void setContactInfo(final Contact newValue) { checkWritePermission(valueIfDefined(super.getParties())); final Iterator<AbstractParty> it = getParties().iterator(); while (it.hasNext()) { final AbstractParty party = it.next(); party.setContactInfo(newValue != null ? Collections.singleton(newValue) : null); if (party.isEmpty()) { it.remove(); } return; } /* * If no existing AbstractParty were found, add a new one. However there is no way to know if * it should be an individual or an organization. Arbitrarily choose an individual for now. */ if (newValue != null) { getParties().add(new DefaultIndividual(null, null, newValue)); } }
/** * Sets the name of the first party of the given type. * * @return {@code true} if the name has been set, or {@code false} otherwise. */ private boolean setName(final Class<? extends AbstractParty> type, final boolean position, final InternationalString name) { checkWritePermission(); final Iterator<AbstractParty> it = getParties().iterator(); while (it.hasNext()) { final AbstractParty party = it.next(); if (type.isInstance(party)) { if (position) { ((DefaultIndividual) party).setPositionName(name); } else { party.setName(name); } if (party.isEmpty()) { it.remove(); } return true; } } return name == null; // If no party and name is null, there is nothing to set. }
/** * Sets the name of the first party of the given type. * * @return {@code true} if the name has been set, or {@code false} otherwise. */ private boolean setName(final Class<? extends AbstractParty> type, final boolean position, final InternationalString name) { checkWritePermission(valueIfDefined(super.getParties())); final Iterator<AbstractParty> it = getParties().iterator(); while (it.hasNext()) { final AbstractParty party = it.next(); if (type.isInstance(party)) { if (position) { ((DefaultIndividual) party).setPositionName(name); } else { party.setName(name); } if (party.isEmpty()) { it.remove(); } return true; } } return name == null; // If no party and name is null, there is nothing to set. }
/** * Commits all pending information under the "responsible party" node (author, address, <i>etc</i>). * If there is no pending party information, then invoking this method has no effect * except setting the {@code type} flag. * If new party information are added after this method call, they will be stored in a new element. * * <p>This method does not need to be invoked unless a new "responsible party" node, * separated from the previous one, is desired.</p> * * @param type whether the party to create is an individual or an organization. */ public final void newParty(final PartyType type) { ArgumentChecks.ensureNonNull("type", type); if (party != null) { addIfNotPresent(responsibility().getParties(), party); party = null; } partyType = type; }
/** * Commits all pending information under the "responsible party" node (author, address, <i>etc</i>). * If there is no pending party information, then invoking this method has no effect * except setting the {@code type} flag. * If new party information are added after this method call, they will be stored in a new element. * * <p>This method does not need to be invoked unless a new "responsible party" node, * separated from the previous one, is desired.</p> * * @param type whether the party to create is an individual or an organization. */ public final void newParty(final PartyType type) { ArgumentChecks.ensureNonNull("type", type); if (party != null) { addIfNotPresent(responsibility().getParties(), party); party = null; } partyType = type; }
/** * Returns the name or the position of the first individual. If no individual is found in the list of parties, * then this method will search in the list of organization members. The later structure is used by our netCDF * reader. * * @param position {@code true} for returning the position name instead than individual name. * @return the name or position of the first individual, or {@code null}. * * @see #getIndividualName() * @see #getPositionName() */ private InternationalString getIndividual(final boolean position) { final Collection<AbstractParty> parties = getParties(); InternationalString name = getName(parties, DefaultIndividual.class, position); if (name == null && parties != null) { for (final AbstractParty party : parties) { if (party instanceof DefaultOrganisation) { name = getName(((DefaultOrganisation) party).getIndividual(), DefaultIndividual.class, position); if (name != null) { break; } } } } return name; }
/** * Returns the name or the position of the first individual. If no individual is found in the list of parties, * then this method will search in the list of organization members. The later structure is used by our netCDF * reader. * * @param position {@code true} for returning the position name instead than individual name. * @return the name or position of the first individual, or {@code null}. * * @see #getIndividualName() * @see #getPositionName() */ private InternationalString getIndividual(final boolean position) { final Collection<AbstractParty> parties = getParties(); InternationalString name = getName(parties, DefaultIndividual.class, position); if (name == null && parties != null) { for (final AbstractParty party : parties) { if (party instanceof DefaultOrganisation) { name = getName(((DefaultOrganisation) party).getIndividual(), DefaultIndividual.class, position); if (name != null) { break; } } } } return name; }
/** * Tests hash code computation of an object containing another metadata object. */ @Test @DependsOnMethod("testSimple") public void testNested() { final InternationalString title = new SimpleInternationalString("Some title"); final InternationalString person = new SimpleInternationalString("Illustre inconnu"); final DefaultIndividual party = new DefaultIndividual(person, null, null); final DefaultResponsibleParty resp = new DefaultResponsibleParty(Role.AUTHOR); final DefaultCitation instance = new DefaultCitation(title); resp.getParties().add(party); instance.getCitedResponsibleParties().add(resp); /* * Individual hash code is the sum of all its properties, none of them being a collection. */ int expected = DefaultIndividual.class.hashCode() + person.hashCode(); assertEquals("Individual", Integer.valueOf(expected), hash(party)); /* * The +31 below come from java.util.List contract, since above Individual is a list member. */ expected += ResponsibleParty.class.hashCode() + Role.AUTHOR.hashCode() + 31; assertEquals("Responsibility", Integer.valueOf(expected), hash(resp)); /* * The +31 below come from java.util.List contract, since above Responsibility is a list member. */ expected += Citation.class.hashCode() + title.hashCode() + 31; assertEquals("Citation", Integer.valueOf(expected), hash(instance)); }
/** * Asserts that the given responsibility has the expected properties, then returns its contact info. */ private static Contact assertResponsibilityEquals(final Role role, final String name, final ResponsibleParty actual) { assertEquals("role", role, actual.getRole()); final AbstractParty p = getSingleton(((DefaultResponsibleParty) actual).getParties()); assertEquals("name", name, p.getName().toString()); return getSingleton(p.getContactInfo()); } }