@Test public void testSetTitles() { List<String> newTitles = Arrays.asList("MTITLE[1][0]-update"); List<String> newSubtitles = Arrays.asList("STITLE[1][new[0]]", "STITLE[1][0]", "STITLE[1][new[2]]"); List<String> newAltTitles = Arrays.asList("ATITLE[0][new[0]]"); List<String> newKeyTitles = Arrays.asList("KTITLE[2][0]-update", "KTITLE[2][new[1]]"); ModsDefinition mods = ModsUtils.unmarshal(XML, ModsDefinition.class); TitleInfoMapper instance = new TitleInfoMapper(mods); instance.setTitles(newTitles, newSubtitles); instance.setKeyTitles(newKeyTitles); instance.setAlternativeTitles(newAltTitles); TitleInfoMapper read = new TitleInfoMapper(mods); List<String> titleResult = read.getTitles(); List<String> subtitleResult = read.getSubtitles(); List<String> alternativeResult = read.getAlternativeTitles(); List<String> keyResult = read.getKeyTitles(); List<String> titleExpected = Arrays.asList("MTITLE[1][0]-update"); List<String> subtitleExpected = Arrays.asList("STITLE[1][new[0]]", "STITLE[1][0]", "STITLE[1][new[2]]"); List<String> alternativeExpected = Arrays.asList("ATITLE[0][new[0]]"); List<String> keyExpected = Arrays.asList("KTITLE[2][0]-update", "KTITLE[2][new[1]]"); assertThat(titleResult, Is.is(titleExpected)); assertThat(subtitleResult, Is.is(subtitleExpected)); assertThat(alternativeResult, Is.is(alternativeExpected)); assertThat(keyResult, Is.is(keyExpected)); System.out.println(ModsUtils.toXml(mods, true)); }
public void setTitles(List<String> newTitles, List<String> newSubtitles) { newTitles = MapperUtils.noNull(newTitles); newSubtitles = MapperUtils.noNull(newSubtitles); searchNodes(); if (titleNode == null) { if (newTitles.isEmpty() && newSubtitles.isEmpty()) { return ; } titleNode = factory.createTitleInfoDefinition(); mods.getTitleInfo().add(titleNode); } updateTitles(titleNode, newTitles); List<StringPlusLanguage> subTitle = titleNode.getSubTitle(); subTitle.clear(); subTitle.addAll(MapperUtils.toStringPlusLanguage(newSubtitles)); }
TitleInfoMapper { public void setTitles(List<String> newTitles, List<String> newSubtitles) { newTitles = MapperUtils.noNull(newTitles); newSubtitles = MapperUtils.noNull(newSubtitles); searchNodes(); if (titleNode == null) { if (newTitles.isEmpty() && newSubtitles.isEmpty()) { return ; } titleNode = factory.createTitleInfoDefinition(); mods.getTitleInfo().add(titleNode); } updateTitles(titleNode, newTitles); List<StringPlusLanguage> subTitle = titleNode.getSubTitle(); subTitle.clear(); subTitle.addAll(MapperUtils.toStringPlusLanguage(newSubtitles)); } }
TitleInfoMapper { public void setTitles(List<String> newTitles, List<String> newSubtitles) { newTitles = MapperUtils.noNull(newTitles); newSubtitles = MapperUtils.noNull(newSubtitles); searchNodes(); if (titleNode == null) { if (newTitles.isEmpty() && newSubtitles.isEmpty()) { return ; } titleNode = factory.createTitleInfoDefinition(); mods.getTitleInfo().add(titleNode); } updateTitles(titleNode, newTitles); List<StringPlusLanguage> subTitle = titleNode.getSubTitle(); subTitle.clear(); subTitle.addAll(MapperUtils.toStringPlusLanguage(newSubtitles)); } TitleInfoMapper(ModsDefinition mods); }
TitleInfoMapper { public void setTitles(List<String> newTitles, List<String> newSubtitles) { newTitles = MapperUtils.noNull(newTitles); newSubtitles = MapperUtils.noNull(newSubtitles); searchNodes(); if (titleNode == null) { if (newTitles.isEmpty() && newSubtitles.isEmpty()) { return ; } titleNode = factory.createTitleInfoDefinition(); mods.getTitleInfo().add(titleNode); } updateTitles(titleNode, newTitles); List<StringPlusLanguage> subTitle = titleNode.getSubTitle(); subTitle.clear(); subTitle.addAll(MapperUtils.toStringPlusLanguage(newSubtitles)); } TitleInfoMapper(ModsDefinition mods); void setTitles(List<String> newTitles, List<String> newSubtitles); void setKeyTitles(List<String> updates); void setAlternativeTitles(List<String> updates); List<String> getTitles(); List<String> getAlternativeTitles(); List<String> getKeyTitles(); List<String> getSubtitles(); }
TitleInfoMapper { public void setTitles(List<String> newTitles, List<String> newSubtitles) { newTitles = MapperUtils.noNull(newTitles); newSubtitles = MapperUtils.noNull(newSubtitles); searchNodes(); if (titleNode == null) { if (newTitles.isEmpty() && newSubtitles.isEmpty()) { return ; } titleNode = factory.createTitleInfoDefinition(); mods.getTitleInfo().add(titleNode); } updateTitles(titleNode, newTitles); List<StringPlusLanguage> subTitle = titleNode.getSubTitle(); subTitle.clear(); subTitle.addAll(MapperUtils.toStringPlusLanguage(newSubtitles)); } TitleInfoMapper(ModsDefinition mods); void setTitles(List<String> newTitles, List<String> newSubtitles); void setKeyTitles(List<String> updates); void setAlternativeTitles(List<String> updates); List<String> getTitles(); List<String> getAlternativeTitles(); List<String> getKeyTitles(); List<String> getSubtitles();  }