edu.stanford.protege.webprotege.lang.DisplayNameSettings Maven / Gradle / Ivy
The newest version!
package edu.stanford.protege.webprotege.lang;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import edu.stanford.protege.webprotege.common.DictionaryLanguage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.stream.Stream;
/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 31 Jul 2018
*/
@AutoValue
public abstract class DisplayNameSettings {
private static final String PRIMARY_DISPLAY_NAME_LANGUAGES = "primaryDisplayNameLanguages";
private static final String SECONDARY_DISPLAY_NAME_LANGUAGES = "secondaryDisplayNameLanguages";
@JsonCreator
@Nonnull
public static DisplayNameSettings get(@Nullable @JsonProperty(PRIMARY_DISPLAY_NAME_LANGUAGES) ImmutableList primaryLanguages,
@Nullable @JsonProperty(SECONDARY_DISPLAY_NAME_LANGUAGES) ImmutableList secondaryLanguages) {
return new AutoValue_DisplayNameSettings(primaryLanguages == null ? ImmutableList.of() : primaryLanguages,
secondaryLanguages == null ? ImmutableList.of() : secondaryLanguages);
}
@Nonnull
public static DisplayNameSettings empty() {
return get(ImmutableList.of(),
ImmutableList.of());
}
@JsonProperty(PRIMARY_DISPLAY_NAME_LANGUAGES)
@Nonnull
public abstract ImmutableList getPrimaryDisplayNameLanguages();
@JsonProperty(SECONDARY_DISPLAY_NAME_LANGUAGES)
@Nonnull
public abstract ImmutableList getSecondaryDisplayNameLanguages();
public boolean hasDisplayNameLanguageForLangTag(@Nonnull String langTag) {
Stream languages = Streams.concat(
getPrimaryDisplayNameLanguages().stream(),
getSecondaryDisplayNameLanguages().stream()
);
return languages.anyMatch(l -> langTag.equalsIgnoreCase(l.getLang()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy