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

develop.toolkit.base.struct.KeyValuePair Maven / Gradle / Ivy

package develop.toolkit.base.struct;

import lombok.*;

import java.io.Serializable;
import java.util.Map;

/**
 * 键值对结构体
 *
 * @author qiushui on 2018-05-24.
 */
@Getter
@Setter
@EqualsAndHashCode(of = "key")
@NoArgsConstructor
@AllArgsConstructor
public class KeyValuePair implements Serializable {

    private static final long serialVersionUID = -6101907039622686690L;

    protected K key;

    protected V value;

    /**
     * 美化成字符串
     */
    public String formatString(String separator) {
        return key + separator + value;
    }

    @Override
    public String toString() {
        return formatString(":");
    }

    /**
     * 带值初始化
     */
    public static  KeyValuePair of(K key, V value) {
        return new KeyValuePair<>(key, value);
    }

    public static  KeyValuePair of(T[] objs) {
        return new KeyValuePair<>(objs[0], objs[1]);
    }

    /**
     * 从Entry初始化
     */
    public static  KeyValuePair of(Map.Entry entry) {
        return new KeyValuePair<>(entry.getKey(), entry.getValue());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy