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

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

import openolap.viewer.common.StringUtil;

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

	// ********** インスタンス変数 **********

	final private Integer index;					// 列/行インデックス(列/行で一意になる0startの通番)
	final private LinkedHashMap axisIdMemKeyMap;	// 列/行の各段の次元IDと値のペアの集合


	// ********** コンストラクタ **********

	public EdgeCoordinates(Integer index,LinkedHashMap axisIdMemKeyMap) {
		this.index = index;
		this.axisIdMemKeyMap = axisIdMemKeyMap;
	}

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

	public static ArrayList createCoordinates(String indexKey, String[] axisIdList) {

		ArrayList axisCoordinatesList = new ArrayList();		// 軸座標リスト
		EdgeCoordinates axisCoordinates = null;				// 軸座標

		Iterator axisIt = StringUtil.splitString(indexKey,",").iterator();

//System.out.println("indexKey:" + indexKey);

		while (axisIt.hasNext()) {
			LinkedHashMap axisIdKeyMap = new LinkedHashMap();

			String indexKeysString = (String) axisIt.next();
			ArrayList indexKeysList = StringUtil.splitString(indexKeysString,":");
			Integer axisIndex = Integer.decode((String) indexKeysList.get(0));		// 列のインデックス
			String colKeys = (String) indexKeysList.get(1);							// 列のキーの組み合わせ(文字列)
			ArrayList axisKeyList = StringUtil.splitString(colKeys,";");			// 列のキーの組み合わせ(配列)

			Iterator keyListIte = axisKeyList.iterator();
			int j = 0;
			while (keyListIte.hasNext()){
				String key = (String) keyListIte.next();
				axisIdKeyMap.put(Integer.decode(axisIdList[j]), key);
				j++;
			}

//System.out.println("axisIndex, axisIdKeyMap:" + axisIndex + "," + axisIdKeyMap);

			axisCoordinatesList.add(new EdgeCoordinates(axisIndex, axisIdKeyMap));
		}

//Iterator it = axisCoordinatesList.iterator();
//System.out.println("size:" + axisCoordinatesList.size());
//while (it.hasNext()) {
//	EdgeCoordinates coordinates = (EdgeCoordinates) it.next();
//	System.out.println("index:" + coordinates.getIndex());
//	
//	Iterator it2 = coordinates.getAxisIdMemKeyMap().keySet().iterator();
//	while (it2.hasNext()) {
//		Integer id = (Integer) it2.next();
//		System.out.println("id,key:" + id + "," + coordinates.getAxisIdMemKeyMap().get(id) + "\n");
//	}
//}

		return axisCoordinatesList;
	}

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

	public Integer getIndex() {
		return index;
	}
	public LinkedHashMap getAxisIdMemKeyMap() {
		return axisIdMemKeyMap;
	}
}
