19 using System.Collections.Generic;
33 private IDictionary<string, object> contents =
new Dictionary<string, object>();
39 public object this[
string fieldName]
41 get {
return contents[fieldName]; }
44 public void Add(
string fieldName,
object fieldValue)
46 if (
Schema.Contains(fieldName))
50 contents[fieldName] = fieldValue;
58 return contents.TryGetValue(fieldName, out result);
61 public override bool Equals(
object obj)
63 if (
this == obj)
return true;
67 return Schema.Equals(other.
Schema) && areEqual(contents, other.contents);
72 private static bool areEqual(IDictionary<string, object> d1, IDictionary<string, object> d2)
74 if (d1.Count == d2.Count)
76 foreach (KeyValuePair<string, object> kv
in d1)
79 if (!d2.TryGetValue(kv.Key, out o))
return false;
80 if (!areEqual(o, kv.Value))
return false;
87 private static bool areEqual(
object o1,
object o2)
89 if (o1 ==
null)
return o2 ==
null;
90 if (o2 ==
null)
return false;
93 if (!(o2 is Array))
return false;
94 return areEqual(o1 as Array, o1 as Array);
96 else if (o1 is IDictionary<string, object>)
98 if (!(o2 is IDictionary<string, object>))
return false;
99 return areEqual(o1 as IDictionary<string, object>, o1 as IDictionary<string, object>);
101 return o1.Equals(o2);
104 private static bool areEqual(Array a1, Array a2)
106 if (a1.Length != a2.Length)
return false;
107 for (
int i = 0; i < a1.Length; i++)
109 if (!areEqual(a1.GetValue(i), a2.GetValue(i)))
return false;
116 return 31 * contents.GetHashCode();
121 StringBuilder sb =
new StringBuilder();
122 sb.Append(
"Schema: ");
124 sb.Append(
", contents: ");
126 foreach (KeyValuePair<string, object> kv
in contents)
134 return sb.ToString();
override int GetHashCode()
void Add(string fieldName, object fieldValue)
override bool Equals(object obj)
Base class for all schema types
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
GenericRecord(RecordSchema schema)
The default type used by GenericReader and GenericWriter for RecordSchema.
override string ToString()
bool TryGetValue(string fieldName, out object result)