DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
IndexRange.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Text;
19 
20 using Deveel.Data.Sql.Objects;
21 using Deveel.Data.Types;
22 
23 namespace Deveel.Data.Index {
38  public struct IndexRange {
42  public static readonly DataObject FirstInSet = new DataObject(PrimitiveTypes.Null(), new SqlString("FirstInSet"));
43 
47  public static readonly DataObject LastInSet = new DataObject(PrimitiveTypes.Null(), new SqlString("LastInSet"));
48 
56  public IndexRange(RangeFieldOffset startOffset, DataObject firstValue, RangeFieldOffset lastOffset, DataObject endValue)
57  : this(false) {
58  StartOffset = startOffset;
59  StartValue = firstValue;
60  EndOffset = lastOffset;
61  EndValue = endValue;
62  }
63 
64  private IndexRange(bool isNull)
65  : this() {
66  IsNull = isNull;
67  }
68 
69  public bool IsNull { get; private set; }
70 
74  public static readonly IndexRange FullRange = new IndexRange(RangeFieldOffset.FirstValue, FirstInSet,
75  RangeFieldOffset.LastValue, LastInSet);
76 
80  public static readonly IndexRange FullRangeNotNull = new IndexRange(RangeFieldOffset.AfterLastValue, DataObject.Null(),
81  RangeFieldOffset.LastValue, LastInSet);
82 
83  public static readonly IndexRange Null = new IndexRange(true);
84 
88  public RangeFieldOffset StartOffset { get; private set; }
89 
93  public DataObject StartValue { get; private set; }
94 
98  public RangeFieldOffset EndOffset { get; private set; }
99 
103  public DataObject EndValue { get; private set; }
104 
106  public override bool Equals(object obj) {
107  var destRange = (IndexRange)obj;
108  if (IsNull && destRange.IsNull)
109  return true;
110  if (IsNull && !destRange.IsNull)
111  return false;
112  if (!IsNull && destRange.IsNull)
113  return false;
114 
115  return (StartValue.Value.Equals(destRange.StartValue.Value) &&
116  EndValue.Value.Equals(destRange.EndValue.Value) &&
117  StartOffset == destRange.StartOffset &&
118  EndOffset == destRange.EndOffset);
119  }
120 
122  public override int GetHashCode() {
123  return base.GetHashCode();
124  }
125 
127  public override string ToString() {
128  var sb = new StringBuilder();
129  if (StartOffset == RangeFieldOffset.FirstValue) {
130  sb.Append("FIRST_VALUE ");
131  } else if (StartOffset == RangeFieldOffset.AfterLastValue) {
132  sb.Append("AFTER_LAST_VALUE ");
133  }
134 
135  sb.Append(StartValue.ToString());
136  sb.Append(" -> ");
137  if (EndOffset == RangeFieldOffset.LastValue) {
138  sb.Append("LAST_VALUE ");
139  } else if (EndOffset == RangeFieldOffset.BeforeFirstValue) {
140  sb.Append("BEFORE_FIRST_VALUE ");
141  }
142  sb.Append(EndValue.ToString());
143  return sb.ToString();
144  }
145 
146  public static bool operator ==(IndexRange a, IndexRange b) {
147  return a.Equals(b);
148  }
149 
150  public static bool operator !=(IndexRange a, IndexRange b) {
151  return !(a == b);
152  }
153  }
154 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
Describes the range of values to select from an index.
Definition: IndexRange.cs:38
static DataObject Null(SqlType type)
Definition: DataObject.cs:630
override int GetHashCode()
Definition: IndexRange.cs:122
IndexRange(RangeFieldOffset startOffset, DataObject firstValue, RangeFieldOffset lastOffset, DataObject endValue)
Constructs the range given a start and an end location
Definition: IndexRange.cs:56
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
override string ToString()
Definition: IndexRange.cs:127
override bool Equals(object obj)
Definition: IndexRange.cs:106
RangeFieldOffset
The absolute offset of a field in a range of a selection.
Deveel.Data.Sql.Objects.SqlString SqlString
Definition: DataObject.cs:27