} else {
// Get the primary language preferences that are not currently
// accepted by the client
final List<String> list = new ArrayList<String>();
for (final Preference<Language> preference : languagePrefs) {
final Language language = preference.getMetadata();
if (!language.getSubTags().isEmpty()) {
if (!list.contains(language.getPrimaryTag())) {
list.add(language.getPrimaryTag());
primaryLanguagePrefs.add(new Preference<Language>(
new Language(language.getPrimaryTag()),
0.005f + (0.001f * preference.getQuality())));
}
}
}
// If the default language is a "primary" language but is not
// present in the list of all primary languages, add it.
if ((defaultLanguage != null)
&& !defaultLanguage.getSubTags().isEmpty()) {
if (!list.contains(defaultLanguage.getPrimaryTag())) {
primaryLanguagePrefs.add(new Preference<Language>(
new Language(defaultLanguage.getPrimaryTag()),
0.002f));
}
}
}
// Client preferences are altered
languagePrefs.addAll(primaryLanguagePrefs);
if (defaultLanguagePref != null) {
languagePrefs.add(defaultLanguagePref);
// In this case, if the client adds the "all languages"
// preference, the latter is removed, in order to support the
// default preference defined by the server
final List<Preference<Language>> list = new ArrayList<Preference<Language>>();
for (final Preference<Language> preference : languagePrefs) {
final Language language = preference.getMetadata();
if (!language.equals(Language.ALL)) {
list.add(preference);
}
}
languagePrefs = list;
}