Kinetica   C#   API  Version 7.2.3.0
ArraySchema.cs
Go to the documentation of this file.
1 
18 using System;
19 using System.Collections.Generic;
20 using Newtonsoft.Json.Linq;
21 
22 namespace Avro
23 {
27  public class ArraySchema : UnnamedSchema
28  {
32  public Schema ItemSchema { get; set; }
33 
41  internal static ArraySchema NewInstance(JToken jtok, PropertyMap props, SchemaNames names, string encspace)
42  {
43  JToken jitem = jtok["items"];
44  if (null == jitem) throw new AvroTypeException("Array does not have 'items'");
45 
46  return new ArraySchema(Schema.ParseJson(jitem, names, encspace), props);
47  }
48 
53  private ArraySchema(Schema items, PropertyMap props) : base(Type.Array, props)
54  {
55  if (null == items) throw new ArgumentNullException("items");
56  this.ItemSchema = items;
57  }
58 
65  protected internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
66  {
67  writer.WritePropertyName("items");
68  ItemSchema.WriteJson(writer, names, encspace);
69  }
70 
76  public override bool CanRead(Schema writerSchema)
77  {
78  if (writerSchema.Tag != Tag) return false;
79 
80  ArraySchema that = writerSchema as ArraySchema;
81  return ItemSchema.CanRead(that.ItemSchema);
82  }
83 
89  public override bool Equals(object obj)
90  {
91  if (this == obj) return true;
92 
93  if (obj != null && obj is ArraySchema)
94  {
95  ArraySchema that = obj as ArraySchema;
96  if (ItemSchema.Equals(that.ItemSchema))
97  return areEqual(that.Props, this.Props);
98  }
99  return false;
100  }
101 
106  public override int GetHashCode()
107  {
108  return 29 * ItemSchema.GetHashCode() + getHashCode(Props);
109  }
110  }
111 }
static int getHashCode(object obj)
Hash code helper function
Definition: Schema.cs:301
override int GetHashCode()
Hash code function
Definition: Schema.cs:272
override bool Equals(object obj)
Function to compare equality of two array schemas
Definition: ArraySchema.cs:89
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: ArraySchema.cs:106
Class for array type schemas
Definition: ArraySchema.cs:27
A class that contains a list of named schemas.
Definition: SchemaName.cs:146
internal override void WriteJsonFields(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
Writes the array schema in JSON format
Definition: ArraySchema.cs:65
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
Schema ItemSchema
Schema for the array 'type' attribute
Definition: ArraySchema.cs:32
Type Tag
Schema type property
Definition: Schema.cs:56
override bool CanRead(Schema writerSchema)
Checks if this schema can read data written by the given schema.
Definition: ArraySchema.cs:76