<commit_before>package us.semanter.app.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.HashSet;
import java.util.Set;

import us.semanter.app.R;
import us.semanter.app.model.Tag;

public class TagView extends LinearLayout implements TagEditor.TagListener {
    private Context context;
    private LinearLayout tagLayout;
    private TagEditor editorView;

    private Set<Tag> tags;

    public TagView(Context context, AttributeSet attrs) {
        super(context, attrs);

        this.context = context;

        // UI

        setOrientation(LinearLayout.HORIZONTAL);

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_tag, this, true);

        tagLayout = (LinearLayout)findViewById(R.id.tag_selector_scroll_layout);
        editorView = (TagEditor)findViewById(R.id.tag_editor_text);
        editorView.registerListener(this);

        // Data

        tags = new HashSet<Tag>();
    }

    public TagView(Context context) {
        this(context, null);
    }

    private void addTag(Tag t) throws TagExistsException {
        // ui
        LayoutInflater inflater = LayoutInflater.from(context);
        Button button = (Button) inflater.inflate(R.layout.tag, null, false);

        button.setText(t.getValue());
        tagLayout.addView(button, 0);

        // data
        if(!tags.add(t))
            throw new TagExistsException();
    }

    public void onNewTag(Tag newTag) {
        Log.d("TagView", newTag.getValue());

        try {
            addTag(newTag);
        } catch(TagExistsException e) {
            Toast.makeText(context, "tag already added", Toast.LENGTH_SHORT);
        }
    }

    public Set getTags() {
        return tags;
    }
<commit_msg>Remove tags by clicking them.<commit_after>package us.semanter.app.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import us.semanter.app.R;
import us.semanter.app.model.Tag;

public class TagView extends LinearLayout implements TagEditor.TagListener {
    private Context context;
    private LinearLayout tagLayout;
    private TagEditor editorView;

    private Set<Tag> tags;
    private Map<Tag, Button> tagButtons;

    public TagView(Context context, AttributeSet attrs) {
        super(context, attrs);

        this.context = context;

        // UI

        setOrientation(LinearLayout.HORIZONTAL);

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_tag, this, true);

        tagLayout = (LinearLayout)findViewById(R.id.tag_selector_scroll_layout);
        editorView = (TagEditor)findViewById(R.id.tag_editor_text);
        editorView.registerListener(this);

        // Data

        tags = new HashSet<Tag>();
        tagButtons = new HashMap<Tag, Button>();
    }

    public TagView(Context context) {
        this(context, null);
    }

    private void addTag(final Tag tag) throws TagExistsException {
        // ui
        LayoutInflater inflater = LayoutInflater.from(context);
        Button button = (Button) inflater.inflate(R.layout.tag, null, false);

        button.setText(tag.getValue());
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                removeTag(tag);
            }
        });

        tagLayout.addView(button, 0);

        // data
        tagButtons.put(tag, button);
        if(!tags.add(tag))
            throw new TagExistsException();
    }

    private synchronized void removeTag(Tag tag) {
        tags.remove(tag);
        tagLayout.removeView(tagButtons.get(tag));
    }

    public void onNewTag(Tag newTag) {
        Log.d("TagView", newTag.getValue());

        try {
            addTag(newTag);
        } catch(TagExistsException e) {
            Toast.makeText(context, "tag already added", Toast.LENGTH_SHORT);
        }
    }

    public Set getTags() {
        return tags;
    }

{'fraction_non_alphanumeric': 0.10213986322523715, 'fraction_numerical': 0.00044120891242003087, 'mean_word_length': 2.704248366013072, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2273082', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1266, 'n_words': 276}