package de.examples;

import de.tvo.nanoleaf.oclasses.MatrixInfo;
import de.tvo.tools.StringUtil;

public class StringTesterClass {

	public StringTesterClass() {
		String ref = "#{d.PanelConfigBean.paneRepeatList[1].panelInfoList[2].panelID}";
		
		
		MatrixInfo info = createMatrixInfo(ref);
	}

	public static void main(String[] args) {
		new StringTesterClass();

	}
	
	
	private MatrixInfo createMatrixInfo(String ref) {
		MatrixInfo matrixInfo = null;
		// #{d.PanelConfigBean.paneRepeatList[1].panelInfoList[2].panelID}
		int x = -1;
		int y = -1;
		
		int lastPointStart = 0;
		int lastPointEnde = 0;
		String lastString = "";
		int counterStart = 0;
		int counterEnde = 0;
		
		counterStart = StringUtil.getCountLetter(ref, '[');
		counterEnde = StringUtil.getCountLetter(ref, ']');
		
		if (counterStart == counterEnde) {
			for (int p = 0; p < counterStart; p++) {
				lastPointStart = ref.indexOf("[");
				lastPointEnde = ref.indexOf("]");
				
				if (x == -1) {
					lastString = ref.substring(lastPointStart +1, lastPointEnde);
					
					x = Integer.parseInt(lastString);
					//System.out.println("X: " + x);
				} else {
					lastString = ref.substring(lastPointStart +1, lastPointEnde);
					y = Integer.parseInt(lastString);
					//System.out.println("Y: " + y);
				}
				ref = ref.substring(lastPointEnde +1);
				//System.out.println(ref);
			}
			matrixInfo = new MatrixInfo(x, y);
		}
		return matrixInfo;
	}

}
