ResolverUtils { static String getOriginator(String type, Boolean isPrimary, ModsDefinition... mods) { ArrayList<NameDefinition> origNames = new ArrayList<NameDefinition>(); for (ModsDefinition modsDefinition : mods) { for (NameDefinition nameDefinition : modsDefinition.getName()) { NameDefinition add = null; if (isPrimary == null) { add = nameDefinition; } else if (isPrimary && "primary".equals(getNameUsage(nameDefinition))) { add = nameDefinition; } else if (!isPrimary && !"primary".equals(getNameUsage(nameDefinition))) { add = nameDefinition; } if (add != null && type.equals(nameDefinition.getType())) { origNames.add(add); } } if (!origNames.isEmpty()) { break; } } return concat(names(origNames, false), "; "); }  static String getIdentifier(String type, ModsDefinition mods);  }
@Test public void testGetOriginator() { final String xml = "<mods xmlns='http: + "<name type='corporate'><namePart>Corporate</namePart></name>" + "<name type='personal' usage='primary'>" + "<namePart type='family'>PrimaryFamily</namePart>" + "<namePart type='given'>PrimaryGiven</namePart>" + "<namePart type='date'>Primary2002</namePart>" + "<namePart type='termsOfAddress'>PrimaryTermsOfAddress</namePart>" + "</name>" + "<name type='personal'>" + "<namePart>FullName</namePart>" + "<namePart type='given'>Given</namePart>" + "<namePart type='date'>2001</namePart>" + "<namePart type='termsOfAddress'>TermsOfAddress</namePart>" + "<namePart type='family'>Family</namePart>" + "</name>" + "<name type='personal'>" + "<namePart type='family'>Family2</namePart>" + "<namePart type='given'>Given2</namePart>" + "<namePart type='date'>2002</namePart>" + "<namePart type='termsOfAddress'>TermsOfAddress2</namePart>" + "</name>" + "</mods>"; ModsDefinition mods = JAXB.unmarshal(new StringReader(xml), ModsDefinition.class); String originator = ResolverUtils.getOriginator("personal", false, mods); assertEquals("FullName, Family, Given; Family2, Given2", originator); originator = ResolverUtils.getOriginator("personal", true, mods); assertEquals("PrimaryFamily, PrimaryGiven", originator); originator = ResolverUtils.getOriginator("corporate", null, mods); assertEquals("Corporate", originator); }