package lookup; import helper.ListGPS; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import DataStructure.GPScoordinate; import DataStructure.GSMMap; import DataStructure.SingleBTS; /** * No longer used! * * @author richy * */ public class BTSLut implements ILut { private LinkedList[] possible_coords_DL = new LinkedList[69]; private LinkedList[] possible_coords_UL = new LinkedList[69]; public int bts; // which bts does this Object store public int threshold_dB; public int threshold_m; /** * create empty LUT * * @param ARFCN * set BTS-ARFCN this object will take measurements and requests */ public BTSLut(int ARFCN, int threshold_dB, int threshold_m) { this.bts = ARFCN; this.threshold_dB = threshold_dB; this.threshold_m = threshold_m; // initialize strength array: -47 ... -115 for (int i = 0; i < 69; i++) { possible_coords_DL[i] = new LinkedList(); possible_coords_UL[i] = new LinkedList(); } } public BTSLut(int ARFCN, GSMMap map, int threshold, int threshold_m) { this.bts = ARFCN; this.threshold_dB = threshold; this.threshold_m = threshold_m; for (int i = 0; i < 69; i++) { possible_coords_DL[i] = new LinkedList(); possible_coords_UL[i] = new LinkedList(); } // fill the LUT for (int x = 0; x < map.Xcoords.length; x++) { for (int y = 0; y < map.Ycoords.length; y++) { fill(map.getCoord(x, y), map.map[x][y]); } } } @Override public LinkedList get(SingleBTS MR) { // hier muss noch das threshold_dB berücksichtigt werden! if (MR == null) return null; LinkedList result = new LinkedList(); for (int i = threshold_dB * (-1); i <= threshold_dB; i++) { try { if (MR.fullBTS && MR.getDLcount() > 0) { // get coords for DL and UL and do a intersection // fix: do no intersection LinkedList listUL = new LinkedList(); LinkedList listDL = new LinkedList(); listUL = possible_coords_UL[getIndex(MR.getUldB() + threshold_dB)]; listDL = possible_coords_DL[getIndex(MR.getDldB() + threshold_dB)]; listUL = ListGPS.removeNullElements(listUL); listDL = ListGPS.removeNullElements(listDL); // result.addAll(helper.ListGPS.intersect(listDL, // listUL,threshold_m)); result.addAll(listUL); result.addAll(listDL); } else { result.addAll(possible_coords_DL[(getIndex(MR.getDldB() + threshold_dB))]); } } catch (Exception e) { // only index out of bound... ignore } } return result; } /** * Takes list. Returns the lookup. Result is the intersection between all * SingleBTSs in MR. That is, only Coordinates that are in common are * returned */ @SuppressWarnings("unused") public LinkedList get(List MR) { // create result list for each function call LinkedList list = new LinkedList(); // create a nested-linked-list in order to compute the intersection LinkedList> nestedlist = new LinkedList>(); // one list for all LinkedList resultset = new LinkedList(); ListIterator itr = MR.listIterator(); while (itr.hasNext()) { SingleBTS current = itr.next(); resultset.addAll(get(current)); } if (true) return resultset; for (SingleBTS current : MR) { // clear list list = new LinkedList(); // save results in that list. do that list into the list-list list.addAll(get(current)); list = ListGPS.removeNullElements(list); if (list != null && !list.isEmpty()) nestedlist.addLast(list); } // ------- // from here on only calculating intersect // ------- // reuse list. take it to store final result nestedlist = ListGPS.removeAllNullElements(nestedlist); if (list != null) list.clear(); if (nestedlist == null || nestedlist.isEmpty()) return null; if (nestedlist.size() == 1) return nestedlist.getFirst(); // nestedlist has at least 2 elements. do intersect with both. Store in // list. list.addAll(ListGPS.intersect(nestedlist.removeFirst(), nestedlist.removeLast(), threshold_m)); // now do intersect with the rest. This could get a speedup by using // pairwise intersection. would be O(log n) then. while (!nestedlist.isEmpty()) { list = ListGPS.intersect(list, nestedlist.removeFirst(), threshold_m); } // TODO: only null elements are here! return list; } /** * Returns index where the strength (dBm) is stored in the array * * @param strength * . Gets rounded * @return */ private int getIndex(double strength) { int rounded = (int) Math.round(strength); // this could be done with math.abs if (strength < 0) { return -47 - rounded; } else { return rounded - 47; } } @Override public void fill(GPScoordinate where, SingleBTS what) { if (what == null || what.ARFCN != bts) return; int hit = 0; if (what.getDldB() != 0) { hit = getIndex(what.getDldB()); possible_coords_DL[hit].add(where); } if (what.getUldB() != 0) { hit = getIndex(what.getUldB()); possible_coords_UL[hit].add(where); } } public void fill(GPScoordinate where, List what) { if (what == null) return; for (SingleBTS current : what) { fill(where, current); } } }