package com.jsowell.common.enums.ykc;

import io.netty.channel.Channel;

import java.util.HashMap;

/**
 * 桩编号和channel的关联关系处理 entity
 */
public class PileChannelEntity {

    private static HashMap<String, Channel> manager = new HashMap<>();
 
    public static void put(String pileSn, Channel channel) {
        manager.put(pileSn, channel);
    }

    /**
     * 通过桩编号获取channel链接信息
     * @param pileSn
     * @return
     */
    public static Channel getChannelByPileSn(String pileSn) {
        return manager.get(pileSn);
    }

    /**
     * 通过channelId获取桩编号
     * @param channelId
     * @return
     */
    public static String getPileSnByChannelId(String channelId) {
        for (HashMap.Entry<String, Channel> entry : manager.entrySet()) {
           if (entry.getValue().id().asLongText().equals(channelId)) {
               return entry.getKey();
           }
        }
        return null;
    }

    /**
     * 打印
     */
    public static void output() {
        for (HashMap.Entry<String, Channel> entry : manager.entrySet()) {
            System.out.println("pileSn:" + entry.getKey() +
                    ",ChannelId:" + entry.getValue().id().asLongText());
        }
    }

    public static void removeByPileSn(String pileSn){
        manager.remove(pileSn);
    }

}