@@ -0,0 +1,2890 @@
+package cn.diaovision.omnicontrol.util;%0A%0Aimport java.util.Iterator;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0Aimport cn.diaovision.omnicontrol.core.model.device.matrix.io.Channel;%0Aimport cn.diaovision.omnicontrol.core.model.device.matrix.io.Port;%0A%0A/**%0A * Created by TaoYimin on 2017/6/5.%0A */%0A%0Apublic class PortHelper %7B%0A    Set%3CChannel%3E channelSet;%0A    List%3CPort%3E inputList;%0A    List%3CPort%3E outputList;%0A%0A    static private PortHelper instance;%0A%0A    public static PortHelper getIntance() %7B%0A        if (instance == null) %7B%0A            synchronized (PortHelper.class) %7B%0A                if (instance == null) %7B%0A                    instance = new PortHelper();%0A                %7D%0A            %7D%0A        %7D%0A        return instance;%0A    %7D%0A%0A    public void init(List%3CPort%3E inputList, List%3CPort%3E outputList, Set%3CChannel%3E channelSet) %7B%0A        this.inputList = inputList;%0A        this.outputList = outputList;%0A        this.channelSet = channelSet;%0A    %7D%0A%0A    public boolean inputPortIsUsed(int inputIdx) %7B%0A        if (getOutputIdx(inputIdx) == null) %7B%0A            return false;%0A        %7D else %7B%0A            return true;%0A        %7D%0A    %7D%0A%0A    public boolean outputPortIsUsed(int outputIdx) %7B%0A        if (getInputIdx(outputIdx) == -1) %7B%0A            return false;%0A        %7D else %7B%0A            return true;%0A        %7D%0A    %7D%0A%0A    public Port getInputPort(int portIdx) %7B%0A        return inputList.get(portIdx);%0A    %7D%0A%0A    public Port getOutputPort(int portIdx) %7B%0A        return outputList.get(portIdx);%0A    %7D%0A%0A    public int%5B%5D getOutputIdx(int inputIdx) %7B%0A        Iterator%3CChannel%3E iterator = channelSet.iterator();%0A        while (iterator.hasNext()) %7B%0A            Channel channel = iterator.next();%0A            if (channel.getInputIdx() == inputIdx) %7B%0A                return channel.getOutputIdx();%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A    public int getInputIdx(int outputIdx) %7B%0A        Iterator%3CChannel%3E iterator = channelSet.iterator();%0A        while (iterator.hasNext()) %7B%0A            Channel channel = iterator.next();%0A            if (channel.containOutputIdx(outputIdx)) %7B%0A                return channel.getInputIdx();%0A            %7D%0A        %7D%0A        return -1;%0A    %7D%0A%0A    public int getInputPortBadge(int inputIdx) %7B%0A        int badge = 1;%0A        int category = inputList.get(inputIdx).category;%0A        for (int i = 0; i %3CinputIdx; i++) %7B%0A            if(inputList.get(i).category==category)%7B%0A                badge++;%0A            %7D%0A        %7D%0A        return badge;%0A    %7D%0A%0A    public int getOutPortBadge(int outPutIdx)%7B%0A        int inputIdx=getInputIdx(outPutIdx);%0A        if(inputIdx!=-1)%7B%0A            return getInputPortBadge(inputIdx);%0A        %7D%0A        return -1;%0A    %7D%0A%0A    public int getInputPortCategory(int outputIdx)%7B%0A        int inputIdx=getInputIdx(outputIdx);%0A        if(inputIdx!=-1)%7B%0A            return inputList.get(inputIdx).category;%0A        %7D%0A        return -1;%0A    %7D%0A%7D%0A

add PortHelper util class