From 72cc9abf555a7ad0609f3f5fa520e967915d893a Mon Sep 17 00:00:00 2001 From: schneefux Date: Thu, 27 Sep 2018 11:58:28 +0200 Subject: Add more javadocs --- .../de/ostfalia/algo/ws18/s1/LinkedListNode.class | Bin 1442 -> 1316 bytes .../bin/de/ostfalia/algo/ws18/s1/Main.class | Bin 0 -> 1310 bytes .../bin/de/ostfalia/algo/ws18/s1/Management.class | Bin 7856 -> 7856 bytes .../de/ostfalia/algo/ws18/s1/LinkedListNode.java | 40 +++++- .../src/de/ostfalia/algo/ws18/s1/Main.java | 9 ++ .../src/de/ostfalia/algo/ws18/s1/Management.java | 140 +++++++++++++++++---- 6 files changed, 162 insertions(+), 27 deletions(-) create mode 100644 AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/Main.class create mode 100644 AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/Main.java diff --git a/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/LinkedListNode.class b/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/LinkedListNode.class index 92305e7..a3aff64 100644 Binary files a/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/LinkedListNode.class and b/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/LinkedListNode.class differ diff --git a/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/Main.class b/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/Main.class new file mode 100644 index 0000000..db6e52f Binary files /dev/null and b/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/Main.class differ diff --git a/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/Management.class b/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/Management.class index 663b9b6..d077242 100644 Binary files a/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/Management.class and b/AlgoAufgabe1/bin/de/ostfalia/algo/ws18/s1/Management.class differ diff --git a/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/LinkedListNode.java b/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/LinkedListNode.java index 5333ac2..a7cf4f1 100644 --- a/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/LinkedListNode.java +++ b/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/LinkedListNode.java @@ -1,30 +1,62 @@ package de.ostfalia.algo.ws18.s1; +/** + * A generic linked list node. + * + * @param The type of the value this node contains. + */ public class LinkedListNode { + /** + * This node's value. + */ private E value; + /** + * The next linked node. + */ private LinkedListNode next; + /** + * Create a node with the given value and no next node. + * + * @param value This node's value. + */ public LinkedListNode(E value) { this.value = value; this.next = null; } - public boolean hasNext() { - return this.next != null; - } - + /** + * Get this node's value. + * + * @return This node's value. + */ public E getValue() { return this.value; } + /** + * Set this node's value. + * + * @param value The new value. + */ public void setValue(E value) { this.value = value; } + /** + * Get the next linked node. + * + * @return The next linked node. + */ public LinkedListNode getNext() { return this.next; } + /** + * Set the next linked node. + * + * @param next + */ public void setNext(LinkedListNode next) { this.next = next; } diff --git a/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/Main.java b/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/Main.java new file mode 100644 index 0000000..686a0bd --- /dev/null +++ b/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/Main.java @@ -0,0 +1,9 @@ +package de.ostfalia.algo.ws18.s1; + +public class Main { + public static void main(String ...args) { + Management management = new Management("Materialien/Mitglieder10000.txt"); + System.out.println("management hat " + management.size() + " Elemente, eingefügt in " + management.numberOfOperations()); + System.out.println("Suche Claudia Wexler: " + management.search("Wexler", "Claudia") + ", gefunden nach " + management.numberOfOperations()); + } +} diff --git a/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/Management.java b/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/Management.java index 8630615..2be04c7 100644 --- a/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/Management.java +++ b/AlgoAufgabe1/src/de/ostfalia/algo/ws18/s1/Management.java @@ -4,36 +4,63 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; import java.util.Optional; import java.util.function.Predicate; -import de.ostfalia.algo.ws18.base.Gender; import de.ostfalia.algo.ws18.base.IManagement; import de.ostfalia.algo.ws18.base.IMember; import de.ostfalia.algo.ws18.base.KindOfSport; public class Management implements IManagement { + /** + * Tracks the number of operations. + */ private int numberOfOperations = 0; + /** + * Current head node. + */ private Optional> head = Optional.empty(); + /** + * Length of the list. + */ private int size = 0; - boolean reversed = false; + /** + * Whether the list is reversed, i. e. the head is the tail. + */ + private boolean reversed = false; + /** + * Empty constructor. + */ public Management() { } + /** + * Insert from an array of strings. + * + * @param membersCsv Array of CSV rows. + */ public Management(String[] membersCsv) { for (String memberCsv : membersCsv) { this.insert(new Member(memberCsv)); } } + /** + * Read from the CSV file and insert. + * + * @param filename Path to the CSV file. + */ public Management(String filename) { this.importFromFile(filename); } + /** + * Read from the CSV file and insert. + * + * @param filename Path to the CSV file. + */ private void importFromFile(String filename) { File file = new File(filename); @@ -44,25 +71,13 @@ public class Management implements IManagement { } } - @Override - public int size() { - return this.size; - } - - @Override - public boolean insert(IMember value) { - this.numberOfOperations++; - - LinkedListNode newHead = new LinkedListNode(value); - if (this.head.isPresent()) { - newHead.setNext(this.head.get()); - } - this.head = Optional.of(newHead); - - this.size++; - return true; // TODO? - } - + /** + * Create a filtered version of this list. + * + * @param criteria Criteria to filter for. + * @param breakAfterFirstMatch If true, return after the first match. + * @return A new list where all elements meet the given criteria. + */ private Management filter(Predicate criteria, boolean breakAfterFirstMatch) { Management result = new Management(); if (!this.head.isPresent()) { @@ -74,6 +89,7 @@ public class Management implements IManagement { LinkedListNode currentNode = this.head.get(); do { + // traverse = 1 operation this.numberOfOperations++; IMember currentValue = currentNode.getValue(); @@ -88,40 +104,113 @@ public class Management implements IManagement { return result; } + /** + * Find the first element that matches the given criteria. + * + * @param criteria Criteria to search for. + * @return An optional containing the first element that matches the given criteria. + */ private Optional search(Predicate criteria) { return this.filter(criteria, true).head.map(head -> head.getValue()); } + /** + * Count the number of elements that match the given criteria. + * + * @param criteria Criteria to filter for. + * @return The number of elements that match the given criteria. + */ private long size(Predicate criteria) { return this.filter(criteria, false).size; } + /** + * Reverse the order of the list. + */ public void reverse() { this.reversed = !this.reversed; } + /** + * @return The length of this list. + */ + @Override + public int size() { + return this.size; + } + + /** + * Add an element at the start of the list. + * Replace the current head with a new node and link this node to the old head. + * + * @return TODO? + */ + @Override + public boolean insert(IMember value) { + this.numberOfOperations++; + + LinkedListNode newHead = new LinkedListNode(value); + if (this.head.isPresent()) { + newHead.setNext(this.head.get()); + } + this.head = Optional.of(newHead); + + this.size++; + return true; // TODO? + } + + /** + * Find the first member with the given key. + * + * @param key The key to search for. + * @return The member or null. + */ @Override public IMember search(long key) { return this.search(member -> member.getKey() == key).orElse(null); } + /** + * Find the first member with the given name. + * + * @param name The name of the member. + * @param firstName first name of the member. + * @return The member or null. + */ @Override public IMember search(String name, String firstName) { return this.search(member -> member.getName().equals(name) && member.getFirstName().equals(firstName)).orElse(null); } + /** + * Count the number of members which have an association to the given kindOfSport. + * + * @param kindOfSport The kindOfSport of the members. + * @return The number of members with the given kindOfSport. + */ @Override public int size(KindOfSport kindOfSport) { return (int) this.size(member -> member.getKindOfSport().equals(kindOfSport)); } + /** + * Return the members which have an association to the given kindOfSport. + * + * @param kindOfSport The kindOfSport of the members. + * @return An array of the members with the given kindOfSport. + */ @Override public IMember[] discipline(KindOfSport kindOfSport) { return this.filter(member -> member.getKindOfSport().equals(kindOfSport), false) .toArray(); } + /** + * Convert the list to an array. + * + * @return The elements of this list as array. + */ @Override public IMember[] toArray() { IMember[] array = new IMember[this.size]; @@ -143,6 +232,11 @@ public class Management implements IManagement { return array; } + /** + * Reset the number of operation counter and get the last value. + * + * @return The number of operations recorded since the last call. + */ @Override public int numberOfOperations() { int numberOfOperations = this.numberOfOperations; -- cgit v1.3.1