package edu.cmu.chimps.messageontap_api;

import android.content.Context;
import android.text.TextUtils;

import com.github.privacystreams.core.Item;
import com.github.privacystreams.utils.annotations.PSItemField;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.regex.Pattern;

public class Tag {
    public static final String TAG_ID = "tag_id";
    public static final String NAME = "name";
    public static final String KEYWORD_LIST = "keyword_list";
    public static final String ENTITY_NAME = "entity_name";

    private String mName;
    private String mEntityName;
    private ArrayList<String> mKeywordList;

    public Tag(String name, ArrayList<String> keywordList){
        this.mName = name;
        this.mKeywordList = keywordList;
    }

    public Tag(String name, String entityName){
        this.mName = name;
        this.mEntityName = entityName;
    }

    void setName(String name){
        mName = name;
    }

    String getName(){
        return mName;
    }

    void setKeywordList(ArrayList keywordList){
        mKeywordList = keywordList;
    }

    ArrayList<String> getKeywordList(){
        return mKeywordList;
    }

    void setEntityName(String entityName){
        this.mEntityName = entityName;
    }

    String getEntityName(){
        return mEntityName;
    }

    boolean matchRE(String word){

        ArrayList<String> keywordList = getKeywordList();
        boolean flag = false;

        for(String str: keywordList){
                if(Pattern.matches(str, word)){
                    flag = true;
                    break;
                };
            }
        return flag;
    }

    boolean matchEntity(String entity){
        return TextUtils.equals(entity, getEntityName());
    }

    public boolean matchWord(String word, String entity){
        if(getKeywordList()!=null)
            if(matchRE(word))
                return true;
        if(getEntityName() != null)
            if(getEntityName() != null && matchEntity(entity))
                return true;

        return false;
    }

}

@@ -708,32 +708,33 @@
 ng%3E keywordList)
+ 
 %7B%0A        this.m
@@ -832,32 +832,33 @@
 ring entityName)
+ 
 %7B%0A        this.m
@@ -941,24 +941,25 @@
 String name)
+ 
 %7B%0A        mN
@@ -993,24 +993,25 @@
 ng getName()
+ 
 %7B%0A        re
@@ -1067,32 +1067,33 @@
 ist keywordList)
+ 
 %7B%0A        mKeywo
@@ -1159,16 +1159,17 @@
 rdList()
+ 
 %7B%0A      
@@ -1239,16 +1239,17 @@
 ityName)
+ 
 %7B%0A      
@@ -1314,16 +1314,17 @@
 tyName()
+ 
 %7B%0A      
@@ -1384,18 +1384,18 @@
 ng word)
+ 
 %7B
-%0A
 %0A       
@@ -1448,38 +1448,8 @@
 t();
-%0A        boolean flag = false;
 %0A%0A  
@@ -1457,16 +1457,17 @@
      for
+ 
 (String 
@@ -1469,16 +1469,17 @@
 ring str
+ 
 : keywor
@@ -1484,16 +1484,17 @@
 ordList)
+ 
 %7B%0A      
@@ -1499,22 +1499,19 @@
         
- 
-   
 if
+ 
 (Pattern
@@ -1530,17 +1530,16 @@
 , word))
-%7B
 %0A       
@@ -1551,75 +1551,21 @@
     
-    flag = true;%0A                    break;%0A                %7D;%0A    
+return true;%0A
     
@@ -1590,11 +1590,12 @@
 rn f
-lag
+alse
 ;%0A  
@@ -1629,32 +1629,33 @@
 y(String entity)
+ 
 %7B%0A        return
@@ -1761,16 +1761,17 @@
  entity)
+ 
 %7B%0A      
@@ -1770,24 +1770,25 @@
 %7B%0A        if
+ 
 (getKeywordL
@@ -1792,18 +1792,20 @@
 rdList()
+ 
 !=
+ 
 null)%0A  
@@ -1816,16 +1816,17 @@
       if
+ 
 (matchRE
@@ -1864,32 +1864,33 @@
 true;%0A        if
+ 
 (getEntityName()
@@ -1913,16 +1913,17 @@
       if
+ 
 (getEnti

Update tag