All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.unit.nva.model.testing.RandomLanguageUtil Maven / Gradle / Ivy

There is a newer version: 0.23.2
Show newest version
package no.unit.nva.model.testing;

import static no.unit.nva.testutils.RandomDataGenerator.randomElement;
import no.unit.nva.language.Language;
import no.unit.nva.language.LanguageConstants;

import java.net.URI;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class RandomLanguageUtil {

    public static final Set unused = Set.of(LanguageConstants.NORWEGIAN, LanguageConstants.MISCELLANEOUS);

    private RandomLanguageUtil() {
    }

    public static String randomBcp47CompatibleLanguage() {
        var languages = getLanguageStream()
                            .map(Language::getIso6391Code)
                            .filter(Objects::nonNull)
                            .collect(Collectors.toList());
        return randomElement(languages);
    }

    public static URI randomLexvoUri() {
        return getLanguageStream().map(Language::getLexvoUri).filter(Objects::nonNull).findAny().orElseThrow();
    }

    private static Stream getLanguageStream() {
        return LanguageConstants.ALL_LANGUAGES.stream().filter(RandomLanguageUtil::isUsedLanguageInNva);
    }

    private static boolean isUsedLanguageInNva(Language f) {
        return !unused.contains(f);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy