Search in sources :

Example 1 with PersonNameComponent

use of nl.knaw.huygens.timbuctoo.model.PersonNameComponent in project timbuctoo by HuygensING.

the class UriBearingPersonNames method insertNameComponentAtNaturalPosition.

private void insertNameComponentAtNaturalPosition(PersonNameComponent.Type nameType, String value, PersonName currentPersonName) {
    final List<PersonNameComponent> currentPersonNameComponents = currentPersonName.getComponents();
    int currentIndex = getNaturalComponentPos(nameType, currentPersonNameComponents);
    final PersonNameComponent newNameComponent = new PersonNameComponent(nameType, value);
    currentPersonNameComponents.add(currentIndex, newNameComponent);
}
Also used : PersonNameComponent(nl.knaw.huygens.timbuctoo.model.PersonNameComponent)

Example 2 with PersonNameComponent

use of nl.knaw.huygens.timbuctoo.model.PersonNameComponent in project timbuctoo by HuygensING.

the class PersonNameBuilderTest method testTwoComponentsReversed.

@Test
public void testTwoComponentsReversed() {
    PersonNameBuilder builder = new PersonNameBuilder();
    builder.addComponent(new PersonNameComponent(Type.SURNAME, "Huygens"));
    builder.addComponent(new PersonNameComponent(Type.FORENAME, "Christiaan"));
    assertThat(builder.getName(), equalTo("Huygens, Christiaan"));
}
Also used : PersonNameComponent(nl.knaw.huygens.timbuctoo.model.PersonNameComponent) PersonNameBuilder(nl.knaw.huygens.timbuctoo.model.PersonNameBuilder) Test(org.junit.Test)

Example 3 with PersonNameComponent

use of nl.knaw.huygens.timbuctoo.model.PersonNameComponent in project timbuctoo by HuygensING.

the class PersonNameBuilderTest method testOneComponent.

@Test
public void testOneComponent() {
    PersonNameBuilder builder = new PersonNameBuilder();
    builder.addComponent(new PersonNameComponent(Type.FORENAME, "Christiaan"));
    assertThat(builder.getName(), equalTo("Christiaan"));
}
Also used : PersonNameComponent(nl.knaw.huygens.timbuctoo.model.PersonNameComponent) PersonNameBuilder(nl.knaw.huygens.timbuctoo.model.PersonNameBuilder) Test(org.junit.Test)

Example 4 with PersonNameComponent

use of nl.knaw.huygens.timbuctoo.model.PersonNameComponent in project timbuctoo by HuygensING.

the class PersonNameBuilderTest method testTwoComponents.

@Test
public void testTwoComponents() {
    PersonNameBuilder builder = new PersonNameBuilder();
    builder.addComponent(new PersonNameComponent(Type.FORENAME, "Christiaan"));
    builder.addComponent(new PersonNameComponent(Type.SURNAME, "Huygens"));
    assertThat(builder.getName(), equalTo("Christiaan Huygens"));
}
Also used : PersonNameComponent(nl.knaw.huygens.timbuctoo.model.PersonNameComponent) PersonNameBuilder(nl.knaw.huygens.timbuctoo.model.PersonNameBuilder) Test(org.junit.Test)

Example 5 with PersonNameComponent

use of nl.knaw.huygens.timbuctoo.model.PersonNameComponent in project timbuctoo by HuygensING.

the class UriBearingPersonNames method removeComponent.

public void removeComponent(String nameUri, PersonNameComponent.Type nameType, String value) {
    if (!nameUris.containsKey(nameUri)) {
        LoggerFactory.getLogger(UriBearingPersonNames.class).error("Uri '{}' not known", nameUri);
        return;
    }
    PersonName personName = list.get(nameUris.get(nameUri));
    personName.getComponents().remove(new PersonNameComponent(nameType, value));
    if (personName.getComponents().isEmpty()) {
        list.remove(personName);
        Integer indexOfRemoved = nameUris.remove(nameUri);
        // reindex the name uri's, because the list will do this automatically.
        Map<String, Integer> newNameUris = Maps.newHashMap();
        nameUris.forEach((key, val) -> {
            if (val > indexOfRemoved) {
                val--;
            }
            newNameUris.put(key, val);
        });
        nameUris = newNameUris;
    }
}
Also used : PersonName(nl.knaw.huygens.timbuctoo.model.PersonName) PersonNameComponent(nl.knaw.huygens.timbuctoo.model.PersonNameComponent)

Aggregations

PersonNameComponent (nl.knaw.huygens.timbuctoo.model.PersonNameComponent)5 PersonNameBuilder (nl.knaw.huygens.timbuctoo.model.PersonNameBuilder)3 Test (org.junit.Test)3 PersonName (nl.knaw.huygens.timbuctoo.model.PersonName)1