public override bool Equals(VirtualValue other) { if (!(other is MapValue)) { return(false); } MapValue that = ( MapValue )other; int size = size(); if (size != that.Size()) { return(false); } IEnumerable <string> keys = KeySet(); foreach (string key in keys) { if (!Get(key).Equals(that.Get(key))) { return(false); } } return(true); }
private void AssertMapValueEquals(MapValue a, MapValue b) { assertThat(a, equalTo(b)); assertThat(a.Size(), equalTo(b.Size())); assertThat(a.GetHashCode(), equalTo(b.GetHashCode())); assertThat(a.Keys, containsInAnyOrder(Iterables.asArray(typeof(string), b.Keys))); assertThat(Arrays.asList(a.Keys().asArray()), containsInAnyOrder(b.Keys().asArray())); a.Foreach((k, v) => assertThat(b.Get(k), equalTo(v))); b.Foreach((k, v) => assertThat(a.Get(k), equalTo(v))); }
public override bool?TernaryEquals(AnyValue other) { if (other == null || other == NO_VALUE) { return(null); } else if (!(other is MapValue)) { return(false); } MapValue otherMap = ( MapValue )other; int size = size(); if (size != otherMap.Size()) { return(false); } //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: string[] thisKeys = StreamSupport.stream(KeySet().spliterator(), false).toArray(string[] ::new); Arrays.sort(thisKeys, string.compareTo); //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: string[] thatKeys = StreamSupport.stream(otherMap.Keys.spliterator(), false).toArray(string[] ::new); Arrays.sort(thatKeys, string.compareTo); for (int i = 0; i < size; i++) { if (thisKeys[i].CompareTo(thatKeys[i]) != 0) { return(false); } } bool?equalityResult = true; for (int i = 0; i < size; i++) { string key = thisKeys[i]; bool? s = Get(key).ternaryEquals(otherMap.Get(key)); if (s == null) { equalityResult = null; } else if (!s.Value) { return(false); } } return(equalityResult); }
public override int CompareTo(VirtualValue other, IComparer <AnyValue> comparator) { if (!(other is MapValue)) { throw new System.ArgumentException("Cannot compare different virtual values"); } MapValue otherMap = ( MapValue )other; int size = size(); int compare = Integer.compare(size, otherMap.Size()); if (compare == 0) { //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: string[] thisKeys = StreamSupport.stream(KeySet().spliterator(), false).toArray(string[] ::new); Arrays.sort(thisKeys, string.compareTo); //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: string[] thatKeys = StreamSupport.stream(otherMap.Keys.spliterator(), false).toArray(string[] ::new); Arrays.sort(thatKeys, string.compareTo); for (int i = 0; i < size; i++) { compare = thisKeys[i].CompareTo(thatKeys[i]); if (compare != 0) { return(compare); } } for (int i = 0; i < size; i++) { string key = thisKeys[i]; compare = comparator.Compare(Get(key), otherMap.Get(key)); if (compare != 0) { return(compare); } } } return(compare); }