Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
Support.cs
Go to the documentation of this file.
1 /*
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20 */
21 
22 using System;
23 using System.Collections.Generic;
24 using System.Text;
25 
26 namespace Lucene.Net.Search.Vectorhighlight
27 {
28  public class HashMap<K, V> : Dictionary<K, V>
29  {
30  V _NullKeyValue = default(V);
31 
32  public new void Add(K key,V value)
33  {
34  if (key == null)
35  _NullKeyValue = value;
36  else
37  base.Add(key,value);
38  }
39 
40  public new int Count
41  {
42  get
43  {
44  return base.Count + (_NullKeyValue!= null ? 1 : 0);
45  }
46  }
47 
48  public new V this[K key]
49  {
50  get{
51  return Get(key);
52  }
53  set{
54  Add(key,value);
55  }
56  }
57 
58  public V Get(K key)
59  {
60  if (key == null) return _NullKeyValue;
61 
62  V v = default(V);
63  base.TryGetValue(key, out v);
64  return v;
65  }
66 
67  public void Put(K key, V val)
68  {
69  Add(key,val);
70  }
71  }
72 }
73