/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using MongoDB.Driver.Core.Misc;
namespace MongoDB.Driver
{
///
/// Represents a documents window for a SetWindowFields window method.
///
public sealed class DocumentsWindow : SetWindowFieldsWindow
{
#region static
private static readonly KeywordDocumentsWindowBoundary __current = new KeywordDocumentsWindowBoundary("current");
private static readonly KeywordDocumentsWindowBoundary __unbounded = new KeywordDocumentsWindowBoundary("unbounded");
///
/// Returns a "current" documents window boundary.
///
public static KeywordDocumentsWindowBoundary Current => __current;
///
/// Returns an "unbounded" documents window boundary.
///
public static KeywordDocumentsWindowBoundary Unbounded => __unbounded;
///
/// Creates a documents window.
///
/// The lower boundary.
/// The upper boundary.
/// A documents window.
public static DocumentsWindow Create(int lowerBoundary, int upperBoundary)
{
return new DocumentsWindow(new PositionDocumentsWindowBoundary(lowerBoundary), new PositionDocumentsWindowBoundary(upperBoundary));
}
///
/// Creates a documents window.
///
/// The lower boundary.
/// The upper boundary.
/// A documents window.
public static DocumentsWindow Create(int lowerBoundary, KeywordDocumentsWindowBoundary upperBoundary)
{
return new DocumentsWindow(new PositionDocumentsWindowBoundary(lowerBoundary), upperBoundary);
}
///
/// Creates a documents window.
///
/// The lower boundary.
/// The upper boundary.
/// A documents window.
public static DocumentsWindow Create(KeywordDocumentsWindowBoundary lowerBoundary, int upperBoundary)
{
return new DocumentsWindow(lowerBoundary, new PositionDocumentsWindowBoundary(upperBoundary));
}
///
/// Creates a documents window.
///
/// The lower boundary.
/// The upper boundary.
/// A documents window.
public static DocumentsWindow Create(KeywordDocumentsWindowBoundary lowerBoundary, KeywordDocumentsWindowBoundary upperBoundary)
{
return new DocumentsWindow(lowerBoundary, upperBoundary);
}
#endregion
private readonly DocumentsWindowBoundary _lowerBoundary;
private readonly DocumentsWindowBoundary _upperBoundary;
///
/// Initializes an instance of DocumentsWindow.
///
/// The lower boundary.
/// The upper boundary.
internal DocumentsWindow(DocumentsWindowBoundary lowerBoundary, DocumentsWindowBoundary upperBoundary)
{
_lowerBoundary = Ensure.IsNotNull(lowerBoundary, nameof(lowerBoundary));
_upperBoundary = Ensure.IsNotNull(upperBoundary, nameof(upperBoundary));
}
///
/// The lower boundary.
///
public DocumentsWindowBoundary LowerBoundary => _lowerBoundary;
///
/// The upper boundary.
///
public DocumentsWindowBoundary UpperBoundary => _upperBoundary;
///
public override string ToString() => $"documents : [{_lowerBoundary}, {_upperBoundary}]";
}
}