<commit_before>package com.nhn.pinpoint.web.applicationmap;

import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.web.applicationmap.rawdata.CallHistogram;
import com.nhn.pinpoint.web.applicationmap.rawdata.CallHistogramList;
import com.nhn.pinpoint.web.applicationmap.rawdata.Histogram;
import com.nhn.pinpoint.web.vo.LinkKey;
import com.nhn.pinpoint.web.vo.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * application map에서 application간의 관계를 담은 클래스
 * 
 * @author netspider
 * @author emeroad
 */
public class Link {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final LinkKey linkKey;

    private final Node fromNode;
    private final Node toNode;

	private final CallHistogramList tagetList;
    private CallHistogramList sourceList;


    public Link(Node from, Node to, CallHistogramList tagetList) {
        this(createLinkKey(from, to), from, to, tagetList);

    }

    private static LinkKey createLinkKey(Node from, Node to) {
        if (from == null) {
            throw new NullPointerException("fromNode must not be null");
        }
        if (to == null) {
            throw new NullPointerException("toNode must not be null");
        }
        final Application fromApplication = from.getApplication();
        final Application toApplication = to.getApplication();
        return new LinkKey(fromApplication, toApplication);
    }

    Link(LinkKey linkKey, Node fromNode, Node toNode, CallHistogramList tagetList) {
        if (fromNode == null) {
            throw new NullPointerException("fromNode must not be null");
        }
        if (toNode == null) {
            throw new NullPointerException("toNode must not be null");
        }
        if (linkKey == null) {
            throw new NullPointerException("linkKey must not be null");
        }
        this.linkKey = linkKey;
        this.fromNode = fromNode;
        this.toNode = toNode;
        this.tagetList = tagetList;
    }

    public Link(Link copyLink) {
        if (copyLink == null) {
            throw new NullPointerException("copyLink must not be null");
        }
        this.linkKey = copyLink.linkKey;
        this.fromNode = copyLink.fromNode;
        this.toNode = copyLink.toNode;
        this.tagetList = new CallHistogramList(copyLink.tagetList);
        this.sourceList = new CallHistogramList(copyLink.sourceList);
    }

    public Application getFilterApplication() {
        // User 링크일 경우 from을 보면 안되고 was를 봐야 한다.
        // User는 가상의 링크이기 때문에, User로 필터링을 칠수 없음.
        if(fromNode.getServiceType() == ServiceType.USER) {
            return toNode.getApplication();
        }
        return fromNode.getApplication();
    }


	public LinkKey getLinkKey() {
		return linkKey;
	}

	public Node getFrom() {
		return fromNode;
	}

	public Node getTo() {
		return toNode;
	}

	public CallHistogramList getTargetList() {
		return tagetList;
	}


	public Histogram getHistogram() {
		Histogram result = null;

		for (CallHistogram callHistogram : tagetList.getCallHistogramList()) {
			if (result == null) {
				// FIXME 뭔가 괴상한 방식이긴 하지만..
                // toNode의 서비스 타입이 들어가면 되는게 아닌가함?
				Histogram histogram = callHistogram.getHistogram();
				result = new Histogram(histogram.getServiceType());
			}
			result.add(callHistogram.getHistogram());
		}
//        Histogram result2 = new Histogram(toNode.getServiceType());
//        for (CallHistogram callHistogram : tagetList.getCallHistogramList()) {
//            result2.addUncheckType(callHistogram.getHistogram());
//        }
//        if (result2.getTotalCount() != result.getTotalCount()) {
//            throw new IllegalArgumentException("ddd--------");
//        }

		return result;
	}

    public void setSourceList(CallHistogramList sourceList) {
        this.sourceList = sourceList;
    }

    public CallHistogramList getSourceList() {
        return sourceList;
    }

	public void addLink(Link link) {
        if (link == null) {
            throw new NullPointerException("link must not be null");
        }<commit_msg>[강운덕] [WEB-57] link의 histogram 생성시 serviceType의 판정로직을 직관적으로 수정함. to의 sericeType을 가지면 됨.<commit_after>package com.nhn.pinpoint.web.applicationmap;

import com.nhn.pinpoint.common.ServiceType;
import com.nhn.pinpoint.web.applicationmap.rawdata.CallHistogram;
import com.nhn.pinpoint.web.applicationmap.rawdata.CallHistogramList;
import com.nhn.pinpoint.web.applicationmap.rawdata.Histogram;
import com.nhn.pinpoint.web.vo.LinkKey;
import com.nhn.pinpoint.web.vo.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * application map에서 application간의 관계를 담은 클래스
 * 
 * @author netspider
 * @author emeroad
 */
public class Link {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final LinkKey linkKey;

    private final Node fromNode;
    private final Node toNode;

	private final CallHistogramList tagetList;
    private CallHistogramList sourceList;


    public Link(Node from, Node to, CallHistogramList tagetList) {
        this(createLinkKey(from, to), from, to, tagetList);

    }

    private static LinkKey createLinkKey(Node from, Node to) {
        if (from == null) {
            throw new NullPointerException("fromNode must not be null");
        }
        if (to == null) {
            throw new NullPointerException("toNode must not be null");
        }
        final Application fromApplication = from.getApplication();
        final Application toApplication = to.getApplication();
        return new LinkKey(fromApplication, toApplication);
    }

    Link(LinkKey linkKey, Node fromNode, Node toNode, CallHistogramList tagetList) {
        if (fromNode == null) {
            throw new NullPointerException("fromNode must not be null");
        }
        if (toNode == null) {
            throw new NullPointerException("toNode must not be null");
        }
        if (linkKey == null) {
            throw new NullPointerException("linkKey must not be null");
        }
        this.linkKey = linkKey;
        this.fromNode = fromNode;
        this.toNode = toNode;
        this.tagetList = tagetList;
    }

    public Link(Link copyLink) {
        if (copyLink == null) {
            throw new NullPointerException("copyLink must not be null");
        }
        this.linkKey = copyLink.linkKey;
        this.fromNode = copyLink.fromNode;
        this.toNode = copyLink.toNode;
        this.tagetList = new CallHistogramList(copyLink.tagetList);
        this.sourceList = new CallHistogramList(copyLink.sourceList);
    }

    public Application getFilterApplication() {
        // User 링크일 경우 from을 보면 안되고 was를 봐야 한다.
        // User는 가상의 링크이기 때문에, User로 필터링을 칠수 없음.
        if(fromNode.getServiceType() == ServiceType.USER) {
            return toNode.getApplication();
        }
        return fromNode.getApplication();
    }


	public LinkKey getLinkKey() {
		return linkKey;
	}

	public Node getFrom() {
		return fromNode;
	}

	public Node getTo() {
		return toNode;
	}

	public CallHistogramList getTargetList() {
		return tagetList;
	}


	public Histogram getHistogram() {
        // 내가 호출하는 대상의 serviceType을 가져와야 한다.
        // tomcat -> arcus를 호출한다고 하였을 경우 arcus의 타입을 가져와야함.
        final Histogram linkHistogram = new Histogram(toNode.getServiceType());
        for (CallHistogram callHistogram : tagetList.getCallHistogramList()) {
            linkHistogram.addUncheckType(callHistogram.getHistogram());
        }
		return linkHistogram;
	}

    public void setSourceList(CallHistogramList sourceList) {
        this.sourceList = sourceList;
    }

    public CallHistogramList getSourceList() {
        return sourceList;
    }

	public void addLink(Link link) {
        if (link == null) {
            throw new NullPointerException("link must not be null");
        }
{'fraction_non_alphanumeric': 0.09522597071928708, 'fraction_numerical': 0.0011457670273711013, 'mean_word_length': 2.7498806682577563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6645297', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2530, 'n_words': 585}