Exemplo n.º 1
0
        public static bool AreSimilar <T>(T first, T second)
        {
            try
            {
                if (first == null && second == null)
                {
                    return(true);
                }
                if (first == null & second != null)
                {
                    return(false);
                }
                if (first != null & second == null)
                {
                    return(false);
                }

                CompareFactory <T> objFactory = new CompareFactory <T>();
                objFactory.ComparerType = first;
                string   ObjectType = objFactory.getType();
                ICompare obj        = objFactory.GetObject(ObjectType);
                return(obj.Comparer(first, second));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool IsEqual(object first, object second)
        {
            var lstFirst  = ((IEnumerable)first).Cast <object>().ToList();
            var lstSecond = ((IEnumerable)second).Cast <object>().ToList();

            if (lstFirst.Count != lstSecond.Count)
            {
                return(false);
            }

            for (int iter = 0; iter < lstFirst.Count; iter++)
            {
                ICompare compare = FactoryResolver.ResolveComparer(lstFirst[iter]);

                if (!compare.IsEqual(lstFirst[iter], lstSecond[iter]))
                {
                    return(false);
                }
            }

            //if(!lstFirst.OrderBy(x => x).SequenceEqual(lstSecond))
            //    return false;

            return(true);
        }
Exemplo n.º 3
0
        // MyFunc - use the methods provided by the ICompare interface
        //          to display the value of two objects and then an indication
        //          of which is greater (according to the object itself)
        public static void MyFunc(ICompare ic1, ICompare ic2)
        {
            Console.WriteLine("The value of ic1 is {0} and ic2 is {1}",
                              ic1.GetValue(), ic2.GetValue());

            string s;

            switch (ic1.CompareTo(ic2))
            {
            case 0:
                s = "is equal to";
                break;

            case -1:
                s = "is less than";
                break;

            case 1:
                s = "is greater than";
                break;

            default:
                s = "something messed up";
                break;
            }
            Console.WriteLine(
                "The objects themselves think that ic1 {0} ic2", s);
        }
 /// <summary>
 /// Initializes a new instance of the FormWhoWasBornOnMyBirthday class.
 /// </summary>
 /// <param name="i_Compare">Strategy comparer</param>
 public FormWhoWasBornOnMyBirthday(ICompare i_Compare)
 {
     InitializeComponent();
     Compare        = i_Compare;
     r_Util         = Utils.Utils.Instance;
     m_BirthdayDate = FormMainWindow.Birthday;
 }
 /// <summary>
 /// Initializes a new instance of the FormWhoWasBornOnMyBirthday class.
 /// </summary>
 /// <param name="i_Compare">Strategy comparer</param>
 public FormWhoWasBornOnMyBirthday(ICompare i_Compare)
 {
     InitializeComponent();
     Compare = i_Compare;
     r_Util = Utils.Utils.Instance;
     m_BirthdayDate = FormMainWindow.Birthday;
 }
 public AppHost(IScraper scraper, ICompare compare, IOptions <ScraperConfiguration> config, IFluentEmailFactory fluentEmail)
 {
     _scraper     = scraper;
     _compare     = compare;
     _config      = config.Value;
     _fluentEmail = fluentEmail;
 }
        public bool IsEqual(object first, object second)
        {
            Type type = first.GetType();

            foreach (System.Reflection.PropertyInfo property in type.GetProperties())
            {
                object Object1Value = null;
                object Object2Value = null;

                if (type.GetProperty(property.Name).GetValue(first, null) != null)
                {
                    Object1Value = type.GetProperty(property.Name).GetValue(first, null);
                }

                if (type.GetProperty(property.Name).GetValue(second, null) != null)
                {
                    Object2Value = type.GetProperty(property.Name).GetValue(second, null);
                }

                ICompare compare = FactoryResolver.ResolveComparer(Object1Value);

                if (!compare.IsEqual(Object1Value, Object2Value))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Loads feature according to type
        /// </summary>
        /// <param name="i_FeatureToLoad">Feature to load</param>
        /// <param name="i_Compare">Compare photos</param>
        public void LoadFeature(Type i_FeatureToLoad, ICompare i_Compare)
        {
            foreach (Type type in m_Assembly.GetTypes())
            {
                if (type.IsSubclassOf(typeof(FormFb)) && type.IsPublic && type == i_FeatureToLoad)
                {
                    ConstructorInfo constructorInfo = type.GetConstructor(new Type[] { typeof(ICompare) });
                    if (constructorInfo != null)
                    {
                        FormFb formToLoad = constructorInfo.Invoke(new object[] { i_Compare }) as FormFb;
                        if (formToLoad != null)
                        {
                            if (i_Compare != null)
                            {
                                formToLoad.Compare = i_Compare;
                            }

                            formToLoad.ShowDialog();
                        }

                        return;
                    }
                }
            }
        }
Exemplo n.º 9
0
        public static void Sort(int[][] array, ICompare compare)
        {
            if (array == null || compare == null)
            {
                throw new ArgumentNullException();
            }
            bool swaped;

            for (int i = 0; i < array.Length; i++)
            {
                swaped = false;
                for (int y = 0; y < array.Length - 1; y++)
                {
                    if (compare.Compare(array[y], array[y + 1]) > 0)
                    {
                        Swap(array, y, y + 1);
                        swaped = true;
                    }
                }
                if (!swaped)
                {
                    break;
                }
            }
        }
Exemplo n.º 10
0
        private static ICompare GetCompareOption(CompareFunctionEnum objectToCompare)
        {
            ICompare Strategy = null;

            switch (objectToCompare)
            {
            case CompareFunctionEnum.Dup:
                Strategy = new DuplicateCompare();
                break;

            case CompareFunctionEnum.Unique:
                Strategy = new UniqueCompare();
                break;

            case CompareFunctionEnum.Unique1f2:
                Strategy = new UniqueinConefromCtwoCompare();
                break;

            case CompareFunctionEnum.Unique2f1:
                Strategy = new UniqueinCtwofromConeCompare();
                break;

            default:
                break;
            }
            return(Strategy);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Finds te first row that matches <paramref name="comparer"/> in <paramref name="inColumn"/>
        /// defined as a TD html element. If no match is found, <c>null</c> is returned. This method will look for rows in all
        /// <see cref="Core.TableBody"/> elements but will ignore rows in nested tables.
        /// </summary>
        /// <param name="comparer">The comparer that the cell text must match.</param>
        /// <param name="inColumn">Index of the column to find the text in.</param>
        /// <returns>The searched for <see cref="TableRow"/>; otherwise <c>null</c>.</returns>
        public TableRow FindRowInDirectChildren(ICompare comparer, int inColumn)
        {
            Logger.LogAction("Matching comparer'" + comparer + "' with text in column " + inColumn + " of " + GetType().Name + " '" + Id + "'");

            TableRowAttributeConstraint constraint = new TableRowAttributeConstraint(comparer, inColumn);

            return(FindRowInDirectChildren(constraint));
        }
Exemplo n.º 12
0
        private void compareFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentControl = singleFileDiff;

            singleFileDiff.Visible = true;
            directoryDiff.Visible  = false;
            textDiff.Visible       = false;
        }
Exemplo n.º 13
0
        private void Init(string attributeName, string value, ICompare comparerInstance)
        {
            CheckArgumentNotNullOrEmpty("attributeName", attributeName);

            this.attributeName = attributeName;
            valueToLookFor     = value;
            comparer           = comparerInstance;
        }
Exemplo n.º 14
0
		private void Init(string attributeName, string value, ICompare comparerInstance)
		{
			CheckArgumentNotNullOrEmpty("attributeName", attributeName);

			this.attributeName = attributeName;
			valueToLookFor = value;
			comparer = comparerInstance;
		}
        public comparing_two_users_facade_tests()
        {
            var            customerKey    = ConfigurationManager.AppSettings["CustomerKey"];
            var            customerSecret = ConfigurationManager.AppSettings["CustomerSecret"];
            ITokenProvider tokenProvider  = new OAuthTwitterToken();

            _token   = tokenProvider.GetAsync(customerKey, customerSecret).Result;
            _compare = new Compare();
        }
Exemplo n.º 16
0
        public static bool AreSimilar <T>(T first, T second)
        {
            if (first == null || second == null)
            {
                return(true);
            }

            ICompare compare = FactoryResolver.ResolveComparer(first);

            return(compare.IsEqual(first, second));
        }
Exemplo n.º 17
0
 public PresenterCompare(ICompare view, List<int> selectedPlants)
 {
     this.view = view;
     view.minYear = 2009;
     view.maxYear = 2014;
     this.view.refreshFilters(view.minYear, view.maxYear, getTypes());
     this.view.changeType += OnChangeType;
     this.view.changeFilters += OnChangeType;
     selectedPlantsId = selectedPlants;
     OnChangeType("Загальна генерація", EventArgs.Empty);
     fillDataTable();
 }
Exemplo n.º 18
0
 public PresenterCompare(ICompare view, List <int> selectedPlants)
 {
     this.view    = view;
     view.minYear = 2009;
     view.maxYear = 2014;
     this.view.refreshFilters(view.minYear, view.maxYear, getTypes());
     this.view.changeType    += OnChangeType;
     this.view.changeFilters += OnChangeType;
     selectedPlantsId         = selectedPlants;
     OnChangeType("Загальна генерація", EventArgs.Empty);
     fillDataTable();
 }
 /// <summary>
 /// BubbleSort
 /// </summary>
 /// <param name="array">array with 2 measure</param>
 public static void BubbleSort(int[][] array, ICompare compare)
 {
     for (int i = 0; i < array.Length - 1; i++)
     {
         for (int j = 0; j < array.Length - 1 - i; j++)
         {
             if (compare.CompareTo(array[j], array[j + 1]) > 0)
             {
                 Swap(ref array[j], ref array[j + 1]);
             }
         }
     }
 }
Exemplo n.º 20
0
 public static void BubbleSort(this int[][] jaggedArray, ICompare howToSort)
 {
     for (int i = 0; i < jaggedArray.GetLength(0) - 1; i++)
     {
         for (int j = 1; j <= jaggedArray.GetLength(0) - 1; j++)
         {
             if (howToSort.Compare(jaggedArray[i], jaggedArray[j]) == -1)
             {
                 Swap(ref jaggedArray[i], ref jaggedArray[j]);
             }
         }
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Find the picture with the minimum likes
        /// </summary>
        /// <param name="i_MostLikeablePhotos">Most likeable picture</param>
        /// <param name="i_Compare"></param>
        /// <returns>The photo with the minimum likes</returns>
        private Photo findMinInTopLikable(List <Photo> i_MostLikeablePhotos, ICompare i_Compare)
        {
            Photo minPhoto = i_MostLikeablePhotos[0];

            foreach (Photo photo in i_MostLikeablePhotos)
            {
                if (i_Compare.Decide(minPhoto, photo))
                {
                    minPhoto = photo;
                }
            }

            return(minPhoto);
        }
 public static void SortArr(int[][] jagged, ICompare<int[]> method)
 {
     if (jagged == null) throw new ArgumentNullException("jugged");        
     for (int i = 0; i < jagged.Length; i++)
     {
         for (int j = i + 1; j < jagged.Length; j++)
         {
             if (method.Compare(jagged[i], jagged[j]) > 0)
             {
                 Swap(ref jagged[i], ref jagged[j]);
             }
         }
     }
 }
Exemplo n.º 23
0
 /// <summary>
 /// Sort method.
 /// </summary>
 /// <param name="array"></param>
 /// <param name="size"></param>
 /// <param name="methodOfCompare"></param>
 public void BubbleSort(ref T[] array, int size, ICompare <T> methodOfCompare)
 {
     for (int i = 0; i < size - 1; ++i)
     {
         for (int j = i + 1; j < size; ++j)
         {
             if (methodOfCompare.Compare(array[i], array[j]))
             {
                 T temp = array[i];
                 array[i] = array[j];
                 array[j] = temp;
             }
         }
     }
 }
 public void Sort(ICompare <T> itemComparer)
 {
     for (var i = 0; i < list.Count - 1; i++)
     {
         for (var j = i + 1; j < list.Count; j++)
         {
             var left  = (T)(list[i]);
             var right = (T)(list[j]);
             if (itemComparer.Compare(left, right) > 0)
             {
                 var temp = list[i];
                 list[i] = list[j];
                 list[j] = temp;
             }
         }
     }
 }
Exemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the FormComparedPhotos class.
        /// </summary>
        /// <param name="i_Compare">Strategy comparer</param>
        public FormComparedPhotos(ICompare i_Compare)
        {
            InitializeComponent();
            r_Util  = Utils.Utils.Instance;
            Compare = i_Compare;

            pictureBoxCurrentPic.LoadCompleted += pictureBoxCurrentPic_LoadCompleted;

            m_AllPhotos           = FormMainWindow.AllPhotos;
            m_IndexOfCurrentImage = 0;

            StartPosition = FormStartPosition.CenterScreen;

            pictureBoxIconFeature.Image = Compare.Picture();

            getTopComparedPhotos();
            loadImage(m_TopComparedPhotos[0]);
        }
        private void btnCompare_Click(object sender, EventArgs e)
        {
            try
            {
                String text = rtText.Text;

                String   subText  = tbSubText.Text;
                ICompare comparer = null;

                comparer = ComparerFactory.Get(cbLegacyCompare.Checked ? ComparerFactory.ComparerType.Legacy : ComparerFactory.ComparerType.Yield);

                PrintResults(comparer.Compare(text, subText));
            }
            catch (Exception ex)
            {
                lbResults.Text = ex.Message;
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Initializes a new instance of the FormComparedPhotos class.
        /// </summary>
        /// <param name="i_Compare">Strategy comparer</param>
        public FormComparedPhotos(ICompare i_Compare)
        {
            InitializeComponent();
            r_Util = Utils.Utils.Instance;
            Compare = i_Compare;

            pictureBoxCurrentPic.LoadCompleted += pictureBoxCurrentPic_LoadCompleted;

            m_AllPhotos = FormMainWindow.AllPhotos;
            m_IndexOfCurrentImage = 0;

            StartPosition = FormStartPosition.CenterScreen;

            pictureBoxIconFeature.Image = Compare.Picture();

            getTopComparedPhotos();
            loadImage(m_TopComparedPhotos[0]);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 兩個object比較
        /// </summary>
        /// <param name="compareType">比較的type</param>
        /// <param name="type">型態</param>
        /// <param name="obj1">value 1</param>
        /// <param name="obj2">value 2</param>
        /// <returns></returns>
        public static bool Compare(LkCompareType compareType, Type type, object obj1, object obj2)
        {
            ICompare compare = null;
            bool     result  = false;

            if (type == typeof(double) || type == typeof(long) || type == typeof(int) || type == typeof(float))
            {
                compare = new CompareNumericalFactory(obj1, obj2);
            }
            else if (type == typeof(DateTime))
            {
                compare = new CompareDatetimeFactory(obj1, obj2);
            }

            if (compare != null)
            {
                switch (compareType)
                {
                case LkCompareType.Equal:
                    result = compare.Equal();
                    break;

                case LkCompareType.IsGreaterThen:
                    result = compare.GreaterThen();
                    break;

                case LkCompareType.IsGreaterThenAndEqual:
                    result = compare.GreaterThenAndEqual();
                    break;

                case LkCompareType.IsLessThen:
                    result = compare.LessThen();
                    break;

                case LkCompareType.IsLessThenAndEqual:
                    result = compare.LessThenAndEqual();
                    break;

                default:
                    break;
                }
            }
            return(result);
        }
 public TableRowFinder(ICompare comparer, int inColumn) : base(comparer, inColumn)
 {
 }
 public AttributeConstraint(string attributeName, ICompare comparer) : base(attributeName, comparer)
 {
 }
Exemplo n.º 31
0
 public static void MyFunc(ICompare ic1, ICompare ic2)
 {
     Console.WriteLine("bc1.Compare(bc2) returned {0}", ic1.Compare(ic2));
 }
Exemplo n.º 32
0
 override public int Compare(ICompare ic)
 {
     return(GetValue().CompareTo(ic.GetValue()));
 }
Exemplo n.º 33
0
 abstract public int Compare(ICompare bc);
Exemplo n.º 34
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TableRowAttributeConstraint"/> class.
		/// </summary>
		/// <param name="comparer">The comparer.</param>
		/// <param name="inColumn">The column index in which to look for the value.</param>
		public TableRowAttributeConstraint(ICompare comparer, int inColumn) : base(Find.textAttribute, comparer)
		{
			columnIndex = inColumn;
			containsText = new AlwaysTrueComparer();
		}
Exemplo n.º 35
0
 /// <summary>
 /// MostCommentatedPhotosCommand to execute
 /// </summary>
 /// <param name="i_Type">Type of the feature</param>
 /// <param name="i_Compare">Strategy method</param>
 public void MostCommentatedPhotosCommand(Type i_Type, ICompare i_Compare)
 {
     MostCommentatedPhotos = new MostCommentatedPhotosCommand(() => m_FeaturesFactory.LoadFeature(i_Type, i_Compare));
 }
Exemplo n.º 36
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TableRowAttributeConstraint"/> class.
		/// </summary>
		/// <param name="findText">The text to find (exact match but case insensitive).</param>
		/// <param name="inColumn">The column index in which to look for the value.</param>
		public TableRowAttributeConstraint(string findText, int inColumn) : base(Find.textAttribute, new StringEqualsAndCaseInsensitiveComparer(findText))
		{
			columnIndex = inColumn;
			containsText = new StringContainsAndCaseInsensitiveComparer(findText);
		}
 public static void SortArrDel(int[][] array, ICompare<int[]> comparer)
 {
     SortArrDel(array, (a, b) => comparer.Compare(a, b));
 }
Exemplo n.º 38
0
 /// <summary>
 /// Sort list of photos by number of likes 
 /// </summary>
 /// <param name="io_ListOfPhotos">List of photos</param>
 /// <param name="i_Compare"></param>
 public void SortPhotosByDescendingOrder(List<Photo> io_ListOfPhotos, ICompare i_Compare)
 {
     io_ListOfPhotos.Sort((i_NumberOfLikesPhotoOne, i_NumberOfLikesPhotoTwo) =>
         i_Compare.Sorted(i_NumberOfLikesPhotoOne, i_NumberOfLikesPhotoTwo));
     io_ListOfPhotos.Reverse();
 }
Exemplo n.º 39
0
        public List <string> Compare()
        {
            ICompare compare = GetCompareOption(_function);

            return(compare.Compare(_column1, _column2));
        }
Exemplo n.º 40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StyleAttribute"/> class.
 /// </summary>
 /// <param name="styleAttributeName">Name of the style attribute.</param>
 /// <param name="comparer">The comparer.</param>
 public StyleAttribute(string styleAttributeName, ICompare comparer)
     : base(attributeName + styleAttributeName, comparer)
 {
 }
Exemplo n.º 41
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TableRowAttributeConstraint"/> class.
		/// </summary>
		/// <param name="findTextRegex">The regular expression to match with.</param>
		/// <param name="inColumn">The column index in which to look for the value.</param>
		public TableRowAttributeConstraint(Regex findTextRegex, int inColumn) : base(Find.textAttribute, findTextRegex)
		{
			columnIndex = inColumn;
			containsText = new AlwaysTrueComparer();
		}
Exemplo n.º 42
0
 bool ICompare.IsBigger(ICompare another)
 {
     return(GetArea() > ((Triangle)another).GetArea());
 }
Exemplo n.º 43
0
 /// <summary>
 /// Add photos to list
 /// </summary>
 /// <param name="i_Photo">Photo to add</param>
 /// <param name="io_MinPhoto">Photo with minimum likes</param>
 /// <param name="i_MostComparedPhotos">Most liked photos</param>
 /// <param name="i_Compare"></param>
 private void addPhotoToList(Photo i_Photo, ref Photo io_MinPhoto, List<Photo> i_MostComparedPhotos, ICompare i_Compare)
 {
     i_MostComparedPhotos.Remove(io_MinPhoto);
     i_MostComparedPhotos.Add(i_Photo);
     io_MinPhoto = findMinInTopLikable(i_MostComparedPhotos, i_Compare);
 }
Exemplo n.º 44
0
        /// <summary>
        /// find most likeable photos
        /// </summary>
        /// <param name="i_NumberOfPhotosToShow">number of photos to show</param>
        /// <param name="i_ListOfPhotos">List of photos</param>
        /// <param name="i_Compare">Compare</param>
        /// <returns>Listed Number of photos to show</returns>
        public List<Photo> FindComparedPhotos(int i_NumberOfPhotosToShow, List<Photo> i_ListOfPhotos, ICompare i_Compare)
        {
            List<Photo> topLikeablePhotos = new List<Photo>(i_NumberOfPhotosToShow);

            Photo minPhoto = new Photo();

            foreach (Photo photo in i_ListOfPhotos)
            {
                if (topLikeablePhotos.Count != topLikeablePhotos.Capacity)
                {
                    topLikeablePhotos.Add(photo);
                    minPhoto = findMinInTopLikable(topLikeablePhotos, i_Compare);
                }
                else
                {
                    if (i_Compare.Decide(photo, minPhoto))
                    {
                        addPhotoToList(photo, ref minPhoto, topLikeablePhotos, i_Compare);
                    }
                }
            }

            return topLikeablePhotos;
        }
Exemplo n.º 45
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Name"/> class.
 /// </summary>
 /// <param name="comparer">The comparer.</param>
 public Name(ICompare comparer)
     : base(attributeName, comparer)
 {
 }
Exemplo n.º 46
0
		public AttributeConstraint(string attributeName, ICompare comparer) : base(attributeName, comparer) {}
Exemplo n.º 47
0
        /// <summary>
        /// Find the picture with the minimum likes
        /// </summary>
        /// <param name="i_MostLikeablePhotos">Most likeable picture</param>
        /// <param name="i_Compare"></param>
        /// <returns>The photo with the minimum likes</returns>
        private Photo findMinInTopLikable(List<Photo> i_MostLikeablePhotos, ICompare i_Compare)
        {
            Photo minPhoto = i_MostLikeablePhotos[0];

            foreach (Photo photo in i_MostLikeablePhotos)
            {
                if (i_Compare.Decide(minPhoto, photo))
                {
                    minPhoto = photo;
                }
            }

            return minPhoto;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AttributeConstraint"/> class.
 /// </summary>
 /// <param name="attributeName">Name of the attribute as recognised by Internet Explorer.</param>
 /// <param name="comparer">The comparer.</param>
 public AttributeConstraint(string attributeName, ICompare comparer)
 {
     CheckArgumentNotNull("comparer", comparer);
         Init(attributeName, comparer.ToString(), comparer);
 }
Exemplo n.º 49
0
		public TableRowFinder(ICompare comparer, int inColumn) : base(comparer, inColumn) {}