<commit_before>import java.util.ArrayList;

/**
 * Class describing a Building.
 */
public class Building {
	
	// these variables are declared public final, since they cannot change after being initialized
	public final Position POSITION;
	public final int PLAYER;
	
	private boolean upgraded;
	/* I don't where this is used, but the player should not be static.
	 * By making the player static every single building will share the
	 * same player, which is certainly not what is intended.
	 * I changed it, so some of the code might need to be rewritten now.
	 * Same goes for the boolean upgraded. */
	//private static ArrayList<Building> buildings = new ArrayList<Building>();
	
	/**
	 * Private constructor. One should use {@link Building#build(Position, int)} instead, since it contains error checking.
	 * @param inPos the Position to place the building at
	 * @param player the player index
	 */
	private Building(Position inPos, int player) {
		POSITION = inPos;
		PLAYER = player;
	}
	
	/**
	 * This method should be used instead of calling the constructor since it contains error checking.
	 * @param division the division
	 * @param index the index
	 * @return the constructed building; returns null if no building can be built
	 */
	public static Building build(Position inPos, int player) {
		// error checking
		if (canBuild(inPos)) {
			System.out.println("Building here:    " + inPos.DIVISION + ", " + inPos.INDEX);
			Building building = new Building(inPos, player);
			GameData.buildings.add(building);
			Road.longestRoad();
			GameData.players.get(player).addPoint();
			System.out.println("Player has " + GameData.players.get(player).points + " points");
			return building;
		}
		
		System.out.println("Can't build here: " + inPos.DIVISION + ", " + inPos.INDEX);
		return null;
	}
	
	/**
	 * Gets the Position of all built buildings.
	 * @return The positions as an ArrayList
	 */
	public static ArrayList<Position> getBuildingPositions() {
		ArrayList<Position> positions = new ArrayList<Position>();
		for (int i = 0; i < GameData.buildings.size(); i++) {
			positions.add(GameData.buildings.get(i).POSITION);
		}
		return positions;
	}
	
	/**
	 * Checks whether it is legal to place a building at a specific position.
	 * @param inPos the position to be checked
	 * @return true if a building can be built; otherwise false
	 */
	public static boolean canBuild(Position inPos) {
		if (getBuildingPositions() != null && Position.getLength(getBuildingPositions(), inPos) < 2)
			return false;
		return true;
	}
	<commit_msg>Fix canBuild() method to only return true if theres a road<commit_after>import java.util.ArrayList;

/**
 * Class describing a Building.
 */
public class Building {
	
	// these variables are declared public final, since they cannot change after being initialized
	public final Position POSITION;
	public final int PLAYER;
	
	private boolean upgraded;
	/* I don't where this is used, but the player should not be static.
	 * By making the player static every single building will share the
	 * same player, which is certainly not what is intended.
	 * I changed it, so some of the code might need to be rewritten now.
	 * Same goes for the boolean upgraded. */
	//private static ArrayList<Building> buildings = new ArrayList<Building>();
	
	/**
	 * Private constructor. One should use {@link Building#build(Position, int)} instead, since it contains error checking.
	 * @param inPos the Position to place the building at
	 * @param player the player index
	 */
	private Building(Position inPos, int player) {
		POSITION = inPos;
		PLAYER = player;
	}
	
	/**
	 * This method should be used instead of calling the constructor since it contains error checking.
	 * @param division the division
	 * @param index the index
	 * @return the constructed building; returns null if no building can be built
	 */
	public static Building build(Position inPos, int player) {
		// error checking
		if (canBuild(inPos)) {
			System.out.println("Building here:    " + inPos.DIVISION + ", " + inPos.INDEX);
			Building building = new Building(inPos, player);
			GameData.buildings.add(building);
			Road.longestRoad();
			GameData.players.get(player).addPoint();
			System.out.println("Player has " + GameData.players.get(player).points + " points");
			return building;
		}
		
		System.out.println("Can't build here: " + inPos.DIVISION + ", " + inPos.INDEX);
		return null;
	}
	
	/**
	 * Gets the Position of all built buildings.
	 * @return The positions as an ArrayList
	 */
	public static ArrayList<Position> getBuildingPositions() {
		ArrayList<Position> positions = new ArrayList<Position>();
		for (int i = 0; i < GameData.buildings.size(); i++) {
			positions.add(GameData.buildings.get(i).POSITION);
		}
		return positions;
	}
	
	/**
	 * Checks whether it is legal to place a building at a specific position.
	 * @param inPos the position to be checked
	 * @return true if a building can be built; otherwise false
	 */
	public static boolean canBuild(Position inPos) {
		if (getBuildingPositions() != null && Position.getLength(getBuildingPositions(), inPos) < 2)
			return false;
		
		for (int i = 0; i < GameData.roads.size(); i++) {
			if (GameData.roads.get(i).PLAYER_INDEX == GameData.ownIndex) {
				if (Position.comparePosition(GameData.roads.get(i).start, inPos) ||
						Position.comparePosition(GameData.roads.get(i).end, inPos))
					return true;
			}
		}
		return false;
	}
	
{'fraction_non_alphanumeric': 0.103429203539823, 'fraction_numerical': 0.0009218289085545723, 'mean_word_length': 3.725609756097561, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 13, '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': '2801515', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1476, 'n_words': 581}