2 * Copyright (C) 2011 Collabora Ltd.
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or
7 * (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 * Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
19 * Travis Reitter <travis.reitter@collabora.co.uk>
25 * Utility functions to simplify common patterns in Folks client code.
29 public class Folks.Utils : Object
31 internal static bool _str_equal_safe (string a, string b)
33 return (a != "" && b != "" && a.down () == b.down ());
37 * Check whether two multi-maps of strings to strings are equal. This performs
38 * a deep check for equality, checking whether both maps are of the same size,
39 * and that each key maps to the same set of values in both maps.
41 * @param a a multi-map to compare
42 * @param b another multi-map to compare
43 * @return `true` if the multi-maps are equal, `false` otherwise
47 public static bool multi_map_str_str_equal (
48 MultiMap<string, string> a,
49 MultiMap<string, string> b)
56 foreach (var key in a.get_keys ())
60 var a_values = a.get (key);
61 var b_values = b.get (key);
62 if (a_values.size != b_values.size)
65 foreach (var a_value in a_values)
67 if (!b_values.contains (a_value))
86 * Check whether two multi-maps of strings to AbstractFieldDetails are equal.
88 * This performs a deep check for equality, checking whether both maps are of
89 * the same size, and that each key maps to the same set of values in both
92 * @param a a multi-map to compare
93 * @param b another multi-map to compare
94 * @return `true` if the multi-maps are equal, `false` otherwise
98 public static bool multi_map_str_afd_equal (
99 MultiMap<string, AbstractFieldDetails> a,
100 MultiMap<string, AbstractFieldDetails> b)
105 if (a.size == b.size)
107 foreach (var key in a.get_keys ())
109 if (b.contains (key))
111 var a_values = a.get (key);
112 var b_values = b.get (key);
113 if (a_values.size != b_values.size)
116 foreach (var a_value in a_values)
118 if (!b_values.contains (a_value))
137 * Check whether a set of strings to AbstractFieldDetails are equal.
139 * This performs a deep check for equality, checking whether both sets are of
140 * the same size, and that each key maps to the same set of values in both
143 * @param a a set to compare
144 * @param b another set to compare
145 * @return `true` if the sets are equal, `false` otherwise
149 public static bool set_afd_equal (
150 Set<AbstractFieldDetails> a,
151 Set<AbstractFieldDetails> b)
156 if (a.size == b.size)
158 foreach (var val in a)
160 if (!b.contains (val))