All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.jformchecker.utils.Utils Maven / Gradle / Ivy

There is a newer version: 0.1.18
Show newest version
package de.jformchecker.utils;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import de.jformchecker.FormCheckerElement;
import de.jformchecker.FormCheckerForm;

public class Utils {
	/**
	 * Return a nicely formated form of the form for debugging or other purposes
	 */
	public static String getDebugOutput(FormCheckerForm form) {
	    Map elements = form.getElementsAsMap();
	  
		int maxLen = 0;
		for (String key : elements.keySet()) {
			if (key.length() > maxLen) {
				maxLen = key.length();
			}
		}
		maxLen += 3;
		StringBuilder debugOutput = new StringBuilder();
		for (String key : elements.keySet()) {

			debugOutput.append(key).append(StringUtils.leftPad(":", maxLen - key.length()));
			debugOutput.append(elements.get(key).getValue()).append("\n");
		}
		return debugOutput.toString();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy