<commit_before>package p012;

import java.awt.Image;
import javax.swing.ImageIcon;

//TODO Transform the code to be used safely in a concurrent context.  
public class Ball {
       //TODO  Find an archive named Ball.png 
	private String Ball = "../../media/Ball.png"; 

	private double x,y,dx,dy;
	private double v,fi;
	private Image image;

	public Ball() {
		ImageIcon ii = new ImageIcon(this.getClass().getResource(Ball));
		image = ii.getImage();
		x = Billiards.Width/4-16;
		y = Billiards.Height/2-16;
		v = 5;
		fi =  Math.random() * Math.PI * 2;
	}

	public void move() {
		invariantes();
		reflect();
		v = v*Math.exp(-v/1000);
		dx = v*Math.cos(fi);
		dy = v*Math.sin(fi);
		if (Math.abs(dx) < 1 && Math.abs(dy) < 1) {
			dx = 0;
			dy = 0;
		}
		x += dx;   
		y += dy;
		invariantes();
		//TODO Check postcondition
	}
	private synchronized void invariantes(){
		boolean res=false;
		res=(x>=Board.LEFTBOARD && x+110<Board.RIGHTBOARD &&
				y>=Board.TOPBOARD && y+110<Board.BOTTOMBOARD);
		assert res;
	}

	public void reflect() {
		if (Math.abs(x + 110 - Board.RIGHTBOARD) <  Math.abs(dx)) {
			fi = Math.PI - fi;
		}
		if (Math.abs(y + 110 - Board.BOTTOMBOARD) <  Math.abs(dy)) {
			fi = - fi;
		}
		if (Math.abs(x - Board.LEFTBOARD) <  Math.abs(dx)) {
			fi = Math.PI - fi;
		}
		if (Math.abs(y - Board.TOPBOARD) <  Math.abs(dy)) {
			fi = - fi;
		}
		invariantes();
		//TODO Check postcondition	
	}

	public int getX() {
		return (int)x;
	}
	
	public int getY() {
		return (int)y;
	}
	
	public double getFi() {
		return fi;
	}

	public double getdr() {
		return Math.sqrt(dx*dx+dy*dy);
	}

	public void setX(double x) {
		this.x = x;
	}

	public void setY(double y) {
		this.y = y;
	}

	public Image getImage() {
		return image;
	}

}
<commit_msg>Concurrencia fix #3<commit_after>package p012;

import java.awt.Image;
import javax.swing.ImageIcon;
//TODO Transform the code to be used safely in a concurrent context.  
public class Ball {
	private String Ball = "../../media/Ball.png"; 

	private double x,y,dx,dy;
	private double v,fi;
	private Image image;

	public Ball() {
		ImageIcon ii = new ImageIcon(this.getClass().getResource(Ball));
		image = ii.getImage();
		x = Billiards.Width/4-16;
		y = Billiards.Height/2-16;
		v = 5;
		fi =  Math.random() * Math.PI * 2;
		if (!invariantes()){
			System.out.println("Violaciï¿½n del invariante en la construcciï¿½n");
			System.out.println("Usando valores por defecto");
			x = Billiards.Width/4-16;
			y = Billiards.Height/2-16;
			v = 5;
			fi =  Math.random() * Math.PI * 2;
		}
	}
	public synchronized void move() {
		invariantes();
		reflect();
		v = v*Math.exp(-v/1000);
		dx = v*Math.cos(fi);
		dy = v*Math.sin(fi);
		if (Math.abs(dx) < 1 && Math.abs(dy) < 1) {
			dx = 0;
			dy = 0;
		}
		x += dx;   
		y += dy;
		invariantes();
		
	}
	private synchronized boolean invariantes(){
		boolean res=false;
		res=(x>=Board.LEFTBOARD && x+110<Board.RIGHTBOARD &&
				y>=Board.TOPBOARD && y+110<Board.BOTTOMBOARD);
		assert res;
		return res;
	}
	public synchronized void reflect() {
		if (Math.abs(x  +110- Board.RIGHTBOARD) <  Math.abs(dx)) {
			fi = Math.PI - fi;
		}
		if (Math.abs(y +110 - Board.BOTTOMBOARD) <  Math.abs(dy)) {
			fi = - fi;
		}
		if (Math.abs(x - Board.LEFTBOARD) <  Math.abs(dx)) {
			fi = Math.PI - fi;
		}
		if (Math.abs(y - Board.TOPBOARD) <  Math.abs(dy)) {
			fi = - fi;
		}
	}

	public synchronized int getX() {
		return (int)x;
	}
	
	public synchronized int getY() {
		return (int)y;
	}
	
	public double getFi() {
		return fi;
	}

	public double getdr() {
		return Math.sqrt(dx*dx+dy*dy);
	}

	public void setX(double x) {
		this.x = x;
	}

	public void setY(double y) {
		this.y = y;
	}

	public Image getImage() {
		return image;
	}

}



{'fraction_non_alphanumeric': 0.16457051110516457, 'fraction_numerical': 0.018999197217019, 'mean_word_length': 2.7949238578680204, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, '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': '2471288', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1489, 'n_words': 357}