package zigen.plugin.db.ext.jdt;


public class CodeCreatorUtil {
	private static final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$

	public static String propertyString(String accessModifiers, String type, String property) {
		StringBuffer sb = new StringBuffer();
		if (accessModifiers != null && !"".equals(accessModifiers)) { //$NON-NLS-1$
			sb.append(accessModifiers + " "); //$NON-NLS-1$
		}
		sb.append(type + " "); //$NON-NLS-1$
		sb.append(property + ";"); //$NON-NLS-1$
		return sb.toString();
	}

	public static String getterString(String propertyName) {
		StringBuffer sb = new StringBuffer();
		sb.append("get"); //$NON-NLS-1$
		sb.append(propertyName.substring(0, 1).toUpperCase());
		sb.append(propertyName.substring(1, propertyName.length()));

		return sb.toString();
	}

	public static String setterString(String propertyName) {
		StringBuffer sb = new StringBuffer();
		sb.append("set"); //$NON-NLS-1$
		sb.append(propertyName.substring(0, 1).toUpperCase());
		sb.append(propertyName.substring(1, propertyName.length()));
		return sb.toString();
	}

	public static String toStringString(String className, String[] properties) {
		StringBuffer sb = new StringBuffer();

		sb.append("\t" + "public String toString(){" + line_sep); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("\t" + "\t" + "StringBuffer buffer = new StringBuffer();" + line_sep); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		sb.append("\t" + "\t" + "buffer.append(\"[" + className + ":\");" + line_sep); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$

		for (int i = 0; i < properties.length; i++) {
			String property = properties[i];
			sb.append("\t" + "\t" + "buffer.append(\" " + property + ": \");" + line_sep); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
			sb.append("\t" + "\t" + "buffer.append(" + property + ");" + line_sep); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
		}

		sb.append("\t" + "\t" + "buffer.append(\"]\");" + line_sep); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		sb.append("\t" + "\t" + "return buffer.toString();" + line_sep); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		sb.append("\t" + "}" + line_sep); //$NON-NLS-1$ //$NON-NLS-2$

		return sb.toString();

	}
}
