Code example for AbstractMap.SimpleEntry

Methods: getKey, getValue

0
	{ 
		boolean bRet = false;
		try 
		{ 
			setSetting(new SimpleEntry("CurrentCategory", DEFAULT_CATEGORY));
			setSetting(new SimpleEntry("CurrentCountry", DEFAULT_COUNTRY));
			setSetting(new SimpleEntry("JavaScriptEnabled", DEFAULT_JAVASCRIPT_VALUE));
			bRet = true;
		} 
		catch (Exception e)
		{ 
			bRet = false;
		} 
		return bRet;
	} //addDefaultSettings() 
	 
	public boolean setSetting(String key, String value)
	{ 
		SimpleEntry<String, String> setting = new SimpleEntry<String, String>(key, value);
		return setSetting(setting);
	} //addSetting() 
	 
	public boolean setSetting(SimpleEntry<String, String> setting)
	{ 
		boolean bRet = false;
		try 
		{ 
			if (setting==null || !isDbOpen())
				return false; 
			 
			// Try and get the setting from the database (if exists). 
			String whereClause = "Name=?";
			String[] whereArgs = new String[] {
					setting.getValue()
			}; 
			Cursor cursor = mSqliteDb.query(SETTINGS_TABLE_NAME, null, 
					whereClause, whereArgs, null, null, null);
			 
			if (cursor!=null && cursor.getCount()>0 && cursor.moveToFirst())
			{ 
				ContentValues values = new ContentValues();
				values.put(setting.getKey(), setting.getValue());
				mSqliteDb.update(SETTINGS_TABLE_NAME, values, whereClause, whereArgs);
			} 
			else 
			{ 
				String sql =   "INSERT INTO " + SETTINGS_TABLE_NAME + 
						" (Name, Value) " + 
						"VALUES ('" + setting.getKey() + "', '" + 
						setting.getValue() + "');";
				mSqliteDb.execSQL(sql);
			} 
			 
			bRet = true;
		}