package huyifei.mymvp.test;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.HashMap;

import huyifei.mymvp.R;

public class HashMapActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "HashMapActivity";
    private HashMap<String, String> mHashMap;


    private EditText mKey, mValue;
    private TextView mResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hash_map);

        mHashMap = new HashMap<>();

        int hash = "name".hashCode() ^ "name".hashCode() >>> 16;

        Log.e(TAG, "onCreate: hash=" + hash);

        mHashMap.put("name", "mike");

        Button mPut = findViewById(R.id.put);
        mPut.setOnClickListener(this);
        Button mGet = findViewById(R.id.get);
        mGet.setOnClickListener(this);
        Button mRemove = findViewById(R.id.remove);
        mRemove.setOnClickListener(this);
        mKey = findViewById(R.id.key);
        mValue = findViewById(R.id.value);
        mResult = findViewById(R.id.result);

    }

    @Override
    public void onClick(View view) {
        String result;
        String key = mKey.getText().toString().trim();
        String value = mValue.getText().toString().trim();
        switch (view.getId()) {
            case R.id.put:
                if (!TextUtils.isEmpty(key) && !TextUtils.isEmpty(value)) {
                    mHashMap.put(key, value);
                }
                break;
            case R.id.get:
                key = mKey.getText().toString().trim();
                result = mHashMap.get(key);
                mResult.setText(result);
                break;
            case R.id.remove:
                result = mHashMap.remove(key);
                Toast.makeText(this, result + " has been removed !", Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }
    }
}

@@ -132,33 +132,8 @@
 ls;%0A
-import android.util.Log;%0A
 impo
@@ -799,159 +799,8 @@
 );%0A%0A
-        int hash = %22name%22.hashCode() %5E %22name%22.hashCode() %3E%3E%3E 16;%0A%0A        Log.e(TAG, %22onCreate: hash=%22 + hash);%0A%0A        mHashMap.put(%22name%22, %22mike%22);%0A
 %0A   
@@ -1652,48 +1652,40 @@
     
-key = mKey.getText().toString().trim();%0A
+if (!TextUtils.isEmpty(key)) %7B%0A 
     
@@ -1688,32 +1688,35 @@
                 
+   
 result = mHashMa
@@ -1723,24 +1723,28 @@
 p.get(key);%0A
+    
             
@@ -1768,24 +1768,43 @@
 xt(result);%0A
+                %7D%0A%0A
             
@@ -1844,16 +1844,67 @@
 remove:%0A
+                if (!TextUtils.isEmpty(key)) %7B%0A    
         
@@ -1938,24 +1938,28 @@
 emove(key);%0A
+    
             
@@ -2039,24 +2039,42 @@
 RT).show();%0A
+                %7D%0A
             

update hashmap activity