text:
// Copyright (c) Aurora Studio. All rights reserved.
//
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Com.Aurora.AuWeather.Models.HeWeather;
using Com.Aurora.Shared.Converters;
using Com.Aurora.Shared.Extensions;
using Com.Aurora.Shared.Helpers;
using System.Text;
using System;

namespace Com.Aurora.AuWeather.Models
{
    public class Glance
    {
        static Windows.ApplicationModel.Resources.ResourceLoader loader = new Windows.ApplicationModel.Resources.ResourceLoader();
        #region Condition desiciption
        private static readonly string[] sunny = new string[] { loader.GetString("GlanceSunny0"), loader.GetString("GlanceSunny1") };
        private static readonly string[] cloudy = new string[] { loader.GetString("Glancecloudy0"), loader.GetString("Glancecloudy1") };
        private static readonly string[] few_clouds = new string[] { loader.GetString("few_clouds0"), loader.GetString("few_clouds1") };
        private static readonly string[] partly_cloudy = new string[] { loader.GetString("partly_cloudy0") };
        private static readonly string[] overcast = new string[] { loader.GetString("overcast0"), loader.GetString("overcast1") };
        private static readonly string[] windy = new string[] { loader.GetString("windy0") };
        private static readonly string[] breeze = new string[] { loader.GetString("breeze0"), loader.GetString("breeze1") };
        private static readonly string[] gale = new string[] { loader.GetString("gale0"), loader.GetString("gale1") };
        private static readonly string[] storm = new string[] { loader.GetString("storm0") };
        private static readonly string[] thundershower = new string[] { loader.GetString("thundershower0") };
        private static readonly string[] hail = new string[] { loader.GetString("hail0") };
        private static readonly string[] moderate_rain = new string[] { loader.GetString("moderate_rain0"), loader.GetString("moderate_rain1"), loader.GetString("moderate_rain2"), loader.GetString("moderate_rain3") };
        private static readonly string[] heavy_rain = new string[] { loader.GetString("heavy_rain0"), loader.GetString("heavy_rain1") };
        private static readonly string[] heavy_storm_rain = new string[] { loader.GetString("heavy_storm_rain0"), loader.GetString("heavy_storm_rain1") };
        private static readonly string[] shower = new string[] { loader.GetString("shower0"), loader.GetString("shower1") };
        private static readonly string[] freezing_rain = new string[] { loader.GetString("freezing_rain0") };
        private static readonly string[] moderate_snow = new string[] { loader.GetString("moderate_snow0"), loader.GetString("moderate_snow1"), loader.GetString("moderate_snow2") };
        private static readonly string[] heavy_snow = new string[] { loader.GetString("heavy_snow0"), loader.GetString("heavy_snow1") };
        private static readonly string[] shower_snow = new string[] { loader.GetString("shower_snow0"), loader.GetString("shower_snow1") };
        private static readonly string[] snowstorm = new string[] { loader.GetString("snowstorm0"), loader.GetString("snowstorm1") };
        private static readonly string[] sleet = new string[] { loader.GetString("sleet0"), loader.GetString("sleet1") };
        private static readonly string[] mist = new string[] { loader.GetString("mist0") };
        private static readonly string[] foggy = new string[] { loader.GetString("foggy0") };
        private static readonly string[] haze = new string[] { loader.GetString("haze0") };
        private static readonly string[] dust = new string[] { loader.GetString("dust0") };
        private static readonly string[] duststorm = new string[] { loader.GetString("duststorm0") };
        #endregion
        #region Condition decoration
        private static readonly string[] haotianqi = new string[] { loader.GetString("haotianqi0"), loader.GetString("haotianqi1") };
        private static readonly string[] huaitianqi = new string[] { loader.GetString("huaitianqi0"), loader.GetString("huaitianqi1") };
        private static readonly string[] shiduda = new string[] { loader.GetString("shiduda0"), loader.GetString("shiduda1") };
        private static readonly string[] nengjiandudi = new string[] { loader.GetString("nengjiandudi0"), loader.GetString("nengjiandudi1") };
        private static readonly string[] wendugao = new string[] { loader.GetString("wendugao0"), loader.GetString("wendugao1") };
        private static readonly string[] wendudi = new string[] { loader.GetString("wendudi0"), loader.GetString("wendudi1") };
        #endregion
        public static string GenerateShortDescription(HeWeatherModel model, bool isNight)
        {
            var utcOffset = model.Location.UpdateTime - model.Location.UtcTime;
            var current = DateTimeHelper.ReviseLoc(utcOffset);
            var todayIndex = Array.FindIndex(model.DailyForecast, x =>
            {
                return x.Date.Date == current.Date;
            });
            if (isNight && current.Hour < 12)
            {
                todayIndex--;
            }
            if (todayIndex < 0)
            {
                todayIndex = 0;
            }
            var 主语 = model.NowWeather.Now.Condition;
            string zhuyu = loader.GetString("xianzai");
            if (Tools.Random.Next(200) >= 100)
            {
                if (isNight)
                {
                    主语 = model.DailyForecast[todayIndex].Condition.NightCond;
                    zhuyu = loader.GetString("wanjian");
                }
                else
                {
                    主语 = model.DailyForecast[todayIndex].Condition.DayCond;
                    zhuyu = loader.GetString("jintian");
                }
            }
            string binyu;
            StringBuilder decoration = new StringBuilder();
            if (Tools.Random.Next(200) >= 100)
            {
                if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius < 0)
                {
                    decoration.Append(wendudi.SelectRandomString() + ", ");
                }
                else if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius > 25)
                {
                    decoration.Append(wendugao.SelectRandomString() + ", ");
                }
                if (Tools.Random.Next(200) >= 100 && model.DailyForecast[todayIndex].Humidity > 80)
                {
                    decoration.Append(shiduda[0] + ", ");
                }
                if (model.NowWeather.Visibility != null)
                    if (Tools.Random.Next(200) >= 100 && model.NowWeather.Visibility.KM < 0.5)
                    {
                        decoration.Append(nengjiandudi[0] + ", ");
                    }
                if (Tools.Random.Next(200) >= 100)
                    switch (主语)
                    {
                        case WeatherCondition.unknown:
                            return loader.GetString("unknown_weather");
                        case WeatherCondition.sunny:
                        case WeatherCondition.few_clouds:
                        case WeatherCondition.partly_cloudy:
                        case WeatherCondition.calm:
                        case WeatherCondition.light_breeze:
                        case WeatherCondition.moderate:
                        case WeatherCondition.fresh_breeze:
                            decoration.Append(haotianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.overcast:
                        case WeatherCondition.cloudy:
                        case WeatherCondition.windy:
                            break;
                        case WeatherCondition.strong_breeze:
                        case WeatherCondition.high_wind:
                            break;
                        case WeatherCondition.gale:
                        case WeatherCondition.strong_gale:
                        case WeatherCondition.storm:
                        case WeatherCondition.violent_storm:
                        case WeatherCondition.hurricane:
                        case WeatherCondition.tornado:
                        case WeatherCondition.tropical_storm:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.shower_rain:
                            break;
                        case WeatherCondition.heavy_shower_rain:
                        case WeatherCondition.thundershower:
                        case WeatherCondition.heavy_thunderstorm:
                        case WeatherCondition.hail:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.light_rain:
                        case WeatherCondition.moderate_rain:
                            break;
                        case WeatherCondition.heavy_rain:
                        case WeatherCondition.extreme_rain:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.drizzle_rain:
                            break;
                        case WeatherCondition.storm_rain:
                        case WeatherCondition.heavy_storm_rain:
                        case WeatherCondition.severe_storm_rain:
                        case WeatherCondition.freezing_rain:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.light_snow:
                            break;
                        case WeatherCondition.moderate_snow:
                        case WeatherCondition.heavy_snow:
                        case WeatherCondition.snowstorm:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.sleet:
                        case WeatherCondition.rain_snow:
                        case WeatherCondition.shower_snow:
                        case WeatherCondition.snow_flurry:
                            break;
                        case WeatherCondition.mist:
                            break;
                        case WeatherCondition.foggy:
                        case WeatherCondition.haze:
                        case WeatherCondition.sand:
                        case WeatherCondition.dust:
                        case WeatherCondition.volcanic_ash:
                        case WeatherCondition.duststorm:
                        case WeatherCondition.sandstorm:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.hot:
                        case WeatherCondition.cold:
                            break;
                        default:
                            break;
                    }
                if (decoration.ToString().EndsWith(", "))
                {
                    decoration.Remove(decoration.Length - 2, 2);
                }
            }
            switch (主语)
            {
                case WeatherCondition.unknown:
                    return loader.GetString("unknown_weather");
                case WeatherCondition.sunny:
                    binyu = sunny.SelectRandomString();
                    break;
                case WeatherCondition.cloudy:
                    binyu = cloudy.SelectRandomString();
                    break;
                case WeatherCondition.few_clouds:
                    binyu = few_clouds.SelectRandomString();
                    break;
                case WeatherCondition.partly_cloudy:
                    binyu = partly_cloudy.SelectRandomString();
                    break;
                case WeatherCondition.overcast:
                    binyu = overcast.SelectRandomString();
                    break;
                case WeatherCondition.windy:
                    binyu = windy.SelectRandomString();
                    break;
                case WeatherCondition.calm:
                case WeatherCondition.light_breeze:
                case WeatherCondition.moderate:
                case WeatherCondition.fresh_breeze:
                    binyu = breeze.SelectRandomString();
                    break;
                case WeatherCondition.strong_breeze:
                case WeatherCondition.high_wind:
                case WeatherCondition.gale:
                case WeatherCondition.strong_gale:
                    binyu = gale.SelectRandomString();
                    break;
                case WeatherCondition.storm:
                case WeatherCondition.violent_storm:
                case WeatherCondition.hurricane:
                case WeatherCondition.tornado:
                case WeatherCondition.tropical_storm:
                    binyu = storm.SelectRandomString();
                    break;
                case WeatherCondition.shower_rain:
                case WeatherCondition.heavy_shower_rain:
                    binyu = shower.SelectRandomString();
                    break;
                case WeatherCondition.thundershower:
                case WeatherCondition.heavy_thunderstorm:
                    binyu = thundershower.SelectRandomString();
                    break;
                case WeatherCondition.hail:
                    binyu = hail.SelectRandomString();
                    break;
                case WeatherCondition.drizzle_rain:
                case WeatherCondition.light_rain:
                case WeatherCondition.moderate_rain:
                    binyu = moderate_rain.SelectRandomString();
                    break;
                case WeatherCondition.heavy_rain:
                case WeatherCondition.extreme_rain:
                    binyu = heavy_rain.SelectRandomString();
                    break;
                case WeatherCondition.storm_rain:
                case WeatherCondition.heavy_storm_rain:
                case WeatherCondition.severe_storm_rain:
                    binyu = storm.SelectRandomString();
                    break;
                case WeatherCondition.freezing_rain:
                    binyu = freezing_rain.SelectRandomString();
                    break;
                case WeatherCondition.light_snow:
                case WeatherCondition.moderate_snow:
                    binyu = moderate_snow.SelectRandomString();
                    break;
                case WeatherCondition.heavy_snow:
                    binyu = heavy_snow.SelectRandomString();
                    break;
                case WeatherCondition.snowstorm:
                    binyu = snowstorm.SelectRandomString();
                    break;
                case WeatherCondition.sleet:
                case WeatherCondition.rain_snow:
                    binyu = sleet.SelectRandomString();
                    break;
                case WeatherCondition.shower_snow:
                case WeatherCondition.snow_flurry:
                    binyu = shower_snow.SelectRandomString();
                    break;
                case WeatherCondition.mist:
                    binyu = mist.SelectRandomString();
                    break;
                case WeatherCondition.foggy:
                    binyu = foggy.SelectRandomString();
                    break;
                case WeatherCondition.haze:
                    binyu = haze.SelectRandomString();
                    break;
                case WeatherCondition.sand:
                case WeatherCondition.dust:
                    binyu = dust.SelectRandomString();
                    break;
                case WeatherCondition.volcanic_ash:
                case WeatherCondition.duststorm:
                case WeatherCondition.sandstorm:
                    binyu = duststorm.SelectRandomString();
                    break;
                case WeatherCondition.hot:
                    binyu = loader.GetString("bianre");
                    break;
                case WeatherCondition.cold:
                    binyu = loader.GetString("bianleng");
                    break;
                default: return loader.GetString("unknown_weather");
            }
            return string.Format(loader.GetString("Glance"), zhuyu, binyu, decoration);
        }

        public static string GenerateGlanceDescription(HeWeatherModel model, bool isNight, TemperatureParameter parameter, DateTime desiredDate)
        {
            var todayIndex = Array.FindIndex(model.DailyForecast, x =>
            {
                return x.Date.Date == desiredDate.Date;
            });
            if (isNight && desiredDate.Hour < 12)
            {
                todayIndex--;
            }
            if (todayIndex < 0)
            {
                todayIndex = 0;
            }
            var 主语 = model.NowWeather.Now.Condition;
            string zhuyu = loader.GetString("xianzai");
            if (Tools.Random.Next(200) >= 100)
            {
                if (isNight)
                {
                    主语 = model.DailyForecast[todayIndex].Condition.NightCond;
                    zhuyu = loader.GetString("wanjian");
                }
                else
                {
                    主语 = model.DailyForecast[todayIndex].Condition.DayCond;
                    zhuyu = loader.GetString("jintian");
                }
            }
            string binyu;
            StringBuilder decoration = new StringBuilder();
            if (Tools.Random.Next(200) >= 100)
            {
                if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius < 0)
                {
                    decoration.Append(wendudi.SelectRandomString() + ", ");
                }
                else if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius > 25)
                {
                    decoration.Append(wendugao.SelectRandomString() + ", ");
                }
                if (Tools.Random.Next(200) >= 100 && model.DailyForecast[todayIndex].Humidity > 80)
                {
                    decoration.Append(shiduda[0] + ", ");
                }
                if (model.NowWeather.Visibility != null)
                    if (Tools.Random.Next(200) >= 100 && model.NowWeather.Visibility.KM < 0.5)
                    {
                        decoration.Append(nengjiandudi[0] + ", ");
                    }
                if (Tools.Random.Next(200) >= 100)
                    switch (主语)
                    {
                        case WeatherCondition.unknown:
                            return loader.GetString("unknown_weather");
                        case WeatherCondition.sunny:
                        case WeatherCondition.few_clouds:
                        case WeatherCondition.partly_cloudy:
                        case WeatherCondition.calm:
                        case WeatherCondition.light_breeze:
                        case WeatherCondition.moderate:
                        case WeatherCondition.fresh_breeze:
                            decoration.Append(haotianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.overcast:
                        case WeatherCondition.cloudy:
                        case WeatherCondition.windy:
                            break;
                        case WeatherCondition.strong_breeze:
                        case WeatherCondition.high_wind:
                            break;
                        case WeatherCondition.gale:
                        case WeatherCondition.strong_gale:
                        case WeatherCondition.storm:
                        case WeatherCondition.violent_storm:
                        case WeatherCondition.hurricane:
                        case WeatherCondition.tornado:
                        case WeatherCondition.tropical_storm:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.shower_rain:
                            break;
                        case WeatherCondition.heavy_shower_rain:
                        case WeatherCondition.thundershower:
                        case WeatherCondition.heavy_thunderstorm:
                        case WeatherCondition.hail:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.light_rain:
                        case WeatherCondition.moderate_rain:
                            break;
                        case WeatherCondition.heavy_rain:
                        case WeatherCondition.extreme_rain:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.drizzle_rain:
                            break;
                        case WeatherCondition.storm_rain:
                        case WeatherCondition.heavy_storm_rain:
                        case WeatherCondition.severe_storm_rain:
                        case WeatherCondition.freezing_rain:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.light_snow:
                            break;
                        case WeatherCondition.moderate_snow:
                        case WeatherCondition.heavy_snow:
                        case WeatherCondition.snowstorm:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.sleet:
                        case WeatherCondition.rain_snow:
                        case WeatherCondition.shower_snow:
                        case WeatherCondition.snow_flurry:
                            break;
                        case WeatherCondition.mist:
                            break;
                        case WeatherCondition.foggy:
                        case WeatherCondition.haze:
                        case WeatherCondition.sand:
                        case WeatherCondition.dust:
                        case WeatherCondition.volcanic_ash:
                        case WeatherCondition.duststorm:
                        case WeatherCondition.sandstorm:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.hot:
                        case WeatherCondition.cold:
                            break;
                        default:
                            break;
                    }
            }
            switch (主语)
            {
                case WeatherCondition.unknown:
                    return loader.GetString("unknown_weather");
                case WeatherCondition.sunny:
                    binyu = sunny.SelectRandomString();
                    break;
                case WeatherCondition.cloudy:
                    binyu = cloudy.SelectRandomString();
                    break;
                case WeatherCondition.few_clouds:
                    binyu = few_clouds.SelectRandomString();
                    break;
                case WeatherCondition.partly_cloudy:
                    binyu = partly_cloudy.SelectRandomString();
                    break;
                case WeatherCondition.overcast:
                    binyu = overcast.SelectRandomString();
                    break;
                case WeatherCondition.windy:
                    binyu = windy.SelectRandomString();
                    break;
                case WeatherCondition.calm:
                case WeatherCondition.light_breeze:
                case WeatherCondition.moderate:
                case WeatherCondition.fresh_breeze:
                    binyu = breeze.SelectRandomString();
                    break;
                case WeatherCondition.strong_breeze:
                case WeatherCondition.high_wind:
                case WeatherCondition.gale:
                case WeatherCondition.strong_gale:
                    binyu = gale.SelectRandomString();
                    break;
                case WeatherCondition.storm:
                case WeatherCondition.violent_storm:
                case WeatherCondition.hurricane:
                case WeatherCondition.tornado:
                case WeatherCondition.tropical_storm:
                    binyu = storm.SelectRandomString();
                    break;
                case WeatherCondition.shower_rain:
                case WeatherCondition.heavy_shower_rain:
                    binyu = shower.SelectRandomString();
                    break;
                case WeatherCondition.thundershower:
                case WeatherCondition.heavy_thunderstorm:
                    binyu = thundershower.SelectRandomString();
                    break;
                case WeatherCondition.hail:
                    binyu = hail.SelectRandomString();
                    break;
                case WeatherCondition.drizzle_rain:
                case WeatherCondition.light_rain:
                case WeatherCondition.moderate_rain:
                    binyu = moderate_rain.SelectRandomString();
                    break;
                case WeatherCondition.heavy_rain:
                case WeatherCondition.extreme_rain:
                    binyu = heavy_rain.SelectRandomString();
                    break;
                case WeatherCondition.storm_rain:
                case WeatherCondition.heavy_storm_rain:
                case WeatherCondition.severe_storm_rain:
                    binyu = storm.SelectRandomString();
                    break;
                case WeatherCondition.freezing_rain:
                    binyu = freezing_rain.SelectRandomString();
                    break;
                case WeatherCondition.light_snow:
                case WeatherCondition.moderate_snow:
                    binyu = moderate_snow.SelectRandomString();
                    break;
                case WeatherCondition.heavy_snow:
                    binyu = heavy_snow.SelectRandomString();
                    break;
                case WeatherCondition.snowstorm:
                    binyu = snowstorm.SelectRandomString();
                    break;
                case WeatherCondition.sleet:
                case WeatherCondition.rain_snow:
                    binyu = sleet.SelectRandomString();
                    break;
                case WeatherCondition.shower_snow:
                case WeatherCondition.snow_flurry:
                    binyu = shower_snow.SelectRandomString();
                    break;
                case WeatherCondition.mist:
                    binyu = mist.SelectRandomString();
                    break;
                case WeatherCondition.foggy:
                    binyu = foggy.SelectRandomString();
                    break;
                case WeatherCondition.haze:
                    binyu = haze.SelectRandomString();
                    break;
                case WeatherCondition.sand:
                case WeatherCondition.dust:
                    binyu = dust.SelectRandomString();
                    break;
                case WeatherCondition.volcanic_ash:
                case WeatherCondition.duststorm:
                case WeatherCondition.sandstorm:
                    binyu = duststorm.SelectRandomString();
                    break;
                case WeatherCondition.hot:
                    binyu = loader.GetString("bianre");
                    break;
                case WeatherCondition.cold:
                    binyu = loader.GetString("bianleng");
                    break;
                default: return loader.GetString("unknown_weather");
            }
            string nowtemp;
            string tomorrowtemp;
            switch (parameter)
            {
                case TemperatureParameter.Celsius:
                    nowtemp = model.DailyForecast[todayIndex].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex].HighTemp.Celsius + '°';
                    tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex + 1].HighTemp.Celsius + '°';
                    break;
                case TemperatureParameter.Fahrenheit:
                    nowtemp = model.DailyForecast[todayIndex + 0].LowTemp.Fahrenheit + "°~" + model.DailyForecast[todayIndex + 0].HighTemp.Fahrenheit + '°';
                    tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Fahrenheit + "°~" + model.DailyForecast[todayIndex + 1].HighTemp.Fahrenheit + '°';
                    break;
                case TemperatureParameter.Kelvin:
                    nowtemp = model.DailyForecast[todayIndex + 0].LowTemp.Kelvin + "K~" + model.DailyForecast[todayIndex + 0].HighTemp.Kelvin + "K";
                    tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Kelvin + "K~" + model.DailyForecast[todayIndex + 1].HighTemp.Kelvin + "K";
                    break;
                default:
                    nowtemp = model.DailyForecast[todayIndex + 0].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex + 0].HighTemp.Celsius + "°";
                    tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex + 1].HighTemp.Celsius + "°";
                    break;
            }
            string tomorrowcondition;
            var converter = new ConditiontoTextConverter();
            tomorrowcondition = (string)converter.Convert(model.DailyForecast[todayIndex + 1].Condition.DayCond, null, null, null);
            return string.Format(loader.GetString("GlanceFull"), zhuyu, binyu, decoration, nowtemp, tomorrowcondition, tomorrowtemp);
        }

        internal static string GenerateLockDetailDescription(HeWeatherModel model, bool isNight, TemperatureParameter parameter, DateTime desiredDate)
        {
            var todayIndex = Array.FindIndex(model.DailyForecast, x =>
            {
                return x.Date.Date == desiredDate.Date;
            });
            if (isNight && desiredDate.Hour < 12)
            {
                todayIndex--;
            }
            if (todayIndex < 0)
            {
                todayIndex = 0;
            }
            var 主语 = model.NowWeather.Now.Condition;
            string zhuyu = loader.GetString("xianzai");
            if (Tools.Random.Next(200) >= 100)
            {
                if (isNight)
                {
                    主语 = model.DailyForecast[todayIndex].Condition.NightCond;
                    zhuyu = loader.GetString("wanjian");
                }
                else
                {
                    主语 = model.DailyForecast[todayIndex].Condition.DayCond;
                    zhuyu = loader.GetString("jintian");
                }
            }
            string binyu;
            StringBuilder decoration = new StringBuilder();
            if (Tools.Random.Next(200) >= 100)
            {
                if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius < 0)
                {
                    decoration.Append(wendudi.SelectRandomString() + ", ");
                }
                else if (Tools.Random.Next(200) >= 100 && model.NowWeather.Temprature.Celsius > 25)
                {
                    decoration.Append(wendugao.SelectRandomString() + ", ");
                }
                if (Tools.Random.Next(200) >= 100 && model.DailyForecast[todayIndex].Humidity > 80)
                {
                    decoration.Append(shiduda[0] + ", ");
                }
                if (model.NowWeather.Visibility != null)
                    if (Tools.Random.Next(200) >= 100 && model.NowWeather.Visibility.KM < 0.5)
                    {
                        decoration.Append(nengjiandudi[0] + ", ");
                    }
                if (Tools.Random.Next(200) >= 100)
                    switch (主语)
                    {
                        case WeatherCondition.unknown:
                            return loader.GetString("unknown_weather");
                        case WeatherCondition.sunny:
                        case WeatherCondition.few_clouds:
                        case WeatherCondition.partly_cloudy:
                        case WeatherCondition.calm:
                        case WeatherCondition.light_breeze:
                        case WeatherCondition.moderate:
                        case WeatherCondition.fresh_breeze:
                            decoration.Append(haotianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.overcast:
                        case WeatherCondition.cloudy:
                        case WeatherCondition.windy:
                            break;
                        case WeatherCondition.strong_breeze:
                        case WeatherCondition.high_wind:
                            break;
                        case WeatherCondition.gale:
                        case WeatherCondition.strong_gale:
                        case WeatherCondition.storm:
                        case WeatherCondition.violent_storm:
                        case WeatherCondition.hurricane:
                        case WeatherCondition.tornado:
                        case WeatherCondition.tropical_storm:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.shower_rain:
                            break;
                        case WeatherCondition.heavy_shower_rain:
                        case WeatherCondition.thundershower:
                        case WeatherCondition.heavy_thunderstorm:
                        case WeatherCondition.hail:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.light_rain:
                        case WeatherCondition.moderate_rain:
                            break;
                        case WeatherCondition.heavy_rain:
                        case WeatherCondition.extreme_rain:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.drizzle_rain:
                            break;
                        case WeatherCondition.storm_rain:
                        case WeatherCondition.heavy_storm_rain:
                        case WeatherCondition.severe_storm_rain:
                        case WeatherCondition.freezing_rain:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.light_snow:
                            break;
                        case WeatherCondition.moderate_snow:
                        case WeatherCondition.heavy_snow:
                        case WeatherCondition.snowstorm:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.sleet:
                        case WeatherCondition.rain_snow:
                        case WeatherCondition.shower_snow:
                        case WeatherCondition.snow_flurry:
                            break;
                        case WeatherCondition.mist:
                            break;
                        case WeatherCondition.foggy:
                        case WeatherCondition.haze:
                        case WeatherCondition.sand:
                        case WeatherCondition.dust:
                        case WeatherCondition.volcanic_ash:
                        case WeatherCondition.duststorm:
                        case WeatherCondition.sandstorm:
                            decoration.Append(huaitianqi.SelectRandomString() + ", ");
                            break;
                        case WeatherCondition.hot:
                        case WeatherCondition.cold:
                            break;
                        default:
                            break;
                    }
            }
            switch (主语)
            {
                case WeatherCondition.unknown:
                    return loader.GetString("unknown_weather");
                case WeatherCondition.sunny:
                    binyu = sunny.SelectRandomString();
                    break;
                case WeatherCondition.cloudy:
                    binyu = cloudy.SelectRandomString();
                    break;
                case WeatherCondition.few_clouds:
                    binyu = few_clouds.SelectRandomString();
                    break;
                case WeatherCondition.partly_cloudy:
                    binyu = partly_cloudy.SelectRandomString();
                    break;
                case WeatherCondition.overcast:
                    binyu = overcast.SelectRandomString();
                    break;
                case WeatherCondition.windy:
                    binyu = windy.SelectRandomString();
                    break;
                case WeatherCondition.calm:
                case WeatherCondition.light_breeze:
                case WeatherCondition.moderate:
                case WeatherCondition.fresh_breeze:
                    binyu = breeze.SelectRandomString();
                    break;
                case WeatherCondition.strong_breeze:
                case WeatherCondition.high_wind:
                case WeatherCondition.gale:
                case WeatherCondition.strong_gale:
                    binyu = gale.SelectRandomString();
                    break;
                case WeatherCondition.storm:
                case WeatherCondition.violent_storm:
                case WeatherCondition.hurricane:
                case WeatherCondition.tornado:
                case WeatherCondition.tropical_storm:
                    binyu = storm.SelectRandomString();
                    break;
                case WeatherCondition.shower_rain:
                case WeatherCondition.heavy_shower_rain:
                    binyu = shower.SelectRandomString();
                    break;
                case WeatherCondition.thundershower:
                case WeatherCondition.heavy_thunderstorm:
                    binyu = thundershower.SelectRandomString();
                    break;
                case WeatherCondition.hail:
                    binyu = hail.SelectRandomString();
                    break;
                case WeatherCondition.drizzle_rain:
                case WeatherCondition.light_rain:
                case WeatherCondition.moderate_rain:
                    binyu = moderate_rain.SelectRandomString();
                    break;
                case WeatherCondition.heavy_rain:
                case WeatherCondition.extreme_rain:
                    binyu = heavy_rain.SelectRandomString();
                    break;
                case WeatherCondition.storm_rain:
                case WeatherCondition.heavy_storm_rain:
                case WeatherCondition.severe_storm_rain:
                    binyu = storm.SelectRandomString();
                    break;
                case WeatherCondition.freezing_rain:
                    binyu = freezing_rain.SelectRandomString();
                    break;
                case WeatherCondition.light_snow:
                case WeatherCondition.moderate_snow:
                    binyu = moderate_snow.SelectRandomString();
                    break;
                case WeatherCondition.heavy_snow:
                    binyu = heavy_snow.SelectRandomString();
                    break;
                case WeatherCondition.snowstorm:
                    binyu = snowstorm.SelectRandomString();
                    break;
                case WeatherCondition.sleet:
                case WeatherCondition.rain_snow:
                    binyu = sleet.SelectRandomString();
                    break;
                case WeatherCondition.shower_snow:
                case WeatherCondition.snow_flurry:
                    binyu = shower_snow.SelectRandomString();
                    break;
                case WeatherCondition.mist:
                    binyu = mist.SelectRandomString();
                    break;
                case WeatherCondition.foggy:
                    binyu = foggy.SelectRandomString();
                    break;
                case WeatherCondition.haze:
                    binyu = haze.SelectRandomString();
                    break;
                case WeatherCondition.sand:
                case WeatherCondition.dust:
                    binyu = dust.SelectRandomString();
                    break;
                case WeatherCondition.volcanic_ash:
                case WeatherCondition.duststorm:
                case WeatherCondition.sandstorm:
                    binyu = duststorm.SelectRandomString();
                    break;
                case WeatherCondition.hot:
                    binyu = loader.GetString("bianre");
                    break;
                case WeatherCondition.cold:
                    binyu = loader.GetString("bianleng");
                    break;
                default: return loader.GetString("unknown_weather");
            }
            string nowtemp;
            string tomorrowtemp;
            switch (parameter)
            {
                case TemperatureParameter.Celsius:
                    nowtemp = model.DailyForecast[todayIndex].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex].HighTemp.Celsius + '°';
                    tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex + 1].HighTemp.Celsius + '°';
                    break;
                case TemperatureParameter.Fahrenheit:
                    nowtemp = model.DailyForecast[todayIndex + 0].LowTemp.Fahrenheit + "°~" + model.DailyForecast[todayIndex + 0].HighTemp.Fahrenheit + '°';
                    tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Fahrenheit + "°~" + model.DailyForecast[todayIndex + 1].HighTemp.Fahrenheit + '°';
                    break;
                case TemperatureParameter.Kelvin:
                    nowtemp = model.DailyForecast[todayIndex + 0].LowTemp.Kelvin + "K~" + model.DailyForecast[todayIndex + 0].HighTemp.Kelvin + "K";
                    tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Kelvin + "K~" + model.DailyForecast[todayIndex + 1].HighTemp.Kelvin + "K";
                    break;
                default:
                    nowtemp = model.DailyForecast[todayIndex + 0].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex + 0].HighTemp.Celsius + "°";
                    tomorrowtemp = model.DailyForecast[todayIndex + 1].LowTemp.Celsius + "°~" + model.DailyForecast[todayIndex + 1].HighTemp.Celsius + "°";
                    break;
            }
            string tomorrowcondition;
            var converter = new ConditiontoTextConverter();
            tomorrowcondition = (string)converter.Convert(model.DailyForecast[todayIndex + 1].Condition.DayCond, null, null, null);
            return string.Format(loader.GetString("LockDetail"), zhuyu, binyu, decoration, nowtemp, tomorrowcondition, tomorrowtemp);
        }
    }
}


text:
require 'stringio'

class Net::HTTPGenericRequest
  def to_s
    io = StringIO.new
    exec(io, ::Net::HTTP::HTTPVersion, path)
    io.string
  end
end

redpajama_set_name: RedPajamaGithub


text:
a beginner friendly financial education tool for anyone

[![Circle CI](https://circleci.com/gh/nyc-cicadas-2015/Can-I-Afford-This.svg?style=svg)](https://circleci.com/gh/nyc-cicadas-2015/Can-I-Afford-This)

[![Coverage Status](https://coveralls.io/repos/nyc-cicadas-2015/Can-I-Afford-This/badge.svg?branch=master&service=github)](https://coveralls.io/github/nyc-cicadas-2015/Can-I-Afford-This?branch=master)

####Made with <3 by: [Dian Pan](https://github.com/dianpan) and [Julianna Rusak](https://github.com/julrusak)
Pulling from personal experience, we aim to educate young adults on the risks of acquiring debt at a young age.

[Trello Board](https://trello.com/b/PP3LXD4i)

##User Stories
- I want to buy an iPhone, can I afford it with the amount of money I currently make and spend
- I want to buy a Macbook pro, can I afford it with the amount of money I currently make and spend
- I want to buy a car, can I afford it with the amount of money I currently make and spend

##MVP
- user can register
- user can login
- user is prompted to input monthly income
- user is prompted to input monthly expense sheet
- user can see data visualization of their expense vs income
- user can see what % of expenses go to which category
- user can select 3 types of planned purchases:
  - $ under 1K (ie beats headphones, iphone) /  limit payoff time: 6 months
  - $$ 1K-3K (ie macbook pro) / limit payoff time: 1 year
  - $$$ 3K+ (ie car) / limit payoff time: 5 years
- user can, input price of item seeking to purchase
- user can see data visualization of all of their planned purchases
- user can see, based on existing expense vs. income level if they can afford to make purchase
  - yes you can afford it, you have $X left over each month, save it and it will take you #X of months
  - no you cannot afford it, based on national spend average, try to cut back on xyz category
    - user can edit original expense sheet
    - user can compare expense sheet against national average
    - user's new updated data chart can fluctuate as they make edits

##Stretches
- user can input a URL of the item they are seeking to purchases
- user can see baseline national spend numbers against their spendings
- users can plan to open a credit card (to decode financial jargon, highlight most important terms)
- users can plan to apply for a loan - these are the risks, average range of % of interest across loan types
- user can read and/or give tips and tricks
- Use an API to pull in current spend data


text:
package org.apache.directory.api.ldap.extras.extended.ads_impl.certGeneration;

import org.apache.directory.api.asn1.ber.grammar.Grammar;
import org.apache.directory.api.asn1.ber.grammar.States;

/**
 * This class store the CertGeneration's grammar constants. It is also used
 * for debugging purposes.
 *
 * @author Apache Directory Project
 */
public enum CertGenerationStatesEnum implements States
{

    /** The END_STATE */
    END_STATE,

    /** start state*/
    START_STATE,

    /** sequence*/
    CERT_GENERATION_REQUEST_SEQUENCE_STATE,

    /** the target Dn*/
    TARGETDN_STATE,

    /** the issuer Dn*/
    ISSUER_STATE,

    /** the subject Dn*/
    SUBJECT_STATE,

    /** the key algorithm*/
    KEY_ALGORITHM_STATE,

    /** terminal state */
    LAST_CERT_GENERATION_STATE;

    /**
     * Get the grammar name
     *
     * @param grammar The grammar class
     * @return The grammar name
     */
    public String getGrammarName( Grammar<CertGenerationContainer> grammar )
    {
        return "CERT_GENERATION_GRAMMER";
    }

    /**
     * Get the grammar name
     *
     * @param grammar The grammar code
     * @return The grammar name
     */
    public String getGrammarName( int grammar )
    {
        return "CERT_GENERATION_GRAMMER";
    }

    /**
     * Get the string representing the state
     *
     * @param state The state number
     * @return The String representing the state
     */
    public String getState( int state )
    {
        return ( ( state == END_STATE.ordinal() ) ? "CERT_GENERATION_END_STATE" : this.name() );
    }

    /**
     * {@inheritDoc}
     */
    public boolean isEndState()
    {
        return this == END_STATE;
    }

    /**
     * {@inheritDoc}
     */
    public CertGenerationStatesEnum getStartState()
    {
        return START_STATE;
    }
}


text:
package org.apache.camel.util;

import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.CharBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.apache.camel.util.BufferCaster.cast;

public final class Scanner implements Iterator<String>, Closeable {

    static {
        WHITESPACE_PATTERN = Pattern.compile("\\s+");
        FIND_ANY_PATTERN = Pattern.compile("(?s).*");
    }

    private static final Map<String, Pattern> CACHE = new LinkedHashMap<String, Pattern>() {
        @Override
        protected boolean removeEldestEntry(Entry<String, Pattern> eldest) {
            return size() >= 7;
        }
    };

    private static final Pattern WHITESPACE_PATTERN;

    private static final Pattern FIND_ANY_PATTERN;

    private static final int BUFFER_SIZE = 1024;

    private Readable source;
    private Pattern delimPattern;
    private Matcher matcher;
    private CharBuffer buf;
    private int position;
    private boolean inputExhausted;
    private boolean needInput;
    private boolean skipped;
    private int savedPosition = -1;
    private boolean closed;
    private IOException lastIOException;

    public Scanner(InputStream source, String charsetName, String pattern) {
        this(new InputStreamReader(Objects.requireNonNull(source, "source"), toDecoder(charsetName)), cachePattern(pattern));
    }

    public Scanner(File source, String charsetName, String pattern) throws FileNotFoundException {
        this(new FileInputStream(Objects.requireNonNull(source, "source")).getChannel(), charsetName, pattern);
    }

    public Scanner(String source, String pattern) {
        this(new StringReader(Objects.requireNonNull(source, "source")), cachePattern(pattern));
    }

    public Scanner(String source, Pattern pattern) {
        this(new StringReader(Objects.requireNonNull(source, "source")), pattern);
    }

    public Scanner(ReadableByteChannel source, String charsetName, String pattern) {
        this(Channels.newReader(Objects.requireNonNull(source, "source"), toDecoder(charsetName), -1), cachePattern(pattern));
    }

    public Scanner(Readable source, String pattern) {
        this(Objects.requireNonNull(source, "source"), cachePattern(pattern));
    }

    private Scanner(Readable source, Pattern pattern) {
        this.source = source;
        delimPattern = pattern != null ? pattern : WHITESPACE_PATTERN;
        buf = CharBuffer.allocate(BUFFER_SIZE);
        cast(buf).limit(0);
        matcher = delimPattern.matcher(buf);
        matcher.useTransparentBounds(true);
        matcher.useAnchoringBounds(false);
    }

    private static CharsetDecoder toDecoder(String charsetName) {
        try {
            Charset cs = charsetName != null ? Charset.forName(charsetName) : Charset.defaultCharset();
            return cs.newDecoder();
        } catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
            throw new IllegalArgumentException(e);
        }
    }

    @Override
    public boolean hasNext() {
        checkClosed();
        saveState();
        while (!inputExhausted) {
            if (hasTokenInBuffer()) {
                revertState();
                return true;
            }
            readMore();
        }
        boolean result = hasTokenInBuffer();
        revertState();
        return result;
    }

    @Override
    public String next() {
        checkClosed();
        while (true) {
            String token = getCompleteTokenInBuffer();
            if (token != null) {
                skipped = false;
                return token;
            }
            if (needInput) {
                readMore();
            } else {
                throwFor();
            }
        }
    }

    private void saveState() {
        savedPosition = position;
    }

    private void revertState() {
        position = savedPosition;
        savedPosition = -1;
        skipped = false;
    }

    private void readMore() {
        if (buf.limit() == buf.capacity()) {
            expandBuffer();
        }
        int p = buf.position();
        cast(buf).position(buf.limit());
        cast(buf).limit(buf.capacity());
        int n;
        try {
            n = source.read(buf);
        } catch (IOException ioe) {
            lastIOException = ioe;
            n = -1;
        }
        if (n == -1) {
            inputExhausted = true;
            needInput = false;
        } else if (n > 0) {
            needInput = false;
        }
        cast(buf).limit(buf.position());
        cast(buf).position(p);
    }

    private void expandBuffer() {
        int offset = savedPosition == -1 ? position : savedPosition;
        cast(buf).position(offset);
        if (offset > 0) {
            buf.compact();
            translateSavedIndexes(offset);
            position -= offset;
            cast(buf).flip();
        } else {
            int newSize = buf.capacity() * 2;
            CharBuffer newBuf = CharBuffer.allocate(newSize);
            newBuf.put(buf);
            cast(newBuf).flip();
            translateSavedIndexes(offset);
            position -= offset;
            buf = newBuf;
            matcher.reset(buf);
        }
    }

    private void translateSavedIndexes(int offset) {
        if (savedPosition != -1) {
            savedPosition -= offset;
        }
    }

    private void throwFor() {
        skipped = false;
        if (inputExhausted && position == buf.limit()) {
            throw new NoSuchElementException();
        } else {
            throw new InputMismatchException();
        }
    }

    private boolean hasTokenInBuffer() {
        matcher.usePattern(delimPattern);
        matcher.region(position, buf.limit());
        if (matcher.lookingAt()) {
            position = matcher.end();
        }
        return position != buf.limit();
    }

    private String getCompleteTokenInBuffer() {
        matcher.usePattern(delimPattern);
        if (!skipped) {
            matcher.region(position, buf.limit());
            if (matcher.lookingAt()) {
                if (matcher.hitEnd() && !inputExhausted) {
                    needInput = true;
                    return null;
                }
                skipped = true;
                position = matcher.end();
            }
        }
        if (position == buf.limit()) {
            if (inputExhausted) {
                return null;
            }
            needInput = true;
            return null;
        }
        matcher.region(position, buf.limit());
        boolean foundNextDelim = matcher.find();
        if (foundNextDelim && (matcher.end() == position)) {
            foundNextDelim = matcher.find();
        }
        if (foundNextDelim) {
            if (matcher.requireEnd() && !inputExhausted) {
                needInput = true;
                return null;
            }
            int tokenEnd = matcher.start();
            matcher.usePattern(FIND_ANY_PATTERN);
            matcher.region(position, tokenEnd);
            if (matcher.matches()) {
                String s = matcher.group();
                position = matcher.end();
                return s;
            } else {
                return null;
            }
        }
        if (inputExhausted) {
            matcher.usePattern(FIND_ANY_PATTERN);
            matcher.region(position, buf.limit());
            if (matcher.matches()) {
                String s = matcher.group();
                position = matcher.end();
                return s;
            }
            return null;
        }
        needInput = true;
        return null;
    }

    private void checkClosed() {
        if (closed) {
            throw new IllegalStateException();
        }
    }

    @Override
    public void close() throws IOException {
        if (!closed) {
            closed = true;
            if (source instanceof Closeable) {
                try {
                    ((Closeable) source).close();
                } catch (IOException e) {
                    lastIOException = e;
                }
            }
        }
        if (lastIOException != null) {
            throw lastIOException;
        }
    }

    private static Pattern cachePattern(String pattern) {
        if (pattern == null) {
            return null;
        }
        synchronized (CACHE) {
            return CACHE.computeIfAbsent(pattern, Pattern::compile);
        }
    }

}


text:
[Stackdriver Logging][logging]  allows you to store, search, analyze, monitor,
and alert on log data and events from Google Cloud Platform and Amazon Web
Services.
These sample Java applications demonstrate how to access the Cloud Storage API using
the [Google Cloud Client Library for Java][google-cloud-java].

[logging]: https://cloud.google.com/logging/
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java

## Quickstart

Install [Maven](http://maven.apache.org/).

Build your project with:

	mvn clean package -DskipTests

You can then run a given `ClassName` via:

	mvn exec:java -Dexec.mainClass=com.example.logging.ClassName \
	    -DpropertyName=propertyValue \
		-Dexec.args="any arguments to the app"

### Writing a log entry (using the quickstart sample)

    mvn exec:java -Dexec.mainClass=com.example.logging.QuickstartSample \
        -Dexec.args="my-log"


text:
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg?style=flat)](https://raw.githubusercontent.com/ansiblebit/oracle-java/master/LICENSE)
[![Build Status](https://travis-ci.org/ansiblebit/oracle-java.svg?branch=master)](https://travis-ci.org/ansiblebit/oracle-java)

[![Platform](http://img.shields.io/badge/platform-centos-932279.svg?style=flat)](#)
[![Platform](http://img.shields.io/badge/platform-debian-a80030.svg?style=flat)](#)
[![Platform](http://img.shields.io/badge/platform-redhat-cc0000.svg?style=flat)](#)
[![Platform](http://img.shields.io/badge/platform-ubuntu-dd4814.svg?style=flat)](#)

[![Project Stats](https://www.openhub.net/p/ansiblebit-oracle-java/widgets/project_thin_badge.gif)](https://www.openhub.net/p/ansiblebit-oracle-java/)

An [Ansible](http://www.ansible.com) role to setup Oracle Java Development Kit.

DISCLAIMER: usage of any version of this role implies you have accepted the
[Oracle Binary Code License Agreement for Java SE](http://www.oracle.com/technetwork/java/javase/terms/license/index.html).

## Tests

| Family | Distribution | Version | Test Status |
|:-:|:-:|:-:|:-:|
| Debian | Debian  | Jessie    | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#) |
| Debian | Debian  | Wheezy    | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#) |
| Debian | Ubuntu  | Precise   | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#)  |
| Debian | Ubuntu  | Trusty    | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#) |
| Debian | Ubuntu  | Vivid     | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#) |
| RedHat | CentOS  | 6.4       | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#) |
| RedHat | CentOS  | 6.6       | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#) |
| RedHat | Centos  | 7         | [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#) |

## Requirements

- ansible >= 1.9.2

# Facts
| variable | description |
|:-:|:--|
| oracle_java_installed         | fact set by this role that contains a flag that indicates if Java is installed on the host. |
| oracle_java_version_installed | fact set by this role that contains the string of the Java version installed in the system. |

## Role Variables

| variable | default | description |
|:--------:|:-------:|:------------|
| oracle_java_set_as_default | no | make the newly installed Java the default runtime environment. |
| oracle_java_state   | latest | the package state (see Ansible apt module for more information). |
| oracle_java_version | 8 | the Oracle JDK version to be installed. |
| oracle_java_version_update | 45 | the Oracle JDK version update. |
| oracle_java_version_build | 14 | the Oracle JDK version update build number. |
| oracle_java_version_string | 1.{{ oracle_java_version }}.0_u{{ oracle_java_version_update }} | the Java version string to verify installation against. |
| oracle_java_os_supported variable | - | role internal variable to check if a OS family is supported or not. |

### Debian-only

| variable | default | description |
|:-:|:-:|:--|
| launchpad_ppa_webupd8_cache_valid_time | 3600 | the amount of time in seconds the apt cache is valid. |
| oracle_java_cache_valid_time | 3600 | the amount of time in seconds the apt cache is valid. |
| oracle_java_state   | latest | the package state (see Ansible apt module for more information). |
| oracle_java_home | /usr/lib/jvm/java-{{ oracle_java_version }}-oracle | the location of the Java home directory. |

### Redhat-only

| variable | default | description |
|:-:|:-:|:--|
| oracle_java_dir_source | /usr/local/src | directory where to store the RPM files. |
| oracle_java_home | /usr/java/jdk1.{{ oracle_java_version }}.0_{{ oracle_java_version_update }} | the location of the Java home directory. |
| oracle_java_rpm_filename | jdk-{{ oracle_java_version }}u{{ oracle_java_version_update }}-linux-x64.rpm | the filename of the RPM. |
| oracle_java_rpm_url | http://download.oracle.com/otn-pub/java/jdk/{{ oracle_java_version }}u{{ oracle_java_version_update }}-b{{ oracle_java_version_build }}/{{ oracle_java_rpm_filename }} | the URL where the RPM can be downloaded from. |

## Dependencies

For Debian and Ubuntu this role depends on:

- ansiblebit.launchpad-ppa-webupd8

## Playbooks

    - hosts: servers
      roles:
         - { role: ansiblebit.oracle-java,
             oracle_java_set_as_default: yes }

Use `--skip-tags=debug` if you want to suppress debug information.

## Changelog

- v4.7.2 : 24 Aug 2015
    - usage of alternatives module to set Java default version on RedHat environments
    - updated default version to Java 1.8u60-b27
    - NOTE: Debian systems will always install the latest version of the JDK
    - improved RPM download task on RedHat environments
    - fixed problem with task setting default JDK always flagging itself as changed
    - removed support for Ansible 1.8
- v4.7.0 : 16 Jul 2015
    - added building blocks for MacOSX support
    - minor version number will now match primogen major version number
    - merge with ansiblebit.primogen v7
        - upgrade tests to use ansible v1.9.2 instead of v1.9.1
        - pass ANSIBLE_ASK_SUDO_PASS environment variable to the tox test environment
        - improved idempotence test
- v4.0.0 : 13 May 2015
    - added support for RedHat-based systems
    - separated Debian from Redhat variables
    - oracle_java_default (default:no) replaced by oracle_java_set_default (default:no)
    - directory structure changes
        - tasks/os_family/<family name>.yml changed in favor of task/<family name>/main.yml
    - added debug task
    - role-specific facts now used to set if an installation process is necessary in Debian or RedHat
    - fixed build issues related to tox 2.0.1
- v3.0.2 : 8 May 2015
    - added oracle_java_home variable
- v3.0.0 : 7 May 2015
    - synchronized major version with primogen for easier reference
    - updated ansiblebit.launchpad-ppa-webupd8 == 3.0.0
    - merged primogen v3.0.4
- v1.0.4 : 5 May 2015
    - standardized tests with primogen v2.2.0
    - implementation of CentOS deployment
- v1.0.2 : 30 April 2015
    - added support for Ubuntu vivid
    - added support for Debian jessie
- v1.0.0 : 30 April 2015
    - initial release of this role with support for Debian
    - dependency on ansiblebit.launchpad-ppa-webupd8 v1.1.0
    - ansible dependency set to 1.8.4

## License

BSD

## Author Information

- [steenzout](http://github.com/steenzout)


text:
module.exports = {
  clearMocks: true,
  testEnvironment: 'jsdom',
  verbose: true,
};


text:
package io.dropwizard.testing.junit;

import io.dropwizard.testing.DropwizardTestSupport;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;

import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.times;

public class DropwizardAppRuleReentrantTest {

    @Rule
    public MockitoRule mockitoRule = MockitoJUnit.rule();

    @Mock
    DropwizardTestSupport<TestConfiguration> testSupport;

    @Mock
    Statement statement;

    @Mock
    Description description;

    @Test
    public void testReentrantRuleStartsApplicationOnlyOnce() throws Throwable {
        DropwizardAppRule<TestConfiguration> dropwizardAppRule = new DropwizardAppRule<>(testSupport);

        RuleChain.outerRule(dropwizardAppRule)
            .around(dropwizardAppRule) // recursive
            .apply(statement, description)
            .evaluate();

        InOrder inOrder = inOrder(testSupport, statement, description);
        inOrder.verify(testSupport, times(1)).before();
        inOrder.verify(statement).evaluate();
        inOrder.verify(testSupport, times(1)).after();
        inOrder.verifyNoMoreInteractions();
    }
}


text:
package org.apache.http.io;

import java.io.IOException;

import org.apache.http.util.CharArrayBuffer;

/**
 * Session output buffer for blocking connections.
 *
 * @author Oleg Kalnichevski
 *
 * @version $Revision: 560528 $
 *
 * @since 4.0
 */
public interface SessionOutputBuffer {

    void write(byte[] b, int off, int len) throws IOException;

    void write(byte[] b) throws IOException;

    void write(int b) throws IOException;

    void writeLine(String s) throws IOException;

    void writeLine(CharArrayBuffer buffer) throws IOException;

    void flush() throws IOException;

    HttpTransportMetrics getMetrics();

}


text:
<!DOCTYPE html>
<html>
  <head>
    <title>Listing 4.14</title>
    <script type="text/javascript" src="../scripts/assert.js"></script>
    <link href="../styles/assert.css" rel="stylesheet" type="text/css">
  </head>

  <body>
    <script type="text/javascript">

      function multiMax(multi){
        return multi * Math.max.apply(Math,
          Array.prototype.slice.call(arguments, 1));           //#1
      }

      assert(multiMax(3, 1, 2, 3) == 9,
             "3*3=9 (First arg, by largest.)");

    </script>
  </body>
</html>