net.optionfactory.spring.localizedenums.dialects.LocalizedEnums Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of localized-enums Show documentation
Show all versions of localized-enums Show documentation
optionfactory-spring enums localization
package net.optionfactory.spring.localizedenums.dialects;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import net.optionfactory.spring.localizedenums.EnumKey;
import net.optionfactory.spring.localizedenums.EnumsLocalizationService;
import net.optionfactory.spring.localizedenums.LocalizedEnumResponse;
import org.springframework.context.i18n.LocaleContextHolder;
public class LocalizedEnums {
private final EnumsLocalizationService les;
public LocalizedEnums(EnumsLocalizationService les) {
this.les = les;
}
public String value(String category, String name) {
return les.value(EnumKey.of(category, name), LocaleContextHolder.getLocale()).orElseThrow();
}
public List values(Class> enumClass) {
return les.values(enumClass, LocaleContextHolder.getLocale());
}
public List values(String category) {
return les.values(Optional.of(category), LocaleContextHolder.getLocale());
}
public boolean in(LocalizedEnumResponse le, Collection> haystack) {
return haystack.stream().anyMatch(e -> e.name().equals(le.name));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy