@SuppressWarnings("unchecked")
	@Override
	public int measurementSimilarityLevel(org.redpin.base.core.Measurement t,
			org.redpin.base.core.Measurement o) {
		
		Location mloc = null;
		if(debug) {
			Fingerprint tf = fingerprintHome.getByMeasurementId(((Measurement)t).getId());
					
			if(tf != null) {
				mloc = (Location) tf.getLocation();
			}
			
			if(mloc != null) {
				log.log(loglevel, "Calculating similarity Level between current measurement and " + mloc.getMap().getMapName() + mloc.getSymbolicID());
			} else {
				log.log(loglevel, "Calculating similarity Level between current Measurements and #" + ((Measurement)t).getId());
			}
		} else {
			log.log(loglevel, "Calculating similarity Level between current Measurements and #" + ((Measurement)t).getId());
		}
		

		/* total amount of credit that can be achieved */
		double totalCredit = 0;

		/* account that holds the achieved credit */
		double account = 0;

		/* counts the nr of positive matches of reading ID's */
		int matches;

		/*log.log(loglevel, "WiFi ID penalty: (" + readings + " read - "
		 * holds the max nr of measured readings. max of reference measurement
		 * and current measurement
		 */
		int readings;
		
		
		java.util.Vector<WiFiReading> this_vect = t.getWiFiReadings();
		java.util.Vector<WiFiReading> other_vect = o.getWiFiReadings();
		
		/* check WiFiReadings */
		//Vector wifiReadings1 = this.wifiReadings;
		//Vector wifiReadings2 = m.getWiFiReadings();
		
		matches = 0;
		
		for (int i = 0; i < this_vect.size(); i++) {
			WiFiReading this_wifi = this_vect.elementAt(i);
			for (int j = 0; j < other_vect.size(); j++) {
				WiFiReading other_wifi = other_vect.elementAt(j);

				/*
				 * bssid match: add ID contribution and signal strength
				 * contribution
				 */
				if (this_wifi != null && this_wifi.getBssid() != null && other_wifi != null && other_wifi.getBssid() != null && 
						this_wifi.getBssid().equals(other_wifi.getBssid())) {
					
					//log.log(loglevel, "WiFi + ID + SC");
					
					account += ID_POS_CONTRIBUTION;
					account += signalContribution(this_wifi.getRssi(), other_wifi.getRssi());
					matches++;
				}
			}
		}

		/*
		 * penalty if for each net that did not match
		 */
		readings = Math.max(this_vect.size(), other_vect.size());
		account += (readings - matches) * ID_NEG_CONTRIBUTION;
		
		log.log(loglevel, "WiFi ID penalty: (" + readings + " read - "
					+ matches + " matches) * "
					+ ID_NEG_CONTRIBUTION + " = "
					+ (readings - matches)
					* ID_NEG_CONTRIBUTION);
		
		/*
		 * get the total credit for this measurement.
		 */
		totalCredit += this_vect.size()
				* ID_POS_CONTRIBUTION;
		
		totalCredit += this_vect.size()
				* SIGNAL_CONTRIBUTION;
		

		/* get accuracy level defined by bounds */
		int factor = LOCATION_KNOWN	- LOCATION_UNKNOWN;

		/* a negative account results immediately in accuracy equals zero */
		int accuracy = 0;
		if (account > 0) {
			/*
			 * compute percentage of account from totalCredit -> [0,1]; stretch
			 * by accuracy span -> [0,MAX]; and in case min accuracy would not
			 * be zero, add this offset
			 */
			double a = (account / totalCredit) * factor
					+ LOCATION_UNKNOWN;

			/* same as Math.round */
			accuracy = (int) Math.floor(a + 0.5d);
		}
		String logmsg = "Comparing measurements..."
			+ "\n" + "-> Testing Measur: " + ( mloc == null ? ((Measurement)t).getId() : mloc.getMap().getMapName() + mloc.getSymbolicID())
			+ "\n" + "-> Credit achieved: " + account
			+ "\n" + "-> Total Credit possible: " + totalCredit
			+ "\n" + "-> Accuracy achieved: " + accuracy;
		log.log(loglevel, logmsg);
		

		return accuracy;
	}