<commit_before>package de.avalax.fitbuddy.app.manageWorkout;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import de.avalax.fitbuddy.app.R;
import de.avalax.fitbuddy.core.workout.Exercise;
import de.avalax.fitbuddy.core.workout.Workout;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class WorkoutAdapter extends ArrayAdapter<Exercise> {
    private final List<Exercise> exercises;
    DecimalFormat decimalFormat;

    public static WorkoutAdapter newInstance(Context context, int textViewResourceId, Workout workout) {
        List<Exercise> items = new ArrayList<>();
        for (int i = 0; i < workout.getExerciseCount(); i++) {
            items.add(workout.getExercise(i));
        }
        return new WorkoutAdapter(context, textViewResourceId, items);
    }

    public WorkoutAdapter(Context context, int textViewResourceId, List<Exercise> exercises) {
        super(context, textViewResourceId, exercises);
        this.exercises = exercises;
        this.decimalFormat = new DecimalFormat("###.#");
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);
        }

        Exercise exercise = exercises.get(position);
        TextView name = (TextView) v.findViewById(R.id.toptext);
        TextView weight = (TextView) v.findViewById(R.id.weightTextView);
        TextView reps = (TextView) v.findViewById(R.id.repsTextView);
        TextView sets = (TextView) v.findViewById(R.id.setsTextView);
        ImageView iv = (ImageView) v.findViewById(R.id.buttonOverflow);

        name.setText(exercise.getName());
        weight.setText(getWeightText(exercise.getWeight()));
        reps.setText(String.valueOf(exercise.getMaxReps()));
        sets.setText(String.valueOf(exercise.getMaxSets()));
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.showContextMenu();
            }
        });
        return v;
    }

    private CharSequence getWeightText(double weight) {
        if (weight > 0) {
            return decimalFormat.format(weight);
        } else {
            return "-";
        }
    }
}<commit_msg>using a ViewHolder to increase performance<commit_after>package de.avalax.fitbuddy.app.manageWorkout;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import de.avalax.fitbuddy.app.R;
import de.avalax.fitbuddy.core.workout.Exercise;
import de.avalax.fitbuddy.core.workout.Workout;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class WorkoutAdapter extends ArrayAdapter<Exercise> {
    private final List<Exercise> exercises;
    DecimalFormat decimalFormat;

    public static WorkoutAdapter newInstance(Context context, int textViewResourceId, Workout workout) {
        List<Exercise> items = new ArrayList<>();
        for (int i = 0; i < workout.getExerciseCount(); i++) {
            items.add(workout.getExercise(i));
        }
        return new WorkoutAdapter(context, textViewResourceId, items);
    }

    public WorkoutAdapter(Context context, int textViewResourceId, List<Exercise> exercises) {
        super(context, textViewResourceId, exercises);
        this.exercises = exercises;
        this.decimalFormat = new DecimalFormat("###.#");
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = vi.inflate(R.layout.row, null);
            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.toptext);
            holder.weight = (TextView) convertView.findViewById(R.id.weightTextView);
            holder.reps = (TextView) convertView.findViewById(R.id.repsTextView);
            holder.sets = (TextView) convertView.findViewById(R.id.setsTextView);
            holder.iv = (ImageView) convertView.findViewById(R.id.buttonOverflow);
            holder.iv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    v.showContextMenu();
                }
            });
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Exercise exercise = exercises.get(position);
        holder.name.setText(exercise.getName());
        holder.weight.setText(getWeightText(exercise.getWeight()));
        holder.reps.setText(String.valueOf(exercise.getMaxReps()));
        holder.sets.setText(String.valueOf(exercise.getMaxSets()));
        return convertView;
    }

    private CharSequence getWeightText(double weight) {
        if (weight > 0) {
            return decimalFormat.format(weight);
        } else {
            return "-";
        }
    }

    private static class ViewHolder {
        public TextView name;
        public TextView weight;
        public TextView sets;
        public TextView reps;
        public ImageView iv;
    }
}
{'fraction_non_alphanumeric': 0.10595217315412812, 'fraction_numerical': 0.0006982021295164951, 'mean_word_length': 2.9192886456908345, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7061522', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1536, 'n_words': 326}