package thisandthat;

/**
 * @author Daniel Weschke
 */
public class WObject {
	private static boolean supressErrorMessage = false;
	private String name;

	public static boolean isSupressErrorMessage() {
		return supressErrorMessage;
	}

	public static void setSupressErrorMessage(boolean supressErrorMessage) {
		WObject.supressErrorMessage = supressErrorMessage;
	}
    
    public static <T> T first(T[] array) {
        return array[0];
    }
    
    public static <T> T nth(T[] array, int n) {
        return array[n];
    }
    
    public static <T> T last(T[] array) {
        return array[array.length - 1];
    }

	public String getName() {
		return name;
	}

	public WObject setName(String name) {
		this.name = name;
		return this;
	}
	
	/**
	 * The declaration of that method is:
	 * public T cast(Object o)
	 * @param o
	 * @param clazz
	 * @return casted object
	 */
	public static <T> T convertInstanceOfObject(Object o, Class<T> clazz) {
	    try {
	        return clazz.cast(o);
	    } catch(ClassCastException e) {
	        return null;
	    }
	}
	
	@Override
	public String toString(){
		return name;
	}
    
    public void println(){
    	System.out.println(this);
    }

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		WObject obj = new WObject();
    	obj.setName("one");
        obj.println();
	}

}
