<commit_before>package se.chalmers.dat255.sleepfighter.model;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;

import se.chalmers.dat255.sleepfighter.utils.collect.ObservableList;
import se.chalmers.dat255.sleepfighter.utils.message.Message;
import se.chalmers.dat255.sleepfighter.utils.message.MessageBus;

import com.badlogic.gdx.utils.IntArray;

/**
 * Manages all the existing alarms.
 *
 * @author Centril<<EMAIL>> / <NAME>.
 * @version 1.0
 * @since Sep 18, 2013
 */
public class AlarmList extends ObservableList<Alarm> {
	/**
	 * Constructs the manager with no initial alarms.
	 */	
	public AlarmList() {
		this( new ArrayList<Alarm>() );
	}

	/**
	 * Constructs the manager starting with given alarms.
	 *
	 * @param alarms list of given alarms. Don't modify this list directly.
	 */
	public AlarmList( List<Alarm> alarms ) {
		this.setDelegate( alarms );
	}

	/**
	 * Sets the list of alarms.
	 *
	 * @param delegate list of given alarms. Don't modify this list directly.
	 */
	@Override
	public void setDelegate( List<Alarm> delegate ) {
		super.setDelegate( delegate );
	}

	@Override
	protected void fireEvent( Event e ) {
		// Intercept add/update events and inject message bus.
		if ( e.operation() == Operation.ADD ) {
			for ( Object obj : e.elements() ) {
				((Alarm) obj).setMessageBus( this.getMessageBus() );
			}
		} else if ( e.operation() == Operation.UPDATE ) {
			this.get( e.index() ).setMessageBus( this.getMessageBus() );
		}

		super.fireEvent( e );
	}

	/**
	 * <p>Finds the lowest unnamed placement number.</p>
	 *
<<<<<<< HEAD
=======
	 * <p>Time complexity: O(n),<br/>
	 * Space complexity: O(n).</p>
	 *
>>>>>>> Fixed findLowestUnnamedPlacement() and provided test.
	 * @see Alarm#getUnnamedPlacement()
	 * @return the lowest unnamed placement number.
	 */
	public int findLowestUnnamedPlacement() {
		// Bail early if we can.
		if ( this.size() == 0 ) {
			return 1;
		}

		// First extract the unnamed placements defined.
		IntArray arr = new IntArray(); 
		arr.ordered = false;
		for ( Alarm alarm : this ) {
			if ( alarm.isUnnamed() ) {
				int place = alarm.getUnnamedPlacement();
				if ( place > 0 ) {
					arr.add( place );
				}
			}
		}

		// Another opportunity to bail.
		if ( arr.size == 0 ) {
			return 1;
		}

		arr.shrink();
<commit_msg>Some merge conflict text accidentally got into javadoc, fixed.<commit_after>package se.chalmers.dat255.sleepfighter.model;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;

import se.chalmers.dat255.sleepfighter.utils.collect.ObservableList;
import se.chalmers.dat255.sleepfighter.utils.message.Message;
import se.chalmers.dat255.sleepfighter.utils.message.MessageBus;

import com.badlogic.gdx.utils.IntArray;

/**
 * Manages all the existing alarms.
 *
 * @author Centril<<EMAIL>> / <NAME>.
 * @version 1.0
 * @since Sep 18, 2013
 */
public class AlarmList extends ObservableList<Alarm> {
	/**
	 * Constructs the manager with no initial alarms.
	 */	
	public AlarmList() {
		this( new ArrayList<Alarm>() );
	}

	/**
	 * Constructs the manager starting with given alarms.
	 *
	 * @param alarms list of given alarms. Don't modify this list directly.
	 */
	public AlarmList( List<Alarm> alarms ) {
		this.setDelegate( alarms );
	}

	/**
	 * Sets the list of alarms.
	 *
	 * @param delegate list of given alarms. Don't modify this list directly.
	 */
	@Override
	public void setDelegate( List<Alarm> delegate ) {
		super.setDelegate( delegate );
	}

	@Override
	protected void fireEvent( Event e ) {
		// Intercept add/update events and inject message bus.
		if ( e.operation() == Operation.ADD ) {
			for ( Object obj : e.elements() ) {
				((Alarm) obj).setMessageBus( this.getMessageBus() );
			}
		} else if ( e.operation() == Operation.UPDATE ) {
			this.get( e.index() ).setMessageBus( this.getMessageBus() );
		}

		super.fireEvent( e );
	}

	/**
	 * <p>Finds the lowest unnamed placement number.</p>
	 *
	 * <p>Time complexity: O(n),<br/>
	 * Space complexity: O(n).</p>
	 *
	 * @see Alarm#getUnnamedPlacement()
	 * @return the lowest unnamed placement number.
	 */
	public int findLowestUnnamedPlacement() {
		// Bail early if we can.
		if ( this.size() == 0 ) {
			return 1;
		}

		// First extract the unnamed placements defined.
		IntArray arr = new IntArray(); 
		arr.ordered = false;
		for ( Alarm alarm : this ) {
			if ( alarm.isUnnamed() ) {
				int place = alarm.getUnnamedPlacement();
				if ( place > 0 ) {
					arr.add( place );
				}
			}
		}

		// Another opportunity to bail.
		if ( arr.size == 0 ) {
			return 1;
		}

		arr.shrink();

{'fraction_non_alphanumeric': 0.13906996957844414, 'fraction_numerical': 0.01086484137331595, 'mean_word_length': 3.1921675774134792, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 36, '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': '6272814', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1486, 'n_words': 408}