package com.eactive.eai.rms.onl.common.sql;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PreparedString {

	private String seat;
	private String preparedString;
	private int numberOfSeat;
	private Pattern pattern;

	public PreparedString(String seat, String preparedString) {
		this.seat = seat;
		this.preparedString = preparedString;
		this.pattern = Pattern.compile(seat);
		Matcher matcher = pattern.matcher(preparedString);
		int size = 0;
		while(matcher.find()) {
			size++;
		}
		this.numberOfSeat = size;
	}

	public String getSeat() {
		return seat;
	}

	public String getPreparedString() {
		return preparedString;
	}

	public int getNumberOfSeat() {
		return numberOfSeat;
	}
	
	public String replaceSeatsToArgs(String...args) throws Exception {
		if(args.length != numberOfSeat) {
			throw new Exception("");
		}
		
		String subject = preparedString;
		for(String arg : args) {
			subject = pattern.matcher(subject).replaceFirst(arg);
		}
		return subject;
	}
	
}