public static GroupArtist createGroup(String names, Source source){
if (!isGroup(names)){
throw new JitcaUnexpectedError("It was tried to build a group based on an artist's name which is not a group!");
}
GroupArtist group = new GroupArtistImpl(names, source);
StringBuffer artist = new StringBuffer();
boolean divider = false;
for (Token token : Scanner.scan(names)){
if (token instanceof StringToken){
artist.append(((StringToken) token).getValue());
artist.append(" ");
divider = false;
} else if (token instanceof DividerToken){
if (!divider){ // The last token was not a divider
artist.deleteCharAt(artist.length()-1); // Remove last space
group.addArtist(artist.toString());
artist = new StringBuffer(); // Clear String Buffer
}
divider = true;
}
}
if (artist.length() > 1){
artist.deleteCharAt(artist.length() - 1); // Remove last space
group.addArtist(artist.toString());
}
return group;
}