|
| 1 | +/* Copyright 2010-present MongoDB Inc. |
| 2 | +* |
| 3 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +* you may not use this file except in compliance with the License. |
| 5 | +* You may obtain a copy of the License at |
| 6 | +* |
| 7 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +* |
| 9 | +* Unless required by applicable law or agreed to in writing, software |
| 10 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +* See the License for the specific language governing permissions and |
| 13 | +* limitations under the License. |
| 14 | +*/ |
| 15 | + |
| 16 | +using MongoDB.Driver.Core.Misc; |
| 17 | + |
| 18 | +namespace MongoDB.Driver |
| 19 | +{ |
| 20 | + /// <summary> |
| 21 | + /// Represents a documents window for a SetWindowFields window method. |
| 22 | + /// </summary> |
| 23 | + public sealed class DocumentsWindow : SetWindowFieldsWindow |
| 24 | + { |
| 25 | + #region static |
| 26 | + private static readonly KeywordDocumentsWindowBoundary __current = new KeywordDocumentsWindowBoundary("current"); |
| 27 | + private static readonly KeywordDocumentsWindowBoundary __unbounded = new KeywordDocumentsWindowBoundary("unbounded"); |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Returns a "current" documents window boundary. |
| 31 | + /// </summary> |
| 32 | + public static KeywordDocumentsWindowBoundary Current => __current; |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Returns an "unbounded" documents window boundary. |
| 36 | + /// </summary> |
| 37 | + public static KeywordDocumentsWindowBoundary Unbounded => __unbounded; |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Creates a documents window. |
| 41 | + /// </summary> |
| 42 | + /// <param name="lowerBoundary">The lower boundary.</param> |
| 43 | + /// <param name="upperBoundary">The upper boundary.</param> |
| 44 | + /// <returns>A documents window.</returns> |
| 45 | + public static DocumentsWindow Create(int lowerBoundary, int upperBoundary) |
| 46 | + { |
| 47 | + return new DocumentsWindow(new PositionDocumentsWindowBoundary(lowerBoundary), new PositionDocumentsWindowBoundary(upperBoundary)); |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Creates a documents window. |
| 52 | + /// </summary> |
| 53 | + /// <param name="lowerBoundary">The lower boundary.</param> |
| 54 | + /// <param name="upperBoundary">The upper boundary.</param> |
| 55 | + /// <returns>A documents window.</returns> |
| 56 | + public static DocumentsWindow Create(int lowerBoundary, KeywordDocumentsWindowBoundary upperBoundary) |
| 57 | + { |
| 58 | + return new DocumentsWindow(new PositionDocumentsWindowBoundary(lowerBoundary), upperBoundary); |
| 59 | + } |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Creates a documents window. |
| 63 | + /// </summary> |
| 64 | + /// <param name="lowerBoundary">The lower boundary.</param> |
| 65 | + /// <param name="upperBoundary">The upper boundary.</param> |
| 66 | + /// <returns>A documents window.</returns> |
| 67 | + public static DocumentsWindow Create(KeywordDocumentsWindowBoundary lowerBoundary, int upperBoundary) |
| 68 | + { |
| 69 | + return new DocumentsWindow(lowerBoundary, new PositionDocumentsWindowBoundary(upperBoundary)); |
| 70 | + } |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// Creates a documents window. |
| 74 | + /// </summary> |
| 75 | + /// <param name="lowerBoundary">The lower boundary.</param> |
| 76 | + /// <param name="upperBoundary">The upper boundary.</param> |
| 77 | + /// <returns>A documents window.</returns> |
| 78 | + public static DocumentsWindow Create(KeywordDocumentsWindowBoundary lowerBoundary, KeywordDocumentsWindowBoundary upperBoundary) |
| 79 | + { |
| 80 | + return new DocumentsWindow(lowerBoundary, upperBoundary); |
| 81 | + } |
| 82 | + #endregion |
| 83 | + |
| 84 | + private readonly DocumentsWindowBoundary _lowerBoundary; |
| 85 | + private readonly DocumentsWindowBoundary _upperBoundary; |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Initializes an instance of DocumentsWindow. |
| 89 | + /// </summary> |
| 90 | + /// <param name="lowerBoundary">The lower boundary.</param> |
| 91 | + /// <param name="upperBoundary">The upper boundary.</param> |
| 92 | + internal DocumentsWindow(DocumentsWindowBoundary lowerBoundary, DocumentsWindowBoundary upperBoundary) |
| 93 | + { |
| 94 | + _lowerBoundary = Ensure.IsNotNull(lowerBoundary, nameof(lowerBoundary)); |
| 95 | + _upperBoundary = Ensure.IsNotNull(upperBoundary, nameof(upperBoundary)); |
| 96 | + } |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// The lower boundary. |
| 100 | + /// </summary> |
| 101 | + public DocumentsWindowBoundary LowerBoundary => _lowerBoundary; |
| 102 | + |
| 103 | + /// <summary> |
| 104 | + /// The upper boundary. |
| 105 | + /// </summary> |
| 106 | + public DocumentsWindowBoundary UpperBoundary => _upperBoundary; |
| 107 | + |
| 108 | + /// <inheritdoc/> |
| 109 | + public override string ToString() => $"documents : [{_lowerBoundary}, {_upperBoundary}]"; |
| 110 | + } |
| 111 | +} |
0 commit comments