Ad
  • Generified Kata class
  • Added extensive testing
    • GetPrivateAttribute
    • Remove
    • Add
    • MergeLinkedList
    • MergeKata
Code
Diff
  • import java.util.LinkedList;
    
    public class Kata<T> {
    
        private LinkedList<T> linkedList;
    
        public Kata() {
          this.linkedList = new LinkedList<>();
        }
      
        public Kata(LinkedList<T> list) {
            this.linkedList = list;
        }
    
        public Kata(Kata<T> kata) {
            this.linkedList = kata.linkedList;
        }
    
        public LinkedList<T> getLinkedList(){
            return this.linkedList;
        }
    
        public void AddItem(T itemToAdd, T whereToAddIt) {
            this.linkedList.add(this.linkedList.indexOf(whereToAddIt) + 1, itemToAdd);
        }
    
        public void RemoveItem(T whereToRemoveIt) {
            this.linkedList.remove(whereToRemoveIt);
        }
    
        public void MergeLists(LinkedList<T> listToMerge) {
            this.linkedList.addAll(listToMerge);
        }
    
        public void MergeKatas(Kata<T> kataToMerge) {
            this.linkedList.addAll(kataToMerge.linkedList);
        }
    
    }
    • import java.util.*;
    • import java.util.LinkedList;
    • public class Kata {
    • private LinkedList<String> linkedList;
    • public static void AddItem(String itemToAdd, String whereToAddIt) {
    • // When given a string, whereToAddIt, find that string
    • // in the LinkedList and add itemToAdd directly after whereToAddIt
    • // in the LinkedList
    • }
    • public static void RemoveItem(String whereToRemoveIt) {
    • // When given a string, whereToRemoveIt, find that string
    • // in the LinkedList and remove it from the linked list
    • public class Kata<T> {
    • private LinkedList<T> linkedList;
    • public Kata() {
    • this.linkedList = new LinkedList<>();
    • }
    • public static void MergeLists(LinkedList<String> listToMerge) {
    • // Merge this linked list with the previous
    • public Kata(LinkedList<T> list) {
    • this.linkedList = list;
    • }
    • public Kata(Kata<T> kata) {
    • this.linkedList = kata.linkedList;
    • }
    • public LinkedList<T> getLinkedList(){
    • return this.linkedList;
    • }
    • public void AddItem(T itemToAdd, T whereToAddIt) {
    • this.linkedList.add(this.linkedList.indexOf(whereToAddIt) + 1, itemToAdd);
    • }
    • public void RemoveItem(T whereToRemoveIt) {
    • this.linkedList.remove(whereToRemoveIt);
    • }
    • public void MergeLists(LinkedList<T> listToMerge) {
    • this.linkedList.addAll(listToMerge);
    • }
    • public void MergeKatas(Kata<T> kataToMerge) {
    • this.linkedList.addAll(kataToMerge.linkedList);
    • }
    • }