<commit_before>package org.kleemann.diceprobabilities;

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

import org.apache.commons.math3.fraction.BigFraction;
import org.kleemann.diceprobabilities.distribution.ConstantDistribution;
import org.kleemann.diceprobabilities.distribution.DieDistribution;
import org.kleemann.diceprobabilities.distribution.Distribution;
import org.kleemann.diceprobabilities.distribution.MultinomialDistribution;
import org.kleemann.diceprobabilities.graph.GraphView;

import android.os.AsyncTask;
import android.os.Bundle;
import android.util.SparseIntArray;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * <p>This class contains the behavior for a set of pool dice, 
 * current dice, and result values. 
 */
public class DiceSet {

	public static class DieType {
		private int sides;
		private Button pool;
		private Button current;
		public DieType(int sides, Button pool, Button current) {
			this.sides = sides;
			this.pool = pool;
			this.current = current;
		}
		public int getSides() { return sides; }
		public Button getPool() { return pool; }
		public Button getCurrent() { return current; }
	}
	
	private CurrentDicePile[] dice;
	private CurrentDicePile target;
	
	private TextView answer_fraction;
	private TextView answer_probability;
	private GraphView.Setter graphSetter;
	
	// every time the dice are changed; this is incremented
	private long serial = 0;
	// true if the background distribution calculation is running
	private boolean running = false;

	private final DecimalFormat answerFormatter;
	private final int maxFractionChars;

	private static final String APPROXIMATELY_EQUAL_TO = "\u2245";
	private static final String GREATER_THAN_OR_EQUAL_TO = "\u2265"; 
	private static final String RIGHT_ARROW = "\u21e8"; 
	
	public DiceSet(
			DieType[] dieType,
			Button clear,
			TextView answer_fraction,
			TextView answer_probability,
			GraphView.Setter graphSetter
			) {
		
		this.answerFormatter = new DecimalFormat(clear.getResources().getString(R.string.answer_format));
		this.maxFractionChars = clear.getResources().getInteger(R.integer.max_fraction_chars); 
		
		CurrentDiceChanged diceChanged = new CurrentDiceChanged();
		dice = new CurrentDicePile[dieType.length-1]; // don't allocate space for the target
		int j=0;
		for (int i=0 ; i<dieType.length ; ++i) {
			DieType dt = dieType[i];
			if (dt.getSides() == 0) {
				target = new Target(dt.getCurrent(),diceChanged);
				new PoolDicePile(dt.getPool(), target);
			} else {
				dice[j] = new CurrentDicePile(dt.getSides(), dt.getCurrent(), diceChanged);
				new PoolDicePile(dt.getPool(), dice[j]);
				++j;
			}
		}
		
		clear.setOnClickListener(new Clear());
		
		this.answer_fraction = answer_fraction;
		this.answer_probability = answer_probability;
		this.graphSetter = graphSetter;<commit_msg>use foreach<commit_after>package org.kleemann.diceprobabilities;

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

import org.apache.commons.math3.fraction.BigFraction;
import org.kleemann.diceprobabilities.distribution.ConstantDistribution;
import org.kleemann.diceprobabilities.distribution.DieDistribution;
import org.kleemann.diceprobabilities.distribution.Distribution;
import org.kleemann.diceprobabilities.distribution.MultinomialDistribution;
import org.kleemann.diceprobabilities.graph.GraphView;

import android.os.AsyncTask;
import android.os.Bundle;
import android.util.SparseIntArray;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * <p>This class contains the behavior for a set of pool dice, 
 * current dice, and result values. 
 */
public class DiceSet {

	public static class DieType {
		private int sides;
		private Button pool;
		private Button current;
		public DieType(int sides, Button pool, Button current) {
			this.sides = sides;
			this.pool = pool;
			this.current = current;
		}
		public int getSides() { return sides; }
		public Button getPool() { return pool; }
		public Button getCurrent() { return current; }
	}
	
	private CurrentDicePile[] dice;
	private CurrentDicePile target;
	
	private TextView answer_fraction;
	private TextView answer_probability;
	private GraphView.Setter graphSetter;
	
	// every time the dice are changed; this is incremented
	private long serial = 0;
	// true if the background distribution calculation is running
	private boolean running = false;

	private final DecimalFormat answerFormatter;
	private final int maxFractionChars;

	private static final String APPROXIMATELY_EQUAL_TO = "\u2245";
	private static final String GREATER_THAN_OR_EQUAL_TO = "\u2265"; 
	private static final String RIGHT_ARROW = "\u21e8"; 
	
	public DiceSet(
			DieType[] dieType,
			Button clear,
			TextView answer_fraction,
			TextView answer_probability,
			GraphView.Setter graphSetter
			) {
		
		this.answerFormatter = new DecimalFormat(clear.getResources().getString(R.string.answer_format));
		this.maxFractionChars = clear.getResources().getInteger(R.integer.max_fraction_chars); 
		
		CurrentDiceChanged diceChanged = new CurrentDiceChanged();
		dice = new CurrentDicePile[dieType.length-1]; // don't allocate space for the target
		int i=0;
		for (DieType dt : dieType) {
			if (dt.getSides() == 0) {
				// zero sides signifies target
				target = new Target(dt.getCurrent(),diceChanged);
				new PoolDicePile(dt.getPool(), target);
			} else {
				dice[i] = new CurrentDicePile(dt.getSides(), dt.getCurrent(), diceChanged);
				new PoolDicePile(dt.getPool(), dice[i]);
				++i;
			}
		}
		
		clear.setOnClickListener(new Clear());
		
		this.answer_fraction = answer_fraction;
		this.answer_probability = answer_probability;
		this.graphSetter = graphSetter;
{'fraction_non_alphanumeric': 0.09399477806788512, 'fraction_numerical': 0.005744125326370757, 'mean_word_length': 4.717412935323383, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '3130727', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1707, 'n_words': 446}