<commit_before>package com.futurice.android.reservator.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Vector;

public class Room implements Serializable {
	private static final long serialVersionUID = 1L;
	private String name, email;
	private Vector<Reservation> reservations;

	public Room(String name, String email) {
		this.name = name;
		this.email = email;
		this.reservations = new Vector<Reservation>();
	}

	//public Vector<Reservation> getReservations(){
	//	return this.reservations;
	//}

	public String getName() {
		return name;
	}

	public String getEmail() {
		return email;
	}

	public void setReservations(Vector<Reservation> reservations){
		this.reservations = reservations;
		Collections.sort(reservations);
	}

	@Override
	public String toString() {
		return name; // + " " + (isFree() ? "(free)" : "(reserved)");
	}

	public boolean isFree() {
		DateTime now = new DateTime();
		for (Reservation r : reservations) {
			if (r.getStartTime().before(now) && r.getEndTime().after(now)) {
				return false;
			}
		}

		return true;
	}

	/**
	 * Time in minutes the room is free
	 * Precondition: room is free
	 *
	 * @param from
	 * @return Integer.MAX_VALUE if no reservations in future
	 */
	public int minutesFreeFrom(DateTime from) {
		for (Reservation r : reservations) {
			if (r.getStartTime().after(from)) {
				return (int) (r.getStartTime().getTimeInMillis() - from.getTimeInMillis()) / 60000;
			}
		}

		return Integer.MAX_VALUE;
	}

	public int minutesFreeFromNow() {
		return minutesFreeFrom(new DateTime());
	}


	/**<commit_msg>Bugfix, rooms that were reserved long in future appeared reserved in the lobby view<commit_after>package com.futurice.android.reservator.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Vector;

public class Room implements Serializable {
	private static final long serialVersionUID = 1L;
	private String name, email;
	private Vector<Reservation> reservations;

	public Room(String name, String email) {
		this.name = name;
		this.email = email;
		this.reservations = new Vector<Reservation>();
	}

	//public Vector<Reservation> getReservations(){
	//	return this.reservations;
	//}

	public String getName() {
		return name;
	}

	public String getEmail() {
		return email;
	}

	public void setReservations(Vector<Reservation> reservations){
		this.reservations = reservations;
		Collections.sort(reservations);
	}

	@Override
	public String toString() {
		return name; // + " " + (isFree() ? "(free)" : "(reserved)");
	}

	public boolean isFree() {
		DateTime now = new DateTime();
		for (Reservation r : reservations) {
			if (r.getStartTime().before(now) && r.getEndTime().after(now)) {
				return false;
			}
		}

		return true;
	}

	/**
	 * Time in minutes the room is free
	 * Precondition: room is free
	 *
	 * @param from
	 * @return Integer.MAX_VALUE if no reservations in future
	 */
	public int minutesFreeFrom(DateTime from) {
		for (Reservation r : reservations) {
			if (r.getStartTime().after(from)) {
				return (int) ((r.getStartTime().getTimeInMillis() - from.getTimeInMillis()) / 60000);
			}
		}

		return Integer.MAX_VALUE;
	}

	public int minutesFreeFromNow() {
		return minutesFreeFrom(new DateTime());
	}


	/**
{'fraction_non_alphanumeric': 0.12470794392523364, 'fraction_numerical': 0.0035046728971962616, 'mean_word_length': 3.9781976744186047, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3110623', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1067, 'n_words': 285}