/*  OpenOlap viewer
 *  パッケージ名：openolap.viewer.common
 *  ファイル：CommonSettings.java
 *  説明：
 *
 *  作成日: 2004/01/12
 */
package openolap.viewer.common;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;

import openolap.viewer.MeasureMemberType;

/**
 *  クラス：CommonSettings
 *  説明：
 */
public class CommonSettings implements Serializable {

	static final CommonSettings commonSettings = new CommonSettings(CommonUtils.FLGTobool(Messages.getString("InitializeStatus.valueXmlContainsAxesInfoFLG")));

	final private ArrayList measureMemberTypeList = new ArrayList();
	final private boolean valueXmlContainsAxesInfo;
	
	// ********** コンストラクタ **********

	private CommonSettings (boolean valueXmlContainsAxesInfo) {
		this.valueXmlContainsAxesInfo = valueXmlContainsAxesInfo;
	}

	// ********** staticメソッド **********

	public static CommonSettings getCommonSettings() {
		return commonSettings;
	}

	// ********** メソッド **********

	public void addMeasureMemberTypeList(MeasureMemberType measureMemberType) {
		this.measureMemberTypeList.add(measureMemberType);
	}
	
	public void addMeasureMemberTypeList(ArrayList measureMemberTypeList) {
		if(measureMemberTypeList == null) { throw new IllegalArgumentException(); }

		Iterator it = measureMemberTypeList.iterator();
		while (it.hasNext()) {
			MeasureMemberType measureMemberType = null;
			Object obj = (Object) it.next();
			if (obj instanceof MeasureMemberType) {
				measureMemberType = (MeasureMemberType) obj;
			} else {
				throw new IllegalArgumentException();
			}
			this.measureMemberTypeList.add(measureMemberType);
		}
	}

	// メジャーメンバタイプIDをもとにメジャーメンバタイプオブジェクトを返す
	public MeasureMemberType getMeasureMemberTypeByID(String typeId) {
		Iterator it = this.measureMemberTypeList.iterator();
		while (it.hasNext()){
			MeasureMemberType measureMemberType = (MeasureMemberType) it.next();
			if(typeId.equals(measureMemberType.getId())) {
				return measureMemberType;
			}
		}
		return null;
	}

	public MeasureMemberType getFirstMeasureMemberType() {
		return (MeasureMemberType)measureMemberTypeList.get(0);
	}

	// ********** Getter メソッド **********

	public ArrayList getMeasureMemberTypeList() {
		return measureMemberTypeList;
	}
	public boolean getValueXmlContainsAxesInfo() {
		return valueXmlContainsAxesInfo;
	}


}
