public class ZirkulaereReihung { ... private static void printInfo(ZirkulaereReihung queue) { System.out.println("Capacity: " + queue.getCapacity()); System.out.println("Size: " + queue.getSize()); System.out.println("Leer: " + queue.isEmpty()); System.out.println("Voll: " + queue.isFull()); System.out.print("Inhalt: "); for (int i = 0; i < queue.getSize(); i++) { System.out.print(queue.getAt(i) + " "); } System.out.println("\n"); } public static void main(String[] args) { final int capacity = 5; byte value = 0; boolean exceptionRaised = false; // Erstellen System.out.println("* Queue erstellen..."); ZirkulaereReihung queue = new ZirkulaereReihung((int)capacity); printInfo(queue); // Füllen System.out.println("* Fuellen des Queue..."); for (int i = 0; i < capacity; i++) { queue.append(value++); } printInfo(queue); // Entfernen System.out.println("* Erstes Element entfernen..."); queue.dequeue(); printInfo(queue); // Eines einfügen System.out.println("* Ein Element einfuegen..."); queue.append(value++); printInfo(queue); // Drei entfernen System.out.println("* Drei Elemente entfernen..."); queue.dequeue(); queue.dequeue(); queue.dequeue(); printInfo(queue); // Drei einfügen System.out.println("* Drei Elemente einfuegen..."); for (int i = 0; i < 3; i++) { queue.append(value++); } printInfo(queue); // Alle entfernen System.out.println("* Alle Elemente entfernen..."); while (!queue.isEmpty()) { queue.dequeue(); } printInfo(queue); // Element bei 0 lesen exceptionRaised = false; System.out.println("* Element bei 0 lesen..."); try { queue.getAt(0); } catch (Exception e) { exceptionRaised = true; } System.out.println("Exception: " + exceptionRaised); printInfo(queue); // Wieder füllen System.out.println("* Wieder fuellen..."); for (int i = 0; i < capacity; i++) { queue.append(value++); } printInfo(queue); // Element bei -1 lesen exceptionRaised = false; System.out.println("* Element bei -1 lesen..."); try { queue.getAt(-1); } catch (Exception e) { exceptionRaised = true; } System.out.println("Exception: " + exceptionRaised); printInfo(queue); // Und noch eins mehr einfügen exceptionRaised = false; System.out.println("* Eins mehr einfuegen als erlaubt..."); try { queue.append(value); } catch (Exception e) { exceptionRaised = true; } System.out.println("Exception: " + exceptionRaised); printInfo(queue); } }