|
@@ -1,6 +1,11 @@
|
|
|
package ui.controller;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.Map.Entry;
|
|
|
+
|
|
|
+import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
|
|
|
|
|
|
import classes.Category;
|
|
|
import classes.CpsObject;
|
|
@@ -16,7 +21,7 @@ public class SearchController {
|
|
|
this.MODEL = model;
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* search for category
|
|
|
*
|
|
@@ -25,14 +30,20 @@ public class SearchController {
|
|
|
*/
|
|
|
public Category searchCategory(String category) {
|
|
|
|
|
|
- for (Category cat : MODEL.getCategories()) {
|
|
|
- if (cat.getName().equals(category)) {
|
|
|
- return cat;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
+ // for (Category cat : MODEL.getCategories()) {
|
|
|
+ // if (cat.getName().equals(category)) {
|
|
|
+ // return cat;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return null;
|
|
|
+ Integer idx;
|
|
|
+
|
|
|
+ if ((idx = MODEL.getCgIdx().get(category)) != null)
|
|
|
+ return MODEL.getCategories().get(idx);
|
|
|
+ else
|
|
|
+ return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Search for Object
|
|
|
*
|
|
@@ -40,12 +51,18 @@ public class SearchController {
|
|
|
* @param list
|
|
|
* @return
|
|
|
*/
|
|
|
- public CpsObject searchHolonObject(String object, ArrayList<CpsObject> list) {
|
|
|
- for (CpsObject objects : list) {
|
|
|
- if (objects.getObjName().equals(object))
|
|
|
- return objects;
|
|
|
- }
|
|
|
- return null;
|
|
|
+ public CpsObject searchCategoryObject(Category category, String object) {
|
|
|
+ // for (CpsObject objects : list) {
|
|
|
+ // if (objects.getObjName().equals(object))
|
|
|
+ // return objects;
|
|
|
+ // }
|
|
|
+ // return null;
|
|
|
+ Integer idx;
|
|
|
+
|
|
|
+ if ((idx = category.getObjIdx().get(object)) != null)
|
|
|
+ return category.getObjects().get(idx);
|
|
|
+ else
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -56,11 +73,17 @@ public class SearchController {
|
|
|
* @return
|
|
|
*/
|
|
|
public CpsObject searchByID(int ID) {
|
|
|
- for (CpsObject objects : MODEL.getObjectsOnCanvas()) {
|
|
|
- if (objects.getID() == ID)
|
|
|
- return objects;
|
|
|
- }
|
|
|
- return null;
|
|
|
+ // for (CpsObject objects : MODEL.getObjectsOnCanvas()) {
|
|
|
+ // if (objects.getID() == ID)
|
|
|
+ // return objects;
|
|
|
+ // }
|
|
|
+ // return null;
|
|
|
+ Integer idx;
|
|
|
+
|
|
|
+ if ((idx = MODEL.getCvsObjIdx().get(ID)) != null)
|
|
|
+ return MODEL.getObjectsOnCanvas().get(idx);
|
|
|
+ else
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -81,4 +104,37 @@ public class SearchController {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Decrement the Indices if a Key as been removed
|
|
|
+ *
|
|
|
+ * @param key
|
|
|
+ * @param map
|
|
|
+ */
|
|
|
+ public <T> void decIdx(T key, HashMap<T, Integer> map) {
|
|
|
+
|
|
|
+ for (Entry<T, Integer> i : map.entrySet()) {
|
|
|
+ if (i.getValue() > map.get(key))
|
|
|
+ i.setValue(i.getValue() - 1);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> ArrayList<T> copyArrayList(ArrayList<T> arr) {
|
|
|
+ ArrayList<T> newArr = new ArrayList<>();
|
|
|
+ for (T t : arr) {
|
|
|
+ newArr.add(t);
|
|
|
+ }
|
|
|
+ return newArr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T,Integer> HashMap<T, Integer> copyHashMap(HashMap<T, Integer> map) {
|
|
|
+
|
|
|
+ HashMap<T, Integer> newMap = new HashMap<>();
|
|
|
+ for (Entry<T, Integer> i : map.entrySet()) {
|
|
|
+ newMap.put(i.getKey(), i.getValue());
|
|
|
+ }
|
|
|
+ return newMap;
|
|
|
+ }
|
|
|
+
|
|
|
}
|