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
TermVectorOffsetInfo.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 
20 using System.Runtime.InteropServices;
21 
22 namespace Lucene.Net.Index
23 {
24 
25  /// <summary> The TermVectorOffsetInfo class holds information pertaining to a Term in a <see cref="Lucene.Net.Index.TermPositionVector" />'s
26  /// offset information. This offset information is the character offset as set during the Analysis phase (and thus may not be the actual offset in the
27  /// original content).
28  /// </summary>
29  [Serializable]
30  public struct TermVectorOffsetInfo : IEquatable<TermVectorOffsetInfo>
31  {
32  /// <summary> Convenience declaration when creating a <see cref="Lucene.Net.Index.TermPositionVector" /> that stores only position information.</summary>
33  [NonSerialized]
34  public static readonly TermVectorOffsetInfo[] EMPTY_OFFSET_INFO = new TermVectorOffsetInfo[0];
35 
36  [NonSerialized]
37  public static readonly TermVectorOffsetInfo Null = new TermVectorOffsetInfo(int.MinValue, int.MinValue);
38 
39  private int startOffset;
40  private int endOffset;
41 
42  //public TermVectorOffsetInfo()
43  //{
44  //}
45 
46  public TermVectorOffsetInfo(int startOffset, int endOffset)
47  {
48  this.endOffset = endOffset;
49  this.startOffset = startOffset;
50  }
51 
52  /// <summary> The accessor for the ending offset for the term</summary>
53  /// <value> The offset </value>
54  public int EndOffset
55  {
56  get { return endOffset; }
57  set { this.endOffset = value; }
58  }
59 
60  /// <summary> The accessor for the starting offset of the term.
61  ///
62  /// </summary>
63  /// <value> The offset </value>
64  public int StartOffset
65  {
66  get { return startOffset; }
67  set { this.startOffset = value; }
68  }
69 
70  ///// <summary> Two TermVectorOffsetInfos are equals if both the start and end offsets are the same</summary>
71  ///// <param name="o">The comparison Object
72  ///// </param>
73  ///// <returns> true if both <see cref="GetStartOffset()" /> and <see cref="GetEndOffset()" /> are the same for both objects.
74  ///// </returns>
75  //public override bool Equals(System.Object o)
76  //{
77  // if (this == o)
78  // return true;
79  // if (!(o is TermVectorOffsetInfo))
80  // return false;
81 
82  // TermVectorOffsetInfo termVectorOffsetInfo = (TermVectorOffsetInfo) o;
83 
84  // if (endOffset != termVectorOffsetInfo.endOffset)
85  // return false;
86  // if (startOffset != termVectorOffsetInfo.startOffset)
87  // return false;
88 
89  // return true;
90  //}
91 
92  //public override int GetHashCode()
93  //{
94  // int result;
95  // result = startOffset;
96  // result = 29 * result + endOffset;
97  // return result;
98  //}
99 
100 
101  public bool Equals(TermVectorOffsetInfo other)
102  {
103  return startOffset == other.startOffset && endOffset == other.endOffset;
104  }
105 
106  public override bool Equals(object obj)
107  {
108  if (ReferenceEquals(null, obj))
109  {
110  return EndOffset == int.MinValue && StartOffset == int.MinValue;
111  }
112  if (obj.GetType() != typeof (TermVectorOffsetInfo)) return false;
113  return Equals((TermVectorOffsetInfo) obj);
114  }
115 
116  public override int GetHashCode()
117  {
118  unchecked
119  {
120  return (startOffset*397) ^ endOffset;
121  }
122  }
123 
124  public static bool operator ==(TermVectorOffsetInfo left, object right)
125  {
126  return left.Equals(right);
127  }
128 
129  public static bool operator !=(TermVectorOffsetInfo left, object right)
130  {
131  return !left.Equals(right);
132  }
133  }
134 }