<commit_before>package com.turlir.example;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

import com.turlir.breaklayout.BreakLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends Activity implements SettingsDialog.Callback {

    private static final int[] MODELS = new int[] {
            BreakLayout.MODE_RIGHT,
            BreakLayout.MODE_LEFT,
            BreakLayout.MODE_CENTER,
            BreakLayout.MODE_EDGE,
            BreakLayout.MODE_AS_IS,
    };

    private static final String BUNDLE_MODEL = "BUNDLE_MODEL";

    @BindView(R.id.target)
    BreakLayout target;

    @Override
    protected void onCreate(Bundle state) {
        super.onCreate(state);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        if (state != null) {
            newMode((Model) state.getParcelable(BUNDLE_MODEL));
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        Model m = new Model(target.getMode(), target.getChildCount());
        outState.putParcelable(BUNDLE_MODEL, m);
        super.onSaveInstanceState(outState);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.settings) {
            openSettingsDialog();
        }
        return false;
    }

    private void openSettingsDialog() {
        Model current = new Model(target.getMode(), target.getChildCount());
        SettingsDialog frg = SettingsDialog.newInstance(MODELS, current);
        frg.show(getFragmentManager(), null);
    }

    @Override
    public void newMode(Model n) {
        int m = n.getId();
        int c = n.getCount();
        // old algorithm
        int tmp = target.getMode();
        if (c > target.getChildCount()) {
            View childAt = target.getChildAt(0);
            for (int i = 0; i <= c - target.getChildCount(); i++) {
                View v = new View(getApplicationContext());
                v.setLayoutParams(childAt.getLayoutParams());
                v.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
                target.addView(v);
            }
        } else if (c < target.getChildCount()) {
            for (int i = target.getChildCount() - 1; i >= c; i--) {
                target.removeViewAt(i);
            }
        }
        if (tmp != m) {
            target.setMode(m);
        }
    }

}<commit_msg>Fix append, remove view algorithm, add comments<commit_after>package com.turlir.example;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

import com.turlir.breaklayout.BreakLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends Activity implements SettingsDialog.Callback {

    private static final int[] MODELS = new int[] {
            BreakLayout.MODE_RIGHT,
            BreakLayout.MODE_LEFT,
            BreakLayout.MODE_CENTER,
            BreakLayout.MODE_EDGE,
            BreakLayout.MODE_AS_IS,
    };

    private static final String BUNDLE_MODEL = "BUNDLE_MODEL";

    @BindView(R.id.target)
    BreakLayout target;

    @Override
    protected void onCreate(Bundle state) {
        super.onCreate(state);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        if (state != null) {
            newMode((Model) state.getParcelable(BUNDLE_MODEL));
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        Model m = new Model(target.getMode(), target.getChildCount());
        outState.putParcelable(BUNDLE_MODEL, m);
        super.onSaveInstanceState(outState);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.settings) {
            openSettingsDialog();
        }
        return false;
    }

    private void openSettingsDialog() {
        Model current = new Model(target.getMode(), target.getChildCount());
        SettingsDialog frg = SettingsDialog.newInstance(MODELS, current);
        frg.show(getFragmentManager(), null);
    }

    @Override
    public void newMode(Model m) {
        int c = m.getCount();
        if (c > target.getChildCount()) { // add
            View childAt = target.getChildAt(0);
            int diff = c - target.getChildCount();
            for (int i = 0; i < diff; ++i) {
                View v = new View(getApplicationContext());
                v.setLayoutParams(childAt.getLayoutParams());
                v.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
                target.addView(v);
            }
        } else if (c < target.getChildCount()) { // remove
            int diff = target.getChildCount() - c;
            for (int i = 0; i < diff; ++i) {
                target.removeViewAt((diff + c) - i - 1); // from end
            }
        }
        // else count not change - nothing
        // mode change independent
        if (target.getMode() != m.getId()) {
            target.setMode(m.getId());
        }
    }

}
{'fraction_non_alphanumeric': 0.10883753748456518, 'fraction_numerical': 0.0012347856764861529, 'mean_word_length': 2.30034924330617, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, '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': '4935518', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1608, 'n_words': 349}