Kinetica   C#   API  Version 7.2.3.0
SchemaName.cs
Go to the documentation of this file.
1 
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21 
22 namespace Avro
23 {
27  public class SchemaName
28  {
32  public String Name { get; private set; }
33 
37  public String Space { get; private set; }
38 
42  public String EncSpace { get; private set; }
43 
47  public String Fullname { get { return string.IsNullOrEmpty(Namespace) ? this.Name : Namespace + "." + this.Name; } }
48 
52  public String Namespace { get { return string.IsNullOrEmpty(this.Space) ? this.EncSpace : this.Space; } }
53 
60  public SchemaName(String name, String space, String encspace)
61  {
62  if (name == null)
63  { // anonymous
64  this.Name = this.Space = null;
65  this.EncSpace = encspace; // need to save enclosing namespace for anonymous types, so named types within the anonymous type can be resolved
66  }
67  else if (!name.Contains("."))
68  { // unqualified name
69  this.Space = space; // use default space
70  this.Name = name;
71  this.EncSpace = encspace;
72  }
73  else
74  {
75  string[] parts = name.Split('.');
76  this.Space = string.Join(".", parts, 0, parts.Length - 1);
77  this.Name = parts[parts.Length - 1];
78  this.EncSpace = encspace;
79  }
80  }
81 
86  public override string ToString()
87  {
88  return Fullname;
89  }
90 
97  internal void WriteJson(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
98  {
99  if (null != this.Name) // write only if not anonymous
100  {
101  JsonHelper.writeIfNotNullOrEmpty(writer, "name", this.Name);
102  if (!String.IsNullOrEmpty(this.Space))
103  JsonHelper.writeIfNotNullOrEmpty(writer, "namespace", this.Space);
104  else if (!String.IsNullOrEmpty(this.EncSpace)) // need to put enclosing name space for code generated classes
105  JsonHelper.writeIfNotNullOrEmpty(writer, "namespace", this.EncSpace);
106  }
107  }
108 
114  public override bool Equals(Object obj)
115  {
116  if (obj == this) return true;
117  if (obj != null && obj is SchemaName)
118  {
119  SchemaName that = (SchemaName)obj;
120  return areEqual(that.Name, Name) && areEqual(that.Namespace, Namespace);
121  }
122  return false;
123  }
124 
131  private static bool areEqual(object obj1, object obj2)
132  {
133  return obj1 == null ? obj2 == null : obj1.Equals(obj2);
134  }
135 
136  public override int GetHashCode()
137  {
138  return string.IsNullOrEmpty(Fullname) ? 0 : 29 * Fullname.GetHashCode();
139  }
140  }
141 
146  public class SchemaNames
147  {
151  public IDictionary<SchemaName, NamedSchema> Names { get; private set; }
152 
156  public SchemaNames()
157  {
158  Names = new Dictionary<SchemaName, NamedSchema>();
159  }
160 
166  public bool Contains(SchemaName name)
167  {
168  if (Names.ContainsKey(name))
169  return true;
170  return false;
171  }
172 
179  public bool Add(SchemaName name, NamedSchema schema)
180  {
181  if (Names.ContainsKey(name))
182  return false;
183 
184  Names.Add(name, schema);
185  return true;
186  }
187 
193  public bool Add(NamedSchema schema)
194  {
195  SchemaName name = schema.SchemaName;
196  return Add(name, schema);
197  }
198 
207  public bool TryGetValue(string name, string space, string encspace, out NamedSchema schema)
208  {
209  SchemaName schemaname = new SchemaName(name, space, encspace);
210  return Names.TryGetValue(schemaname, out schema);
211  }
212 
217  public IEnumerator<KeyValuePair<SchemaName, NamedSchema>> GetEnumerator()
218  {
219  return Names.GetEnumerator();
220  }
221  }
222 }
String? Fullname
Namespace.Name of the schema
Definition: SchemaName.cs:47
bool TryGetValue(string name, string space, string encspace, out NamedSchema schema)
Tries to get the value for the given name fields
Definition: SchemaName.cs:207
String Name
Name of the schema
Definition: SchemaName.cs:32
IDictionary< SchemaName, NamedSchema > Names
Map of schema name and named schema objects
Definition: SchemaName.cs:151
bool Contains(SchemaName name)
Checks if given name is in the map
Definition: SchemaName.cs:166
override string ToString()
Returns the full name of the schema
Definition: SchemaName.cs:86
String? Namespace
Namespace of the schema
Definition: SchemaName.cs:52
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
SchemaName(String name, String space, String encspace)
Constructor for SchemaName
Definition: SchemaName.cs:60
Class to store schema name, namespace and enclosing namespace
Definition: SchemaName.cs:27
bool Add(NamedSchema schema)
Adds a named schema to the list
Definition: SchemaName.cs:193
A class that contains a list of named schemas.
Definition: SchemaName.cs:146
override int GetHashCode()
Definition: SchemaName.cs:136
override bool Equals(Object obj)
Compares two schema names
Definition: SchemaName.cs:114
bool Add(SchemaName name, NamedSchema schema)
Adds a schema name to the map if it doesn't exist yet
Definition: SchemaName.cs:179
String EncSpace
Namespace from the most tightly enclosing schema
Definition: SchemaName.cs:42
String Space
Namespace specified within the schema
Definition: SchemaName.cs:37
SchemaNames()
Constructor
Definition: SchemaName.cs:156
IEnumerator< KeyValuePair< SchemaName, NamedSchema > > GetEnumerator()
Returns the enumerator for the map
Definition: SchemaName.cs:217
Base class for all named schemas: fixed, enum, record
Definition: NamedSchema.cs:29
SchemaName SchemaName
Name of the schema, contains name, namespace and enclosing namespace
Definition: NamedSchema.cs:34