|
| 1 | +// |
| 2 | +// Copyright © Pete Sramek. All rights reserved. |
| 3 | +// Licensed under the MIT License. See LICENSE file in the project root for full license information. |
| 4 | +// |
| 5 | + |
| 6 | +namespace PolylineAlgorithm.Abstraction; |
| 7 | + |
| 8 | +using PolylineAlgorithm.Abstraction.Validation; |
| 9 | +using PolylineAlgorithm.Abstraction.Validation.Abstraction; |
| 10 | +using System; |
| 11 | + |
| 12 | +/// <summary> |
| 13 | +/// Provides a builder for configuring <see cref="PolylineEncodingOptions{TCoordinate}"/> instances. |
| 14 | +/// </summary> |
| 15 | +/// <typeparam name="TCoordinate">The type representing a coordinate.</typeparam> |
| 16 | +internal class PolylineEncodingOptionsBuilder<TCoordinate> : IPolylineEncodingOptionsBuilder<TCoordinate> { |
| 17 | + private int _bufferSize = 64_000; |
| 18 | + private Validator<TCoordinate> _validator = new NullValidator<TCoordinate>(); |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// Builds a new <see cref="PolylineEncodingOptions{TCoordinate}"/> instance using the configured options. |
| 22 | + /// </summary> |
| 23 | + /// <returns>A configured <see cref="PolylineEncodingOptions{TCoordinate}"/> instance.</returns> |
| 24 | + PolylineEncodingOptions<TCoordinate> IPolylineEncodingOptionsBuilder<TCoordinate>.Build() { |
| 25 | + return new PolylineEncodingOptions<TCoordinate> { |
| 26 | + BufferSize = _bufferSize, |
| 27 | + Validator = _validator |
| 28 | + }; |
| 29 | + } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Sets the buffer size for encoding operations. |
| 33 | + /// </summary> |
| 34 | + /// <param name="maxBufferSize">The maximum buffer size. Must be greater than 11.</param> |
| 35 | + /// <returns>The current builder instance.</returns> |
| 36 | + /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="maxBufferSize"/> is less than or equal to 11.</exception> |
| 37 | + IPolylineEncodingOptionsBuilder<TCoordinate> IPolylineEncodingOptionsBuilder<TCoordinate>.WithBufferSize(int maxBufferSize) { |
| 38 | + _bufferSize = maxBufferSize > 11 ? maxBufferSize : throw new ArgumentOutOfRangeException(nameof(maxBufferSize), "Buffer size must be greater than 11."); |
| 39 | + |
| 40 | + return this; |
| 41 | + } |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Sets the validator to use for coordinate validation. |
| 45 | + /// </summary> |
| 46 | + /// <param name="validator">The validator instance to use.</param> |
| 47 | + /// <returns>The current builder instance.</returns> |
| 48 | + /// <exception cref="ArgumentNullException">Thrown if <paramref name="validator"/> is <c>null</c>.</exception> |
| 49 | + IPolylineEncodingOptionsBuilder<TCoordinate> IPolylineEncodingOptionsBuilder<TCoordinate>.WithValidator(Validator<TCoordinate> validator) { |
| 50 | + _validator = validator ?? throw new ArgumentNullException(nameof(validator)); |
| 51 | + |
| 52 | + return this; |
| 53 | + } |
| 54 | +} |
0 commit comments