/* This is wrapper class...
 Objective would be to push more functionality into this Class to enforce consistent definition
 */
public abstract class Generics {
	public final String masterType = "Generic";
	private String type;	// extender should define their data type

	// generic enumerated interface
	public interface KeyTypes {
		String name();
	}
	protected abstract KeyTypes getKey();  	// this method helps force usage of KeyTypes

	// getter
	public String getMasterType() {
		return masterType;
	}

	// getter
	public String getType() {
		return type;
	}

	// setter
	public void setType(String type) {
		this.type = type;
	}
	
	// this method is used to establish key order
	public abstract String toString();

	// static print method used by extended classes
	public static void print(Generics[] objs) {
		// print 'Object' properties
		System.out.println(objs.getClass() + " " + objs.length);

		// print 'Generics' properties
		if (objs.length > 0) {
			Generics obj = objs[0];	// Look at properties of 1st element
			System.out.println(
					obj.getMasterType() + ": " + 
					obj.getType() +
					" listed by " +
					obj.getKey());
		}

		// print "Generics: Objects'
		for(Object o : objs)	// observe that type is Opaque
			System.out.println(o);

		System.out.println();
	}
}
public class User extends Generics {
	// Class data
	public static KeyTypes key = KeyType.title;  // static initializer
	public static void setOrder(KeyTypes key) {User.key = key;}
	public enum KeyType implements KeyTypes {title, name, grade, role}

	// Instance data
	private final String name;
	private final int grade;
	private final String role;

	// Constructor
	User(String name, int grade, String role)
	{
		this.setType("User");
		this.name = name;
		this.grade = grade;
		this.role = role;
	}

	/* 'Generics' requires getKey to help enforce KeyTypes usage */
	@Override
	protected KeyTypes getKey() { return User.key; }

	/* 'Generics' requires toString override
	 * toString provides data based off of Static Key setting
	 */
	@Override
	public String toString() {		
		String output="";
		if (KeyType.name.equals(this.getKey())) {
			output += this.name;
		} else if (KeyType.grade.equals(this.getKey())) {
			output += this.grade;
		} else if (KeyType.role.equals(this.getKey())) {
			output += this.role;
		} else {
			output = super.getType() + ": " + this.name + ", " + this.grade + ", " + this.role;
		}
		return output;
	}

	// Test data initializer
	public static User[] users() {
		return new User[]{
				new User("Allie", 12, "Admin"),
			    new User("Soren", 12, "Admin"),
				new User("Saathvika", 12, "Admin"),
		};
	}
	
	public static void main(String[] args)
	{
		// Inheritance Hierarchy
		User[] objs = users();

		// print with title
		User.setOrder(KeyType.title);
		User.print(objs);

		// print name only
		User.setOrder(KeyType.name);
		User.print(objs);
	}
	
}
User.main(null);