diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..3b7b654
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/src/debug/ContainerArray.java b/src/debug/ContainerArray.java
index 124ece6..918f633 100755
--- a/src/debug/ContainerArray.java
+++ b/src/debug/ContainerArray.java
@@ -1,33 +1,56 @@
package debug;
+import java.util.List;
public class ContainerArray {
- private int initialCapacity = 10;
+ private static final int LIMIT = 10;
private int currentSize = 0;
private Object[] internalArray;
public ContainerArray () {
- this(10);
+ this(LIMIT);
}
- public ContainerArray (int initialCapacity) {
- internalArray = new Object[initialCapacity];
+ public ContainerArray (int limit) {
+ internalArray = new Object[limit];
}
- public void add (E element) {
- internalArray[currentSize++] = element;
+ public void add (E element) { //1: handling array out of bounds; don't allow addition when full
+ if(currentSize < internalArray.length){
+ internalArray[currentSize++] = element;
+ }
+ }
+
+ public void addAll(List toAdd){
+ for(E e: toAdd){
+ add(e);
+ }
}
public int size () {
return currentSize;
}
- public void remove (E objectToRemove) {
- currentSize--;
+ public void remove (E objectToRemove) { //2: Remove object (first instance) and shift rightmost elements to left
+ int index = -1;
+ for(int i = 0; i < internalArray.length; i++){
+ if(objectToRemove.equals(internalArray[i])){
+ index = i;
+ break;
+ }
+ }
+ if(index != -1){
+ for(;index < internalArray.length-1; index++){
+ internalArray[index] = internalArray[index+1];
+ internalArray[index+1] = null;
+ }
+ currentSize--; //3: only decrement currentSize if something is removed
+ }
}
@SuppressWarnings("unchecked")
- public E get (int index) {
- return (E)internalArray[index];
+ public E get (int index) { //4: handle index out of bounds
+ if(index>=0 && index < LIMIT) return (E)internalArray[index];
+ return null;
}
}
diff --git a/src/debug/ContainerArrayTest.java b/src/debug/ContainerArrayTest.java
index c566d50..d42c491 100755
--- a/src/debug/ContainerArrayTest.java
+++ b/src/debug/ContainerArrayTest.java
@@ -1,6 +1,9 @@
package debug;
import static org.junit.Assert.*;
+
+import java.util.Arrays;
+
import org.junit.Before;
import org.junit.Test;
@@ -20,28 +23,60 @@ public void testSizeChangeWithAdd () {
myContainer.add("Camel");
assertEquals("Add size", 3, myContainer.size());
}
+
+ @Test //
+ public void testStoreLimit () {
+ myContainer.addAll(Arrays.asList("aaaaaaaaaaaaaaaaaaaaaa".split("")));
+ assertEquals("Add size", 10, myContainer.size());
+ }
@Test
public void testObjectIsStored () {
String alligator = "Alligator";
myContainer.add(alligator);
+ myContainer.add("Alligator");
assertEquals("Add should be same reference", alligator, myContainer.get(0));
}
- @Test
+ @Test
public void testSizeChangeWithRemove () {
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Alligator");
assertEquals("Remove size", 1, myContainer.size());
}
+
+ @Test //
+ public void testRemoveNonExistentObject () {
+ myContainer.add("Alligator");
+ myContainer.add("Bear");
+ myContainer.remove("Falafel");
+ assertEquals("Remove size", 2, myContainer.size());
+ }
+
+ @Test //
+ public void testRemoveModifiesAndShiftsArray () {
+ myContainer.add("Alligator");
+ myContainer.add("Bear");
+ myContainer.remove("Alligator");
+ assertEquals("Bear", myContainer.get(0));
+ }
+ @Test //
+ public void testGetOutOfBounds () {
+ myContainer.add("Alligator");
+ myContainer.add("Bear");
+ myContainer.add("Loofah");
+ assertEquals(null, myContainer.get(-1));
+ assertEquals(null, myContainer.get(2568));
+ }
@Test
- public void testObjectIsRemoved () {
+ public void testObjectIsRemoved () {
String alligator = "Alligator";
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.remove("Bear");
+ myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
}
}
diff --git a/src/resource/invalidbasegiven.properties b/src/resource/invalidbasegiven.properties
new file mode 100644
index 0000000..985e493
--- /dev/null
+++ b/src/resource/invalidbasegiven.properties
@@ -0,0 +1 @@
+Test=test
\ No newline at end of file
diff --git a/src/resource/validbasegiven.properties b/src/resource/validbasegiven.properties
new file mode 100644
index 0000000..985e493
--- /dev/null
+++ b/src/resource/validbasegiven.properties
@@ -0,0 +1 @@
+Test=test
\ No newline at end of file
diff --git a/src/tdd/Sheet.java b/src/tdd/Sheet.java
new file mode 100644
index 0000000..bd9e234
--- /dev/null
+++ b/src/tdd/Sheet.java
@@ -0,0 +1,34 @@
+package tdd;
+
+import java.util.HashMap;
+
+public class Sheet {
+ HashMap sheetMap;
+ HashMap literalMap;
+ public Sheet() {
+ this.sheetMap = new HashMap<>();
+ this.literalMap = new HashMap<>();
+ }
+
+ public String get(String key) {
+ String toReturn = sheetMap.get(key);
+ if(toReturn!=null) return toReturn;
+ return "";
+ }
+
+ public void put(String theCell, String string) {
+ try{
+ int testInt = Integer.parseInt(string.trim());
+ sheetMap.put(theCell, string.trim());
+ }
+ catch(Exception e){
+ sheetMap.put(theCell, string);
+ }
+ literalMap.put(theCell, string);
+ }
+
+ public Object getLiteral(String theCell) {
+ return literalMap.get(theCell);
+ }
+
+}
diff --git a/src/tdd/TestSheet.java b/src/tdd/TestSheet.java
new file mode 100644
index 0000000..78d2347
--- /dev/null
+++ b/src/tdd/TestSheet.java
@@ -0,0 +1,85 @@
+package tdd;
+
+//static allows to import all static methods from this class, Assert
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class TestSheet {
+
+ @Test
+ public void testThatCellsAreEmptyByDefault() {
+ Sheet sheet = new Sheet();
+ assertEquals("", sheet.get("A1"));
+ assertEquals("", sheet.get("ZX347"));
+ }
+
+ @Test
+ public void testThatTextCellsAreStored() {
+ Sheet sheet = new Sheet();
+ String theCell = "A21";
+
+ sheet.put(theCell, "A string");
+ assertEquals("A string", sheet.get(theCell));
+
+ sheet.put(theCell, "A different string");
+ assertEquals("A different string", sheet.get(theCell));
+
+ sheet.put(theCell, "");
+ assertEquals("", sheet.get(theCell));
+ }
+
+ @Test
+ public void testThatManyCellsExist() {
+ Sheet sheet = new Sheet();
+ sheet.put("A1", "First");
+ sheet.put("X27", "Second");
+ sheet.put("ZX901", "Third");
+
+ assertEquals("A1", "First", sheet.get("A1"));
+ assertEquals("X27", "Second", sheet.get("X27"));
+ assertEquals("ZX901", "Third", sheet.get("ZX901"));
+
+ sheet.put("A1", "Fourth");
+ assertEquals("A1 after", "Fourth", sheet.get("A1"));
+ assertEquals("X27 same", "Second", sheet.get("X27"));
+ assertEquals("ZX901 same", "Third", sheet.get("ZX901"));
+ }
+
+ @Test
+ public void testThatNumericCellsAreIdentifiedAndStored() {
+ Sheet sheet = new Sheet();
+ String theCell = "A21";
+
+ sheet.put(theCell, "X99"); // "Obvious" string
+ assertEquals("X99", sheet.get(theCell));
+
+ sheet.put(theCell, "14"); // "Obvious" number
+ assertEquals("14", sheet.get(theCell));
+
+ sheet.put(theCell, " 99 X"); // Whole string must be numeric
+ assertEquals(" 99 X", sheet.get(theCell));
+
+ sheet.put(theCell, " 1234 "); // Blanks ignored
+ assertEquals("1234", sheet.get(theCell));
+
+ sheet.put(theCell, " "); // Just a blank
+ assertEquals(" ", sheet.get(theCell));
+ }
+
+ @Test
+ public void testThatWeHaveAccessToCellLiteralValuesForEditing() {
+ Sheet sheet = new Sheet();
+ String theCell = "A21";
+
+ sheet.put(theCell, "Some string");
+ assertEquals("Some string", sheet.getLiteral(theCell));
+
+ sheet.put(theCell, " 1234 ");
+ assertEquals(" 1234 ", sheet.getLiteral(theCell));
+
+ sheet.put(theCell, "=7"); // Foreshadowing formulas:)
+ assertEquals("=7", sheet.getLiteral(theCell));
+ }
+
+}
diff --git a/src/voogasalad/TabAttributes.java b/src/voogasalad/TabAttributes.java
new file mode 100644
index 0000000..fe23ef4
--- /dev/null
+++ b/src/voogasalad/TabAttributes.java
@@ -0,0 +1,98 @@
+package voogasalad;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import javafx.geometry.Insets;
+import javafx.geometry.Pos;
+import javafx.scene.Node;
+import javafx.scene.control.Label;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.VBox;
+
+/**
+ * Abstract Tab for setting attributes to go in the Inspector Pane in either the Level or Actor Editing Environment GUI.
+ * @author AnnieTang
+ *
+ */
+public class TabAttributes {
+ private static final String DEFAULT_BASE = "invalidbasegiven";
+ private static final int PADDING = 10;
+ private static final double TEXTFIELD_WIDTH = 150;
+ private static final String EDITOR_ELEMENTS = "EditorElements";
+ private static final String PROMPT = "Select";
+ private static final String DELIMITER = ",";
+ private static final String LABEL = "Label";
+ private static final String OPTIONS = "Options";
+ private static final String TEXTFIELD = "Textfields";
+ private static final String COMBOBOXES = "Comboboxes";
+ private static final String TEST = "TEST";
+ private static final String GO = "GO";
+ private ResourceBundle myAttributesResources;
+ private String levelOptionsResource;
+
+ public TabAttributes(String tabText, String levelOptionsResource) {
+ this.levelOptionsResource = levelOptionsResource;
+ setResources();
+ }
+
+ private void setResources(){
+ try{
+ this.myAttributesResources = ResourceBundle.getBundle(levelOptionsResource);
+ }catch(Exception e){
+ this.myAttributesResources = ResourceBundle.getBundle(DEFAULT_BASE);
+ }
+ }
+
+ public String getResourcesBundleBaseName(){
+ return myAttributesResources.getBaseBundleName();
+ }
+
+ Node getContent() {
+ VBox vbox = new VBox(PADDING);
+ vbox.setPadding(new Insets(PADDING, PADDING, PADDING, PADDING));
+
+
+ String[] elements = myAttributesResources.getString(EDITOR_ELEMENTS).split(DELIMITER);
+ for (int i = 0; i < elements.length; i++) {
+ HBox hbox = new HBox(PADDING);
+ hbox.setAlignment(Pos.CENTER_LEFT);
+ Label label = new Label(myAttributesResources.getString(elements[i] + LABEL));
+ label.setWrapText(true);
+// IGUIElement elementToCreate = null;
+// elementToCreate = createNewGUIObject(elements[i]);
+// hbox.getChildren().addAll(label, elementToCreate.createNode());
+ vbox.getChildren().add(hbox);
+ }
+ return vbox;
+ }
+
+// private IGUIElement createNewGUIObject(String nodeType) {
+// if (isTextField(nodeType)) {
+// return createTextField(nodeType);
+// } else if (isComboBox(nodeType)) {
+// return createComboBox(nodeType);
+// }
+// return null;
+// }
+
+ private boolean isTextField(String nodeType) {
+ return Arrays.asList(myAttributesResources.getString(TEXTFIELD).split(",")).contains(nodeType);
+ }
+
+ private boolean isComboBox(String nodeType) {
+ return Arrays.asList(myAttributesResources.getString(COMBOBOXES).split(",")).contains(nodeType);
+ }
+
+// private IGUIElement createTextField(String nodeType) {
+// IGUIElement textField = new TextFieldWithButton("", TEST, TEXTFIELD_WIDTH, GO, null);
+// return textField;
+// }
+
+// private IGUIElement createComboBox(String nodeType) {
+// String options = myAttributesResources.getString(nodeType + OPTIONS);
+// List optionsList = Arrays.asList(options.split(DELIMITER));
+// return (IGUIElement) new ComboBoxOptions(myAttributesResources,PROMPT,optionsList);
+// }
+}
diff --git a/src/voogasalad/TabAttributesTest.java b/src/voogasalad/TabAttributesTest.java
new file mode 100644
index 0000000..e1fa41f
--- /dev/null
+++ b/src/voogasalad/TabAttributesTest.java
@@ -0,0 +1,22 @@
+package voogasalad;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+
+public class TabAttributesTest {
+ private TabAttributes ta = null;
+ private String rbValidBaseBundle;
+
+ @Test
+ public void testHandleInvalidBaseBundle() {
+ rbValidBaseBundle = "validbasegiven";
+ ta = new TabAttributes("tabTest", rbValidBaseBundle);
+ assertEquals("validbasegiven", ta.getResourcesBundleBaseName());
+ ta = new TabAttributes("tabTest", "randomword");
+ assertEquals("invalidbasegiven", ta.getResourcesBundleBaseName());
+
+ }
+
+}
diff --git a/src/voogasalad/ToDo.java b/src/voogasalad/ToDo.java
new file mode 100644
index 0000000..393cea0
--- /dev/null
+++ b/src/voogasalad/ToDo.java
@@ -0,0 +1,27 @@
+package voogasalad;
+
+import java.util.ResourceBundle;
+
+public class ToDo {
+ private static final String DEFAULT_BASE = "invalidbasegiven";
+ private ResourceBundle myAttributesResources;
+ private String bundleBase;
+
+ public ToDo(String bundleBase) {
+ this.bundleBase = bundleBase;
+ setResources();
+ }
+
+ private void setResources(){
+ try{
+ this.myAttributesResources = ResourceBundle.getBundle(bundleBase);
+ }catch(Exception e){
+ this.myAttributesResources = ResourceBundle.getBundle(DEFAULT_BASE);
+ }
+ }
+
+ public String getResourcesBundleBaseName(){
+ return myAttributesResources.getBaseBundleName();
+ }
+
+}
diff --git a/src/voogasalad/ToDoTest.java b/src/voogasalad/ToDoTest.java
new file mode 100644
index 0000000..45f4f08
--- /dev/null
+++ b/src/voogasalad/ToDoTest.java
@@ -0,0 +1,21 @@
+package voogasalad;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ToDoTest {
+ private ToDo td = null;
+ private String rbValidBaseBundle;
+
+ @Test
+ public void testHandleInvalidBaseBundle() {
+ rbValidBaseBundle = "validbasegiven";
+ td = new ToDo(rbValidBaseBundle);
+ assertEquals("validbasegiven", td.getResourcesBundleBaseName());
+ td = new ToDo("randomword");
+ assertEquals("invalidbasegiven", td.getResourcesBundleBaseName());
+
+ }
+
+}