<commit_before>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Alensia.Core.Actor;
using Alensia.Core.Common;
using UnityEngine.Assertions;

namespace Alensia.Core.Camera
{
    public class CameraManager : ICameraManager
    {
        private ICameraMode _mode;

        public ICameraMode Mode
        {
            get { return _mode; }

            private set
            {
                if (value == null || value == _mode) return;

                if (_mode != null) _mode.Deactivate();

                _mode = value;

                if (_mode == null) return;

                _mode.Activate();

                CameraChanged.Fire(_mode);
            }
        }

        public ReadOnlyCollection<ICameraMode> AvailableModes { get; private set; }

        public CameraChangeEvent CameraChanged { get; private set; }

        public CameraManager(List<ICameraMode> modes, CameraChangeEvent cameraChanged)
        {
            Assert.IsNotNull(modes, "modes != null");
            Assert.IsTrue(modes.Count > 0, "modes.Count > 0");
            Assert.IsNotNull(cameraChanged, "cameraChanged != null");

            AvailableModes = modes.AsReadOnly();
            CameraChanged = cameraChanged;
        }

        public T Switch<T>() where T : class, ICameraMode
        {
            return AvailableModes.FirstOrDefault(m => m is T) as T;
        }

        public IFirstPersonCamera ToFirstPerson(IActor target)
        {
            var camera = Switch<IFirstPersonCamera>();

            if (camera == null) return null;

            camera.Initialize(target);

            Mode = camera;

            return camera;
        }

        public IThirdPersonCamera ToThirdPerson(IActor target)
        {<commit_msg>Use ICollection.Any(), instead of Count() for validation<commit_after>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Alensia.Core.Actor;
using Alensia.Core.Common;
using UnityEngine.Assertions;

namespace Alensia.Core.Camera
{
    public class CameraManager : ICameraManager
    {
        private ICameraMode _mode;

        public ICameraMode Mode
        {
            get { return _mode; }

            private set
            {
                if (value == null || value == _mode) return;

                if (_mode != null) _mode.Deactivate();

                _mode = value;

                if (_mode == null) return;

                _mode.Activate();

                CameraChanged.Fire(_mode);
            }
        }

        public ReadOnlyCollection<ICameraMode> AvailableModes { get; private set; }

        public CameraChangeEvent CameraChanged { get; private set; }

        public CameraManager(List<ICameraMode> modes, CameraChangeEvent cameraChanged)
        {
            Assert.IsNotNull(modes, "modes != null");
            Assert.IsTrue(modes.Any(), "modes.Any()");

            Assert.IsNotNull(cameraChanged, "cameraChanged != null");

            AvailableModes = modes.AsReadOnly();
            CameraChanged = cameraChanged;
        }

        public T Switch<T>() where T : class, ICameraMode
        {
            return AvailableModes.FirstOrDefault(m => m is T) as T;
        }

        public IFirstPersonCamera ToFirstPerson(IActor target)
        {
            var camera = Switch<IFirstPersonCamera>();

            if (camera == null) return null;

            camera.Initialize(target);

            Mode = camera;

            return camera;
        }

        public IThirdPersonCamera ToThirdPerson(IActor target)
        {
{'fraction_non_alphanumeric': 0.08940397350993377, 'fraction_numerical': 0.0005518763796909492, 'mean_word_length': 1.9447603574329813, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '5617959', 'n_tokens_mistral': 966, 'n_tokens_neox': 918, 'n_words': 234}