summaryrefslogtreecommitdiffstats
path: root/helper/ListBTS.java
diff options
context:
space:
mode:
Diffstat (limited to 'helper/ListBTS.java')
-rw-r--r--helper/ListBTS.java300
1 files changed, 300 insertions, 0 deletions
diff --git a/helper/ListBTS.java b/helper/ListBTS.java
new file mode 100644
index 0000000..dac45b0
--- /dev/null
+++ b/helper/ListBTS.java
@@ -0,0 +1,300 @@
+package helper;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+import DataStructure.SingleBTS;
+
+public class ListBTS {
+
+ /**
+ *
+ * @param list
+ * Where to search
+ * @param arfcn
+ * which BTS to search
+ * @return false if BTS not found or list or arfcn is null or empty. True if
+ * BTS is found
+ */
+ public static boolean contains(List<SingleBTS> list, SingleBTS arfcn) {
+ return contains(list, arfcn.ARFCN);
+ }
+
+ public static boolean contains(List<SingleBTS> list, int arfcn) {
+ if (list == null || list.isEmpty()) {
+ return false;
+ }
+ if (list instanceof LinkedList<?>) {
+ ListIterator<SingleBTS> itr = list.listIterator();
+ while (itr.hasNext()) {
+ SingleBTS element = itr.next();
+ if (element.ARFCN == arfcn)
+ return true;
+ }
+ } else {
+ for (int i = list.size() - 1; i >= 0; i--) {
+ if (list.get(i).ARFCN == arfcn) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public static boolean containsUL(List<SingleBTS> list, SingleBTS arfcn) {
+ for (SingleBTS current : list) {
+ if (current.ARFCN == arfcn.ARFCN && current.fullBTS)
+ return true;
+ }
+ return false;
+ }
+
+ public static int countDL(LinkedList<SingleBTS> list, SingleBTS arfcn) {
+ int count = 0;
+ for (SingleBTS current : list) {
+ if (current != null && current.ARFCN == arfcn.ARFCN)
+ count++;
+ }
+ return count;
+ }
+
+ public static int countUL(LinkedList<SingleBTS> list, SingleBTS arfcn) {
+ int count = 0;
+ for (SingleBTS current : list) {
+ if (current != null && current.fullBTS
+ && current.ARFCN == arfcn.ARFCN)
+ count++;
+ }
+ return count;
+ }
+
+ /**
+ * Searches the list for the _first_ BTS with same arfcn. Removes it from
+ * that list and returns the element
+ *
+ * @param list
+ * from which to search
+ * @param arfcn
+ * MR with ARFCN you search for
+ * @return Element from list that got deleted. Null if element is not
+ * present in list
+ */
+ public static SingleBTS removeARFCN(List<SingleBTS> list, SingleBTS arfcn) {
+ return removeARFCN(list, arfcn.ARFCN);
+ }
+
+ public static SingleBTS removeARFCN(List<SingleBTS> list, int arfcn) {
+ ListIterator<SingleBTS> itr = list.listIterator();
+ while (itr.hasNext()) {
+ SingleBTS element = itr.next();
+ if (element.ARFCN == arfcn) {
+ itr.remove();
+ return element;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Gets the first occurence of the specified arfcn from the list. Element
+ * stays in list
+ *
+ * @param list
+ * the list from where to extract the BTS
+ * @param arfcn
+ * arfcn to extract
+ * @return first SingleBTS that matches from the list. Null if Element is
+ * not present
+ */
+ public static SingleBTS getARFCN(List<SingleBTS> list, SingleBTS arfcn) {
+ if (list == null || arfcn == null) {
+ return null;
+ }
+ for (int i = 0; i < list.size(); i++) {
+ if (list.get(i).ARFCN == arfcn.ARFCN) {
+ return list.get(i);
+ }
+ }
+ return null;
+ }
+
+ public static ArrayList<SingleBTS> getAllARFCN(ArrayList<SingleBTS> list,
+ int arfcn) {
+ if (list == null || list.isEmpty()) {
+ return null;
+ }
+ boolean aHitWasFound = false;
+ ArrayList<SingleBTS> result = new ArrayList<SingleBTS>();
+ for (int i = 0; i < list.size(); i++) {
+ if (list.get(i).ARFCN == arfcn) {
+ result.add(list.get(i));
+ aHitWasFound = true;
+ }
+ }
+ if (aHitWasFound)
+ return result;
+ else
+ return null;
+ }
+
+ /**
+ * Gets the first occurence of the specified arfcn from the list. Element
+ * stays in list
+ *
+ * @param list
+ * the list from where to extract the BTS
+ * @param arfcn
+ * arfcn to extract
+ * @return first SingleBTS that matches from the list. Null if Element is
+ * not present
+ */
+ public static SingleBTS getARFCN(List<SingleBTS> list, int arfcn) {
+ for (int i = 0; i < list.size(); i++) {
+ if (list.get(i).ARFCN == arfcn) {
+ return list.get(i);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Takes a list. Returns a copy of that list without null-elements
+ *
+ * @param list
+ * ListBTS where all elements with null will be filtered out
+ * @return a copy of this list without null-elements. Null if the whole list
+ * is null
+ */
+ public static ArrayList<SingleBTS> removeNullElements(List<SingleBTS> list) {
+ if (list == null)
+ return null;
+ ArrayList<SingleBTS> list2 = new ArrayList<SingleBTS>();
+ boolean element_present = false;
+ for (SingleBTS element : list) {
+ if (element != null) {
+ element_present = true;
+ list2.add(element);
+ }
+ }
+ if (element_present)
+ return list2;
+ else
+ return null;
+ }
+
+ /**
+ * ListBTS all the unique SingleBTS's that occur in this list
+ *
+ * @param list
+ * ListBTS with SingleBTS's
+ * @return Array with the unique SingleBTS's. That is, every BTS in this
+ * Array occurs also in the list. Null if the list was empty
+ */
+ public static SingleBTS[] content(List<SingleBTS> list) {
+ // get first element of list.
+ // traverse list and delete every occurence of first element
+ // get next element
+ // copy list to destroy reference
+ LinkedList<SingleBTS> list2 = new LinkedList<SingleBTS>(list);
+ if (list2.isEmpty())
+ return null;
+ // int count = 0;
+ LinkedList<SingleBTS> output = new LinkedList<SingleBTS>();
+ while (!list2.isEmpty()) {
+ SingleBTS bts = list2.getFirst();
+ list2.removeFirst();
+ output.add(bts);
+ // remove the just added bts from the BTS-list
+ // speedup with listiterator
+ /*
+ * for (int i = 0; i < list2.size(); i++) { if (list2.get(i).ARFCN
+ * == bts.ARFCN) { list2.remove(i); i--; }
+ */
+ ListIterator<SingleBTS> itr = list2.listIterator();
+ SingleBTS testelement;
+ while (itr.hasNext()) {
+ testelement = itr.next();
+ if (testelement.ARFCN == bts.ARFCN) {
+ // same element found. Delete it
+ itr.remove();
+ // if we are on the first element, itr.previous will throw
+ // an exception. Just ignore it and go on
+ try {
+ itr.previous();
+ } catch (Exception e) {
+
+ }
+ }
+
+ }
+
+ }
+ return output.toArray(new SingleBTS[1]);
+ }
+
+ /**
+ * Takes two lists. Merges missing parameters. Interpolated BTS will be
+ * overwritten by real measurements. NOT IMPLEMENTED!!!!
+ *
+ * @param list1
+ * @param list2
+ * @return
+ */
+ public static LinkedList<SingleBTS> addMissing(LinkedList<SingleBTS> list1,
+ LinkedList<SingleBTS> list2) {
+ // LinkedList<SingleBTS> result = new LinkedList<SingleBTS>();
+ if ((list1 == null && list2 != null)) {
+ return list2;
+ }
+ if (list1 != null && list2 == null) {
+ return list1;
+ }
+ if (list1.isEmpty() && !list2.isEmpty()) {
+ return list2;
+ }
+ if (!list1.isEmpty() && list2.isEmpty()) {
+ return list1;
+ }
+
+ // for (SingleBTS element1 : list1) {
+ // for (SingleBTS element2 : list2) {
+ // TODO: Code here!
+ // }
+ // }
+ return null;
+ }
+
+ /**
+ * Takes all BTS with same arfcn and adds the Measurements together
+ *
+ * @param List
+ * @param content
+ * @return
+ */
+ public static ArrayList<SingleBTS> generateAveragedList(
+ ArrayList<SingleBTS> List, SingleBTS[] content) {
+ ArrayList<SingleBTS> output = new ArrayList<SingleBTS>();
+ // traverse every unique BTS
+ for (SingleBTS singleBTS : content) {
+ // initialize with ARFCN and Name
+ SingleBTS current = new SingleBTS(singleBTS.ARFCN, singleBTS.name);
+ // add everything from list. SingleBTS-Class takes only correct BTSs
+ for (SingleBTS measure : List) {
+ current.addBTSMeasure(measure);
+ }
+ output.add(current);
+ }
+
+ return output;
+ }
+
+ public static ArrayList<SingleBTS> generateAveragedList(
+ ArrayList<SingleBTS> List) {
+ SingleBTS[] content = content(List);
+ return generateAveragedList(List, content);
+ }
+
+}