package org.xander.katas;

import java.util.ArrayList;
import java.util.List;

public class RecentlyUsedList {
    private static final String LIST_IS_EMPTY = "list is empty";
    private int capacity = 5;
    private List<String> stringContainer = new ArrayList<>(capacity);

    public void pushAString(String stringToHold) {
        if (stringToHold == null || stringToHold.isEmpty()) {
            throw new UnsupportedOperationException("it is not possible to add a null or empty size string");
        }

        if (getCapacity() == stringContainer.size() && itIsPossibleToGetAnElement()) {
            stringContainer.remove(0);
        }

        if (elementIsUnique(stringToHold)) {

            stringContainer.add(stringToHold);
        }
    }

    private boolean elementIsUnique(String elementToCheckForUniqueness) {
            if (itIsPossibleToGetAnElement()) {
                for (String element : stringContainer) {
                    if (element.equals(elementToCheckForUniqueness)) {
                        return false;
                    }
                }
            }
        return true;
    }

    public String getLastString() {
        int lastElement = 0;
        if (itIsPossibleToGetAnElement())
            return getReversedStringContainer().get(lastElement);
        throw new UnsupportedOperationException(LIST_IS_EMPTY);
    }

    public String getFirstString() {
        int firstElement = stringContainer.size() - 1;
        if (itIsPossibleToGetAnElement())
            return getReversedStringContainer().get(firstElement);
        throw new UnsupportedOperationException(LIST_IS_EMPTY);
    }

    private boolean itIsPossibleToGetAnElement() {
        if (!stringContainer.isEmpty()) {
            return true;
        }
        return false;
    }

    private List<String> getReversedStringContainer() {
        List<String> reversedStringContainer = new ArrayList<>(stringContainer.size());
        for (int i = stringContainer.size(); i > 0; i--) {
            reversedStringContainer.add(stringContainer.get(i - 1));
        }
        return reversedStringContainer;
    }

    public int getSizeOfList() {
        return stringContainer.size();
    }

    public String getElementNumber(int index) {
        if (index < 0 || index >= stringContainer.size()) {
            throw new UnsupportedOperationException("the index value you entered is not reachable");
        }

        String elementToGet = "";
        for (int i = 0; i < stringContainer.size(); i++) {
            if (i == index)
                elementToGet = stringContainer.get(i);
        }
        return elementToGet;
    }

    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }

    public int getCapacity() {
        return capacity;
    }
}

@@ -1219,32 +1219,34 @@
 oGetAnElement())
+ %7B
 %0A            ret
@@ -1288,32 +1288,42 @@
 t(lastElement);%0A
+        %7D%0A
         throw ne
@@ -1510,16 +1510,18 @@
 ement())
+ %7B
 %0A       
@@ -1572,32 +1572,42 @@
 (firstElement);%0A
+        %7D%0A
         throw ne
@@ -2566,16 +2566,18 @@
 = index)
+ %7B
 %0A       
@@ -2624,16 +2624,30 @@
 get(i);%0A
+            %7D%0A
         

Update RecentlyUsedList.java