~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Projects.Utility/DiffUtility.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections;
 
3
 
 
4
namespace MonoDevelop.Projects.Utility 
 
5
{
 
6
        internal class DiffUtility
 
7
        {
 
8
                public static int GetAddedItems(IList original, IList changed, IList result)
 
9
                {
 
10
                        return GetAddedItems(original, changed, result, Comparer.Default);
 
11
                }
 
12
                
 
13
                public static int GetAddedItems(IList original, IList changed, IList result, IComparer comparer)
 
14
                {
 
15
                        int count = 0;
 
16
                        if(changed != null && result != null) {
 
17
                                if(original == null) {
 
18
                                        foreach(object item in changed) {
 
19
                                                result.Add(item);
 
20
                                        }
 
21
                                        count = changed.Count;
 
22
                                }
 
23
                                else {
 
24
                                        foreach(object item in changed) {
 
25
                                                if(!Contains(original, item, comparer)) {
 
26
                                                        result.Add(item);
 
27
                                                        count++;
 
28
                                                }
 
29
                                        }
 
30
                                }
 
31
                        }
 
32
                        return count;
 
33
                }
 
34
                
 
35
                public static int GetRemovedItems(IList original, IList changed, IList result)
 
36
                {
 
37
                        return GetRemovedItems(original, changed, result, Comparer.Default);
 
38
                }
 
39
                
 
40
                public static int GetRemovedItems(IList original, IList changed, IList result, IComparer comparer)
 
41
                {
 
42
                        return GetAddedItems(changed, original, result, comparer);
 
43
                }
 
44
                
 
45
                static bool Contains(IList list, object value, IComparer comparer)
 
46
                {
 
47
                        foreach(object item in list) {
 
48
                                if(0 == comparer.Compare(item, value)) {
 
49
                                        return true;
 
50
                                }
 
51
                        }
 
52
                        return false;
 
53
                }
 
54
                
 
55
                static public int Compare(IList a, IList b)
 
56
                {
 
57
                        return Compare(a, b, Comparer.Default);
 
58
                }
 
59
                
 
60
                static public int Compare(IList a, IList b, IComparer comparer)
 
61
                {
 
62
                        if (a == null || b == null) {
 
63
                                if (a == b)
 
64
                                        return 0;
 
65
                                else
 
66
                                        return (a == null) ? -1 : 1;
 
67
                        }
 
68
                        int limit = (a.Count < b.Count) ? a.Count : b.Count;
 
69
                        for(int i=0; i < limit; i++) {
 
70
                                if (a[i] is IComparable && b[i] is IComparable) {
 
71
                                        int cmp = comparer.Compare(a[i], b[i]);
 
72
                                        if (cmp != 0) {
 
73
                                                return cmp;
 
74
                                        }
 
75
                                }
 
76
                        }
 
77
                        return a.Count - b.Count;
 
78
                }
 
79
                
 
80
                static public int Compare(SortedList a, SortedList b)
 
81
                {
 
82
                        return Compare(a, b, Comparer.Default);
 
83
                }
 
84
                
 
85
                static public int Compare(SortedList a, SortedList b, IComparer comparer)
 
86
                {
 
87
                        if (a == null || b == null) {
 
88
                                if (a == b)
 
89
                                        return 0;
 
90
                                else
 
91
                                        return (a == null) ? -1 : 1;
 
92
                        }
 
93
                        int cmp;
 
94
                        int limit = (a.Count < b.Count) ? a.Count : b.Count;
 
95
                        for(int i=0; i < limit; i++) {
 
96
                                if(0 != (cmp = comparer.Compare(a.GetByIndex(i), b.GetByIndex(i)))) {
 
97
                                        return cmp;
 
98
                                }
 
99
                        }
 
100
                        return a.Count - b.Count;
 
101
                }
 
102
        }
 
103
}