Code example for Map

Methods: containsKey, get, isEmpty, put

0
			{ 
				final String _openUDID = reply.readString();
				if (_openUDID != null) { //if valid OpenUDID, save it
					if (LOG) Log.d(TAG, "Received " + _openUDID);
 
					if (mReceivedOpenUDIDs.containsKey(_openUDID)) mReceivedOpenUDIDs.put(_openUDID, mReceivedOpenUDIDs.get(_openUDID) + 1);
					else mReceivedOpenUDIDs.put(_openUDID, 1);
						 
				} 
			} 
		} catch (RemoteException e) {if (LOG) Log.e(TAG, "RemoteException: " + e.getMessage());}		    	    			
		mContext.unbindService(this);
		 
		startService(); //Try the next one 
  	} 
	 
	@Override 
	public void onServiceDisconnected(ComponentName className) {}
	 
	private void storeOpenUDID() { 
    	final Editor e = mPreferences.edit();
		e.putString(PREF_KEY, OpenUDID);
		e.commit();
	} 
	 
	/* 
	 * Generate a new OpenUDID 
	 */ 
	private void generateOpenUDID() { 
		if (LOG) Log.d(TAG, "Generating openUDID");
		//Try to get the ANDROID_ID 
		OpenUDID = Secure.getString(mContext.getContentResolver(), Secure.ANDROID_ID); 
		if (OpenUDID == null || OpenUDID.equals("9774d56d682e549c") || OpenUDID.length() < 15 ) {
			//if ANDROID_ID is null, or it's equals to the GalaxyTab generic ANDROID_ID or bad, generates a new one 
			final SecureRandom random = new SecureRandom();
			OpenUDID = new BigInteger(64, random).toString(16);
		} 
    } 
	 
	 
	/* 
	 * Start the oldest service 
	 */ 
	private void startService() { 
		if (mMatchingIntents.size() > 0) { //There are some Intents untested
			if (LOG) Log.d(TAG, "Trying service " + mMatchingIntents.get(0).loadLabel(mContext.getPackageManager()));
		 
			final ServiceInfo servInfo = mMatchingIntents.get(0).serviceInfo;
            final Intent i = new Intent();
            i.setComponent(new ComponentName(servInfo.applicationInfo.packageName, servInfo.name));
            mContext.bindService(i, this,  Context.BIND_AUTO_CREATE);
            mMatchingIntents.remove(0);
		} else { //No more service to test 
			 
			getMostFrequentOpenUDID(); //Choose the most frequent 
	 
			if (OpenUDID == null) //No OpenUDID was chosen, generate one			
				generateOpenUDID(); 
			if (LOG) Log.d(TAG, "OpenUDID: " + OpenUDID);
 
			storeOpenUDID();//Store it locally 
			mInitialized = true;
		} 
	} 
	 
	private void getMostFrequentOpenUDID() { 
		if (mReceivedOpenUDIDs.isEmpty() == false) {
			final TreeMap<String,Integer> sorted_OpenUDIDS = new TreeMap(new ValueComparator());
			sorted_OpenUDIDS.putAll(mReceivedOpenUDIDs);
         
			OpenUDID = sorted_OpenUDIDS.firstKey();
		}