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

top.cutexingluo.tools.common.ICommonResult Maven / Gradle / Ivy

There is a newer version: 1.1.6
Show newest version
package top.cutexingluo.tools.common;

import top.cutexingluo.tools.common.base.IData;
import top.cutexingluo.tools.utils.se.array.XTArrayUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * IResult 公用方法
 * 

v1.0.3 : 推荐用作函数式接口

*

于 v1.1.2 getData 改为 data 方法

* * @author XingTian * @version 1.0.0 * @date 2023/7/13 21:18 */ @FunctionalInterface public interface ICommonResult extends IData { @Override T data(); public static int intCode(String code) { return Integer.parseInt(code); } public static String strCode(int code) { return String.valueOf(code); } /** * @param pairs Add the element you want to add,a pair of (key,value), odd totals. 数据对,最好是偶数 * @return Result: Contains map */ default Map put(Object... pairs) { Map map; T data = data(); if (!(data instanceof Map)) map = new HashMap<>(); else map = (Map) data; XTArrayUtil.putMapFromDValues(map, pairs); return map; } /** * @param items ; Add the element you want to add * @return Result ; Contains list */ default List add(Object... items) { List list; T data = data(); if (!(data instanceof List)) list = new ArrayList<>(); else list = (List) data; list.add(items); return list; } }