package me.allenz.zlog;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * Utility tools.
 * 
 * @author Allenz
 * @since 0.1.0-RELEASE
 */
public class Utils {

	private Utils() {
		throw new UnsupportedOperationException();
	}

	/**
	 * Consider if the string is empty.
	 * 
	 * @param str
	 *            String
	 * @return if the string is {@code null} or length equals 0 return
	 *         true,otherwise return false;
	 * @since 0.1.0-RELEASE
	 */
	public static boolean isEmpty(final String str) {
		return str == null || str.length() == 0;
	}

	/**
	 * Get the integer value of static field the declared in specified class.
	 * 
	 * @param className
	 *            the fullname of the class
	 * @param fieldName
	 *            the name of the field
	 * @param defaultValue
	 *            the default value to return when failed to get value of the
	 *            field
	 * @return the value of the field when successed, or the default value when
	 *         failure
	 * @since 0.1.0-RELEASE
	 */
	public static int intReflectStaticFieldValue(final String className,
			final String fieldName, final int defaultValue) {
		try {
			final Class<?> clazz = Class.forName(className);
			final Field field = clazz.getDeclaredField(fieldName);
			if (Modifier.isStatic(field.getModifiers())
					&& field.getType().getName().equals("int")) {
				field.setAccessible(true);
				return field.getInt(null);
			}
		} catch (final Exception e) {
			LoggerFactory.getInternalLogger().verbose(e,
					"Can not get the value of %s.%s", className, fieldName);
		}
		return defaultValue;
	}

	/**
	 * Get the boolean value of static field the declared in specified class.
	 * 
	 * @param className
	 *            the fullname of the class
	 * @param fieldName
	 *            the name of the field
	 * @param defaultValue
	 *            the default value to return when failed to get value of the
	 *            field
	 * @return the value of the field when successed, or the default value when
	 *         failure
	 * @since 0.1.0-RELEASE
	 */
	public static boolean booleanReflectStaticFieldValue(
			final String className, final String fieldName,
			final boolean defaultValue) {
		try {
			final Class<?> clazz = Class.forName(className);
			final Field field = clazz.getDeclaredField(fieldName);
			if (Modifier.isStatic(field.getModifiers())
					&& field.getType().getName().equals("int")) {
				field.setAccessible(true);
				return field.getBoolean(null);
			}
		} catch (final Exception e) {
			LoggerFactory.getInternalLogger().verbose(e,
					"Can not get the value of %s.%s", className, fieldName);
		}
		return defaultValue;
	}
}

@@ -565,24 +565,502 @@
 ) == 0;%0A%09%7D%0A%0A
+%09/**%0A%09 * Get the final tag for the class.%0A%09 * %0A%09 * @param classFullName%0A%09 *            fullname(with package) of the class%0A%09 * @param tag%0A%09 *            tag in configure%0A%09 * @return the tag for the class%0A%09 * @since 0.2.0-RELEASE%0A%09 */%0A%09public static String finalTag(final String classFullName, final String tag) %7B%0A%09%09if (tag != null) %7B%0A%09%09%09return tag;%0A%09%09%7D%0A%09%09final int dot = classFullName.lastIndexOf(%22.%22);%0A%09%09return dot == -1 ? classFullName : classFullName.substring(dot + 1);%0A%09%7D%0A%0A
 %09/**%0A%09 * Get
@@ -1119,32 +1119,32 @@
 pecified class.%0A
-
 %09 * %0A%09 * @param 
@@ -1941,118 +1941,8 @@
 ) %7B%0A
-%09%09%09LoggerFactory.getInternalLogger().verbose(e,%0A%09%09%09%09%09%22Can not get the value of %25s.%25s%22, className, fieldName);%0A
 %09%09%7D%0A
@@ -2838,32 +2838,32 @@
 ean(null);%0A%09%09%09%7D%0A
+
 %09%09%7D catch (final
@@ -2882,118 +2882,8 @@
 ) %7B%0A
-%09%09%09LoggerFactory.getInternalLogger().verbose(e,%0A%09%09%09%09%09%22Can not get the value of %25s.%25s%22, className, fieldName);%0A
 %09%09%7D%0A

add method finalTag for class Utils