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

io.github.nichetoolkit.rest.RestStatus 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;

/**
 * 

RiceStatus

* @author Cyan ([email protected]) * @version v1.0.0 */ public interface RestStatus { String name(); Integer getStatus(); String getMessage(); default Map entry() { return Collections.singletonMap(this.getStatus(),this.getMessage()); } static List lists(Class clazz) { return Arrays.asList(clazz.getEnumConstants()); } static List> entries(Class clazz) { return lists(clazz).stream().map(RestStatus::entry).distinct().collect(Collectors.toList()); } static List statuses(Class clazz) { return lists(clazz).stream().map(RestStatus::getStatus).distinct().collect(Collectors.toList()); } static List messages(Class clazz) { return lists(clazz).stream().map(RestStatus::getMessage).distinct().collect(Collectors.toList()); } static Boolean confirm(Class clazz, Integer status) { return Optional.ofNullable(parseStatus(clazz,status)).isPresent(); } @SuppressWarnings("Duplicates") static T parseStatus(Class clazz, Integer status){ if (status != null && clazz.isEnum()) { Map errorMap = Stream.of(clazz.getEnumConstants()).collect(Collectors.toMap(RestStatus::getStatus, Function.identity())); return errorMap.get(status); } return null; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy