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 LinkedList<T>
 {
     private T data;
     private LinkedList<T> prevNode, nextNode;
 
     /**
      *  Constructs a new element
      *
      * @param  data, data of object
      * @param  node, previous node
      */
     public LinkedList(T data, LinkedList<T> node)
     {
         this.setData(data);
         this.setPrevNode(node);
         this.setNextNode(null);
     }
 
     /**
      *  Clone an object,
      *
      * @param  node  object to clone
      */
     public LinkedList(LinkedList<T> node)
     {
         this.setData(node.data);
         this.setPrevNode(node.prevNode);
         this.setNextNode(node.nextNode);
     }
 
     /**
      *  Setter for T data in DoubleLinkedNode object
      *
      * @param  data, update data of object
      */
     public void setData(T data)
     {
         this.data = data;
     }
 
     /**
      *  Returns T data for this element
      *
      * @return  data associated with object
      */
     public T getData()
     {
         return this.data;
     }
 
     /**
      *  Setter for prevNode in DoubleLinkedNode object
      *
      * @param node, prevNode to current Object
      */
     public void setPrevNode(LinkedList<T> node)
     {
         this.prevNode = node;
     }
 
     /**
      *  Setter for nextNode in DoubleLinkedNode object
      *
      * @param node, nextNode to current Object
      */
     public void setNextNode(LinkedList<T> node)
     {
         this.nextNode = node;
     }
 
 
     /**
      *  Returns reference to previous object in list
      *
      * @return  the previous object in the list
      */
     public LinkedList<T> getPrevious()
     {
         return this.prevNode;
     }
 
     /**
      *  Returns reference to next object in list
      *
      * @return  the next object in the list
      */
     public LinkedList<T> getNext()
     {
         return this.nextNode;
     }
 }
import java.util.Iterator;

/**
 * Queue Iterator
 *
 * 1. "has a" current reference in Queue
 * 2. supports iterable required methods for next that returns a generic T Object
 */
class QueueIterator<T> implements Iterator<T> {
    LinkedList<T> current;  // current element in iteration

    // QueueIterator is pointed to the head of the list for iteration
    public QueueIterator(LinkedList<T> head) {
        current = head;
    }

    // hasNext informs if next element exists
    public boolean hasNext() {
        return current != null;
    }

    // next returns data object and advances to next position in queue
    public T next() {
        T data = current.getData();
        current = current.getNext();
        return data;
    }
}

/**
 * Queue: custom implementation
 * @author     John Mortensen
 *
 * 1. Uses custom LinkedList of Generic type T
 * 2. Implements Iterable
 * 3. "has a" LinkedList for head and tail
 */
public class Queue<T> implements Iterable<T> {
    LinkedList<T> head = null, tail = null;

    /**
     *  Add a new object at the end of the Queue,
     *
     * @param  data,  is the data to be inserted in the Queue.
     */
    public void add(T data) {
        // add new object to end of Queue
        LinkedList<T> tail = new LinkedList<>(data, null);

        if (this.head == null)  // initial condition
            this.head = this.tail = tail;
        else {  // nodes in queue
            this.tail.setNextNode(tail); // current tail points to new tail
            this.tail = tail;  // update tail
        }
    }

    /**
     *  Returns the data of head.
     *
     * @return  data, the dequeued data
     */
    public T delete() {
        T data = this.peek();
        if (this.tail != null) { // initial condition
            this.head = this.head.getNext(); // current tail points to new tail
            if (this.head != null) {
                this.head.setPrevNode(tail);
            }
        }
        return data;
    }

    /**
     *  Returns the data of head.
     *
     * @return  this.head.getData(), the head data in Queue.
     */
    public T peek() {
        return this.head.getData();
    }

    /**
     *  Returns the head object.
     *
     * @return  this.head, the head object in Queue.
     */
    public LinkedList<T> getHead() {
        return this.head;
    }

    /**
     *  Returns the tail object.
     *
     * @return  this.tail, the last object in Queue
     */
    public LinkedList<T> getTail() {
        return this.tail;
    }

    /**
     *  Returns the iterator object.
     *
     * @return  this, instance of object
     */
    public Iterator<T> iterator() {
        return new QueueIterator<>(this.head);
    }
}
public class Person extends Generics {

    public static KeyTypes key = KeyType.title;
	public static void setOrder(KeyTypes key) { Person.key = key; }
	public enum KeyType implements KeyTypes {title,name, dob, height, weight}

	private final String name;
	private final String dob;
	private final double height;
	private final double weight;
    
   
	public Person(String name, String dob, double height, double weight)
	{
		super.setType("Person");
		this.name = name;
		this.dob = dob;
		this.height = height;
		this.weight = weight;
	}

	@Override
	protected KeyTypes getKey() { return Person.key; }
	

	@Override
	public String toString()
	{
		String output="";
		if (KeyType.name.equals(this.getKey())) {
			output += this.name;
		} else if (KeyType.dob.equals(this.getKey())) {
			output += this.dob; 
		} else if (KeyType.height.equals(this.getKey())) {
			output += this.height;
		}else if (KeyType.weight.equals(this.getKey())) {
			output += this.weight;
		}else {
			output += super.getType() + ": " + this.name + ", " + this.dob + ", " + this.height + ", " + this.weight;
		}
		return output;
		
	}

	// Test data initializer
	public static Person[] persons() {
		return new Person[]{
				new Person("Joe Biden", "09-09-1940", 120, 120),
				new Person("Donald Trump", "09-09-1940", 120, 120),
				new Person("Kamala Harris", "09-09-1940", 120, 120)		
            };
	}
	

	public static void main(String[] args)
	{
		Person[] objs = persons();

		Person.setOrder(KeyType.title);
		Person.print(objs);

		Person.setOrder(KeyType.name);
		Person.print(objs);

		Person.setOrder(KeyType.dob);
		Person.print(objs);

		Person.setOrder(KeyType.weight);
		Person.print(objs);

		Person.setOrder(KeyType.height);
		Person.print(objs);
	}

}
Person.main(null);
class [LREPL.$JShell$22B$Person; 3
Generic: Person listed by title
Person: Joe Biden, 09-09-1940, 120.0, 120.0
Person: Donald Trump, 09-09-1940, 120.0, 120.0
Person: Kamala Harris, 09-09-1940, 120.0, 120.0

class [LREPL.$JShell$22B$Person; 3
Generic: Person listed by name
Joe Biden
Donald Trump
Kamala Harris

class [LREPL.$JShell$22B$Person; 3
Generic: Person listed by dob
09-09-1940
09-09-1940
09-09-1940

class [LREPL.$JShell$22B$Person; 3
Generic: Person listed by weight
120.0
120.0
120.0

class [LREPL.$JShell$22B$Person; 3
Generic: Person listed by height
120.0
120.0
120.0

class QueueManager<T> {
    // queue data
    private final String name; // name of queue
    private int count = 0; // number of objects in queue
    public final Queue<T> queue = new Queue<>(); // queue object

    /**
     *  Queue constructor
     *  Title with empty queue
     */
    public QueueManager(String name) {
        this.name = name;
    }

    /**
     *  Queue constructor
     *  Title with series of Arrays of Objects
     */
    public QueueManager(String name, T[]... seriesOfObjects) {
        this.name = name;
        this.addList(seriesOfObjects);
    }
    /**
     * Add a list of objects to queue
     */
    public void addList(T[]... seriesOfObjects) {  //accepts multiple generic T lists
        for (T[] objects: seriesOfObjects)
            for (T data : objects) {
                this.queue.add(data);
                this.count++;
            }
    }
    /**
     * Print any array objects from queue
     */
    public void printQueue() {
        System.out.println(this.name + " count: " + count);
        System.out.print(this.name + " data: ");
        for (T data : queue)
            System.out.print(data + " ");
        System.out.println();
    }
}
class QueueTester {
    public static void main(String[] args)
    {

        Person.setOrder(Person.KeyType.name);
        
        QueueManager qGenerics = new QueueManager("My Generics", Person.persons());
        qGenerics.printQueue();
                
        qGenerics.queue.delete();
        
        qGenerics.printQueue();


    }
}
QueueTester.main(null)
My Generics count: 3
My Generics data: Joe Biden Donald Trump Kamala Harris 
My Generics count: 3
My Generics data: Joe Biden Donald Trump Kamala Harris 
My Generics count: 3
My Generics data: Donald Trump Kamala Harris