package parser.ServletParser.library;

import java.awt.*;
import java.util.*;
import java.io.*;

public class MetricsData extends Object implements Serializable {
	/** 버전 제어를 위한 시리얼 넘버이다.
	 */
	public static final long serialVersionUID = -8128447115591115753L;
	/** class name or package name
	 */
	public String itemName;
	/** class 인가를 나타내는 flag
	 */
	public boolean isClass;
	/** ClassInfoNode에 대한 레퍼런스이다.
	 */
	transient public ClassInfoNode classInfoNode;
	/** 메트릭 데이터 값을 저장하는 배열
	 */
	int data[];
	/** 메트릭 값을 요약할 때 합계를 구할 것
	 */
	static public int I_SUM = 0;
	/** 메트릭 값을 요약할 때 평균을 구할 것
	 */
	static public int I_AVE = 1;
	/** 메트릭 값을 요약할 때 최대값을 구할 것
	 */
	static public int I_MAX = 2;
	/** 메트릭 값을 요약할 때 최소값을 구할 것
	 */
	static public int I_MIN = 3;
	/** 메트릭 값을 요약하지 말것
	 */
	static public int I_NON = 4;
	/** 메트릭 데이터들을 패키지 별로 어떻게 요약할 것인가를 나타내는 태그
	 */
	public static int summarizeAction[];
	/** Lines Of Code
	 */
	static public int Iloc = 0;
	/** Number Of Attributes
	 */
	static public int Inoa = 1;
	/** Number Of Classes
	 */
	static public int Inoc = 2;
	/** Number Of Constructors
	 */
	static public int Inocon = 3;
	/** Number Of Import Statements 
	 */
	static public int Inois = 4;
	/** Number Of Members
	 */
	static public int Inom = 5;
	/** Number Of Operations
	 */
	static public int Inoo = 6;
	/** Lack Of Cohesion Of Methods 1
	 */
	static public int Ilocom1 = 7;
	/** Lack Of Cohesion Of Methods 2
	 */
	static public int Ilocom2 = 8;
	/** Lack Of Cohesion Of Methods 3
	 */
	static public int Ilocom3 = 9;
	/** Attribute Complexity
	 */
	static public int Iac = 10;
	/** Cyclomatic Complexity
	 */
	static public int Icc = 11;
	/** Number Of Remote Methods
	 */
	static public int Inorm = 12;
	/** Response For Class
	 */
	static public int Irfc = 13;
	/** Weighted Methods Per Class 1
	 */
	static public int Iwmpc1 = 14;
	/** Weighted Methods Per Class 2
	 */
	static public int Iwmpc2 = 15;
	/** Coupling Between Objects
	 */
	static public int Icbo = 16;
	/** Coupling Factor
	 */
	static public int Icf = 17;
	/** Data Abstraction Coupling
	 */
	static public int Idac = 18;
	/** FanOut
	 */
	static public int Ifo = 19;
	/** Halstead Difficulty
	 */
	static public int Ihdiff = 20;
	/** Halstead Effort
	 */
	static public int Iheff = 21;
	/** Halstead Program Length
	 */
	static public int Ihplen = 22;
	/** Halstead Program Vocabulary
	 */
	static public int Ihpvoc = 23;
	/** Halstead Program Volumn
	 */
	static public int Ihpvol = 24;
	/** Number of Operands
	 */
	static public int Inoprnd = 25;
	/** Number of Operators
	 */
	static public int Inoprtr = 26;
	/** Number of Unique Operands
	 */
	static public int Inuoprnd = 27;
	/** Number of Unique Operators
	 */
	static public int Inuoprtr = 28;
	/** Attribute Hiding Factor
	 */
	static public int Iahf = 29;
	/** Method Hiding Factor
	 */
	static public int Imhf = 30;
	/** Attribute Inheritance Factor
	 */
	static public int Iaif = 31;
	/** Depth Of Inheritance Hierarchy
	 */
	static public int Idoih = 32;
	/** Method Inheritance Factor
	 */
	static public int Imif = 33;
	/** Number Of Child Classes
	 */
	static public int Inocc = 34;
	/** Maximum Number Of Levels
	 */
	static public int Imnol = 35;
	/** Maximum Number Of Parameters
	 */
	static public int Imnop = 36;
	/** Maximum Size Of Operation
	 */
	static public int Imsoo = 37;
	/** Number Of Added Methods
	 */
	static public int Inoam = 38;
	/** Number Of Overridden Methods
	 */
	static public int Inoom = 39;
	/** Polymorphism Factor
	 */
	static public int Ipf = 40;
	/** Comment Ratio
	 */
	static public int Icr = 41;
	/** Percentage of Package Members
	 */
	static public int Ippkgm = 42;
	/** Percentage of Private Members
	 */
	static public int Ipprivm = 43;
	/** Percentage of protected Members
	 */
	static public int Ipprotm = 44;
	/** Percentage of public Members
	 */
	static public int Ippubm = 45;
	/** True Comment Ratio
	 */
	static public int Itcr = 46;
	/** total number of data
	 */
	static public int Nmetrics = 47;
	/** static initializer
	 */
	static {
		summarizeAction = new int[Nmetrics];

		summarizeAction[Iloc] = I_SUM;
		summarizeAction[Inoa] = I_MAX;
		summarizeAction[Inoc] = I_SUM;
		summarizeAction[Inocon] = I_MAX;
		summarizeAction[Inois] = I_MAX;
		summarizeAction[Inom] = I_MAX;
		summarizeAction[Inoo] = I_MAX;
		summarizeAction[Ilocom1] = I_MAX;
		summarizeAction[Ilocom2] = I_MAX;
		summarizeAction[Ilocom3] = I_MAX;
		summarizeAction[Iac] = I_AVE;
		summarizeAction[Icc] = I_MAX;
		summarizeAction[Inorm] = I_MAX;
		summarizeAction[Irfc] = I_MAX;
		summarizeAction[Iwmpc1] = I_MAX;
		summarizeAction[Iwmpc2] = I_MAX;
		summarizeAction[Icbo] = I_MAX;
		summarizeAction[Icf] = I_NON;
		summarizeAction[Idac] = I_MAX;
		summarizeAction[Ifo] = I_MAX;
		summarizeAction[Ihdiff] = I_SUM;
		summarizeAction[Iheff] = I_SUM;
		summarizeAction[Ihplen] = I_SUM;
		summarizeAction[Ihpvoc] = I_SUM;
		summarizeAction[Ihpvol] = I_SUM;
		summarizeAction[Inoprnd] = I_SUM;
		summarizeAction[Inoprtr] = I_SUM;
		summarizeAction[Inuoprnd] = I_SUM;
		summarizeAction[Inuoprtr] = I_SUM;
		summarizeAction[Iahf] = I_NON;
		summarizeAction[Imhf] = I_NON;
		summarizeAction[Iaif] = I_NON;
		summarizeAction[Idoih] = I_MAX;
		summarizeAction[Imif] = I_NON;
		summarizeAction[Inocc] = I_MAX;
		summarizeAction[Imnol] = I_MAX;
		summarizeAction[Imnop] = I_MAX;
		summarizeAction[Imsoo] = I_MAX;
		summarizeAction[Inoam] = I_MAX;
		summarizeAction[Inoom] = I_MAX;
		summarizeAction[Ipf] = I_NON;
		summarizeAction[Icr] = I_MIN;
		summarizeAction[Ippkgm] = I_AVE;
		summarizeAction[Ipprivm] = I_AVE;
		summarizeAction[Ipprotm] = I_AVE;
		summarizeAction[Ippubm] = I_AVE;
		summarizeAction[Itcr] = I_MIN;
	}
	/** 생성자이다.
	 */
	public MetricsData(String name,ClassInfoNode nodePtr) {
		this(name,true,nodePtr);
	}
	/** 생성자이다.
	 */
	public MetricsData(String name,boolean classflag,ClassInfoNode nodePtr) {
		classInfoNode = nodePtr;
		itemName = new String(name);
		isClass = classflag;
		data = new int[Nmetrics];
		for (int i = 0; i < Nmetrics; i++) {
			data[i] = 0;
		}
	}
	public String toString() {
		return new String(itemName);
	}
	/** 인덱스 필드의 값을 -1 로 셋팅함으로써 빈칸으로 처리한다.
	 *  MetricsTableValues.getValueAt() 함수 참조.
	 */
	public void setMinusAt(int index) {
		data[index] = -1;
	}
	/** 패키지 노드 경우에 메트릭 값을 정리하는 함수이다.
	 */
	public void summarize(MetricsData value) {
		for (int i = 0; i < Nmetrics; i++) {
			if (summarizeAction[i] == I_MAX) {
				if (value.data[i] > data[i]) data[i] = value.data[i];
			} else if (summarizeAction[i] == I_MIN) {
				if (data[i] == 0) data[i] = value.data[i];
				else if (value.data[i] < data[i]) data[i] = value.data[i];
			} else if (summarizeAction[i] == I_SUM) {
				data[i] = data[i] + value.data[i];
			}
		}
	}
	/** 패키지 노드 값이 평균값인 경우를 처리하는 함수이다.
	 */
	public void summarizeAverage(MetricsData totalValue,int nClass) {
		for (int i = 0; i < Nmetrics; i++) {
			if (summarizeAction[i] == I_AVE) {
				data[i] = totalValue.data[i] / nClass;
			}
		}
	}
	/** 메트릭 값을 누적시키는데 사용되는 함수이다.
	 */
	public void add(MetricsData value) {
		for (int i = 0; i < Nmetrics; i++) {
			data[i] = data[i] + value.data[i];
		}
	}
	/** 특정 메트릭값을 설정하는 함수이다.
	 */
	public void setMetricsData(int i,int v) {
		data[i] = v;
	}
    /** 특정 메트릭값을 읽는 함수이다.
	 */
	public int getMetricsData(int i) {
		return data[i];
	}
	/** 메트릭 이름을 알아내는 함수이다.
	 */
	public static String getColumnName(int i) {
		if (i == Iloc) {
			return new String("LOC");
		} else if (i == Inoa) {
			return new String("NOA");
		} else if (i == Inoc) {
			return new String("NOC");
		} else if (i == Inocon) {
			return new String("NOCON");
		} else if (i == Inois) {
			return new String("NOIS");
		} else if (i == Inom) {
			return new String("NOM");
		} else if (i == Inoo) {
			return new String("NOO");
		} else if (i == Ilocom1) {
			return new String("LOCOM1");
		} else if (i == Ilocom2) {
			return new String("LOCOM2");
		} else if (i == Ilocom3) {
			return new String("LOCOM3");
		} else if (i == Iac) {
			return new String("AC");
		} else if (i == Icc) {
			return new String("CC");
		} else if (i == Inorm) {
			return new String("NORM");
		} else if (i == Irfc) {
			return new String("RFC");
		} else if (i == Iwmpc1) {
			return new String("WMPC1");
		} else if (i == Iwmpc2) {
			return new String("WMPC2");
		} else if (i == Icbo) {
			return new String("CBO");
		} else if (i == Icf) {
			return new String("CF");
		} else if (i == Idac) {
			return new String("DAC");
		} else if (i == Ifo) {
			return new String("FO");
		} else if (i == Ihdiff) {
			return new String("Hdiff");
		} else if (i == Iheff) {
			return new String("HEff");
		} else if (i == Ihplen) {
			return new String("HPLen");
		} else if (i == Ihpvoc) {
			return new String("HPVoc");
		} else if (i == Ihpvol) {
			return new String("HPVol");
		} else if (i == Inoprnd) {
			return new String("NOprnd");
		} else if (i == Inoprtr) {
			return new String("NOprtr");
		} else if (i == Inuoprnd) {
			return new String("NUOprnd");
		} else if (i == Inuoprtr) {
			return new String("NUOprtr");
		} else if (i == Iahf) {
			return new String("AHF");
		} else if (i == Imhf) {
			return new String("MHF");
		} else if (i == Iaif) {
			return new String("AIF");
		} else if (i == Idoih) {
			return new String("DOIH");
		} else if (i == Imif) {
			return new String("MIF");
		} else if (i == Inocc) {
			return new String("NOCC");
		} else if (i == Imnol) {
			return new String("MNOL");
		} else if (i == Imnop) {
			return new String("MNOP");
		} else if (i == Imsoo) {
			return new String("MSOO");
		} else if (i == Inoam) {
			return new String("NOAM");
		} else if (i == Inoom) {
			return new String("NOOM");
		} else if (i == Ipf) {
			return new String("PF");
		} else if (i == Icr) {
			return new String("CR");
		} else if (i == Ippkgm) {
			return new String("PPkgM");
		} else if (i == Ipprivm) {
			return new String("PPrivM");
		} else if (i == Ipprotm) {
			return new String("PProtM");
		} else if (i == Ippubm) {
			return new String("PPubM");
		} else if (i == Itcr) {
			return new String("TCR");
		} else {
			return new String("Error");
		}
	}
	/** 메트릭 이름을 알아내는 함수이다.
	 */
	public static String getColumnToolTips(int i) {
		if (i == Iloc) {
			return new String("Lines Of Code");
		} else if (i == Inoa) {
			return new String("Number Of Attributes");
		} else if (i == Inoc) {
			return new String("Number Of Classes");
		} else if (i == Inocon) {
			return new String("Number Of Constructors");
		} else if (i == Inois) {
			return new String("Number Of Import Statements");
		} else if (i == Inom) {
			return new String("Number Of Members");
		} else if (i == Inoo) {
			return new String("Number Of Operations");
		} else if (i == Ilocom1) {
			return new String("Lack Of Cohesion Of Methods 1");
		} else if (i == Ilocom2) {
			return new String("Lack Of Cohesion Of Methods 2");
		} else if (i == Ilocom3) {
			return new String("Lack Of Cohesion Of Methods 3");
		} else if (i == Iac) {
			return new String("Attribute Complexity");
		} else if (i == Icc) {
			return new String("Cyclomatic Complexity");
		} else if (i == Inorm) {
			return new String("Number Of Remote Methods");
		} else if (i == Irfc) {
			return new String("Response For Class");
		} else if (i == Iwmpc1) {
			return new String("Weighted Methods Per Class 1");
		} else if (i == Iwmpc2) {
			return new String("Weighted Methods Per Class 2");
		} else if (i == Icbo) {
			return new String("Coupling Between Objects");
		} else if (i == Icf) {
			return new String("Coupling Factor");
		} else if (i == Idac) {
			return new String("Data Abstraction Coupling");
		} else if (i == Ifo) {
			return new String("FanOut");
		} else if (i == Ihdiff) {
			return new String("Halstead Difficulty");
		} else if (i == Iheff) {
			return new String("Halstead Effort");
		} else if (i == Ihplen) {
			return new String("Halstead Program Length");
		} else if (i == Ihpvoc) {
			return new String("Halstead Vocabulary");
		} else if (i == Ihpvol) {
			return new String("Halstead Volumn");
		} else if (i == Inoprnd) {
			return new String("Number of Operands");
		} else if (i == Inoprtr) {
			return new String("Number of Operators");
		} else if (i == Inuoprnd) {
			return new String("Number of Unique Operands");
		} else if (i == Inuoprtr) {
			return new String("Number of Unique Operators");
		} else if (i == Iahf) {
			return new String("Attribute Hiding Factor");
		} else if (i == Imhf) {
			return new String("Method Hiding Factor");
		} else if (i == Iaif) {
			return new String("Attribute Inheritance Factor");
		} else if (i == Idoih) {
			return new String("Depth Of Inheritance Factor");
		} else if (i == Imif) {
			return new String("Method Inheritance Factor");
		} else if (i == Inocc) {
			return new String("Number Of Child Classes");
		} else if (i == Imnol) {
			return new String("Maximum Number Of Levels");
		} else if (i == Imnop) {
			return new String("Maximum Number Of Parameters");
		} else if (i == Imsoo) {
			return new String("Maximum Size Of Operation");
		} else if (i == Inoam) {
			return new String("Number Of Added Methods");
		} else if (i == Inoom) {
			return new String("Number Of Overridden Methods");
		} else if (i == Ipf) {
			return new String("Polymorphism Factor");
		} else if (i == Icr) {
			return new String("Comments Ratio");
		} else if (i == Ippkgm) {
			return new String("Percentage of Package Members");
		} else if (i == Ipprivm) {
			return new String("Percentage of Private Members");
		} else if (i == Ipprotm) {
			return new String("Percentage of Protected Members");
		} else if (i == Ippubm) {
			return new String("Percentage of Public Members");
		} else if (i == Itcr) {
			return new String("True Comment Ratio");
		} else {
			return new String("Error");
		}
	}
}