Kinetica   C#   API  Version 7.2.3.0
MapSchema.cs
Go to the documentation of this file.
1 
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21 using Newtonsoft.Json.Linq;
22 
23 namespace Avro
24 {
28  public class MapSchema : UnnamedSchema
29  {
33  public Schema ValueSchema { get; set; }
34 
35  public static MapSchema CreateMap(Schema type)
36  {
37  return new MapSchema(type,null);
38  }
39 
47  internal static MapSchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
48  {
49  JToken jvalue = jtok["values"];
50  if (null == jvalue) throw new AvroTypeException("Map does not have 'values'");
51 
52  return new MapSchema(Schema.ParseJson(jvalue, names, encspace), props);
53  }
54 
59  private MapSchema(Schema valueSchema, PropertyMap props) : base(Type.Map, props)
60  {
61  if (null == valueSchema) throw new ArgumentNullException("valueSchema", "valueSchema cannot be null.");
62  this.ValueSchema = valueSchema;
63  }
64 
71  protected internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
72  {
73  writer.WritePropertyName("values");
74  ValueSchema.WriteJson(writer, names, encspace);
75  }
76 
82  public override bool CanRead(Schema writerSchema)
83  {
84  if (writerSchema.Tag != Tag) return false;
85 
86  MapSchema that = writerSchema as MapSchema;
87  return ValueSchema.CanRead(that.ValueSchema);
88  }
89 
95  public override bool Equals(object obj)
96  {
97  if (this == obj) return true;
98 
99  if (obj != null && obj is MapSchema)
100  {
101  MapSchema that = obj as MapSchema;
102  if (ValueSchema.Equals(that.ValueSchema))
103  return areEqual(that.Props, this.Props);
104  }
105  return false;
106  }
107 
112  public override int GetHashCode()
113  {
114  return 29 * ValueSchema.GetHashCode() + getHashCode(Props);
115  }
116  }
117 }
static int getHashCode(object obj)
Hash code helper function
Definition: Schema.cs:301
override int GetHashCode()
Hash code function
Definition: Schema.cs:272
static MapSchema CreateMap(Schema type)
Definition: MapSchema.cs:35
Schema ValueSchema
Schema for map values type
Definition: MapSchema.cs:33
Base class for all unnamed schemas
Base class for all schema types
Definition: Schema.cs:29
virtual bool CanRead(Schema writerSchema)
Returns true if and only if data written using writerSchema can be read using the current schema acco...
Definition: Schema.cs:283
Type
Enum for schema types
Definition: Schema.cs:34
virtual internal void WriteJson(JsonTextWriter writer, SchemaNames names, string encspace)
Writes schema object in JSON format
Definition: Schema.cs:248
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
override int GetHashCode()
Hashcode function
Definition: MapSchema.cs:112
internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
Writes map schema in JSON format
Definition: MapSchema.cs:71
override bool CanRead(Schema writerSchema)
Checks if this schema can read data written by the given schema.
Definition: MapSchema.cs:82
A class that contains a list of named schemas.
Definition: SchemaName.cs:146
Class for map schemas
Definition: MapSchema.cs:28
Schema(Type type, PropertyMap props)
Constructor for schema class
Definition: Schema.cs:67
static bool areEqual(object o1, object o2)
Compares two objects, null is equal to null
Definition: Schema.cs:291
override bool Equals(object obj)
Compares equality of two map schemas
Definition: MapSchema.cs:95
Type Tag
Schema type property
Definition: Schema.cs:56