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

io.github.nichetoolkit.rest.RestValue Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package io.github.nichetoolkit.rest;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 

RiceValue

* @author Cyan ([email protected]) * @version v1.0.0 */ public interface RestValue extends RestKey { V getValue(); default Map entry() { return Collections.singletonMap(this.getKey(), this.getValue()); } static , K, V> List lists(Class clazz) { return Arrays.asList(clazz.getEnumConstants()); } static , K, V> List> entries(Class clazz) { return lists(clazz).stream().map(RestValue::entry).distinct().collect(Collectors.toList()); } static , K, V> List mapKey(Class clazz) { return lists(clazz).stream().map(RestEnum::mapKey).distinct().collect(Collectors.toList()); } static , K, V> List mapValue(Class clazz) { return lists(clazz).stream().map(RestEnum::mapValue).distinct().collect(Collectors.toList()); } static , K, V> List mapBean(Class clazz) { return lists(clazz).stream().map(RestEnum::mapBean).distinct().collect(Collectors.toList()); } static , K, V> List values(Class clazz) { return lists(clazz).stream().map(RestValue::getValue).distinct().collect(Collectors.toList()); } static , K, V> Boolean confirm(Class clazz, K key) { return Optional.ofNullable(parserKey(clazz, key)).isPresent(); } @SuppressWarnings("Duplicates") static , K, V> T parserKey(Class clazz, K key) { if (key != null && clazz.isEnum()) { Map keyEnumMap = Stream.of(clazz.getEnumConstants()).collect(Collectors.toMap(RestKey::getKey, Function.identity())); return keyEnumMap.get(key); } return null; } @SuppressWarnings("Duplicates") static , K, V> T parserValue(Class clazz, V value) { if (value != null && clazz.isEnum()) { Map valueEnumMap = Stream.of(clazz.getEnumConstants()).collect(Collectors.toMap(RestValue::getValue, Function.identity())); return valueEnumMap.get(value); } return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy