MaxSegmentCollection.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// This class contains a collection of <see cref="MaxSegment"/> objects.
  6. /// </summary>
  7. [Serializable]
  8. public class MaxSegmentCollection
  9. {
  10. [SerializeField] private List<MaxSegment> segments;
  11. private MaxSegmentCollection(MaxSegmentCollectionBuilder maxSegmentCollectionBuilder)
  12. {
  13. segments = maxSegmentCollectionBuilder.segments;
  14. }
  15. /// <returns>The list of <see cref="MaxSegment"/> in the <see cref="MaxSegmentCollection"/></returns>
  16. public List<MaxSegment> GetSegments()
  17. {
  18. return segments;
  19. }
  20. public static MaxSegmentCollectionBuilder Builder()
  21. {
  22. return new MaxSegmentCollectionBuilder();
  23. }
  24. /// <summary>
  25. /// Builder class for MaxSegmentCollection.
  26. /// </summary>
  27. public class MaxSegmentCollectionBuilder
  28. {
  29. internal readonly List<MaxSegment> segments = new List<MaxSegment>();
  30. internal MaxSegmentCollectionBuilder() { }
  31. /// <summary>
  32. /// Adds a MaxSegment to the collection.
  33. /// </summary>
  34. /// <param name="segment">The MaxSegment to add.</param>
  35. /// <returns>The MaxSegmentCollectionBuilder instance for chaining.</returns>
  36. public MaxSegmentCollectionBuilder AddSegment(MaxSegment segment)
  37. {
  38. segments.Add(segment);
  39. return this;
  40. }
  41. /// <summary>
  42. /// Builds and returns the MaxSegmentCollection.
  43. /// </summary>
  44. /// <returns>The constructed MaxSegmentCollection.</returns>
  45. public MaxSegmentCollection Build()
  46. {
  47. return new MaxSegmentCollection(this);
  48. }
  49. }
  50. }
  51. /// <summary>
  52. /// This class encapsulates a key-value pair, where the key is an int and the value is a List&lt;int&gt;.
  53. /// </summary>
  54. [Serializable]
  55. public class MaxSegment
  56. {
  57. [SerializeField] private int key;
  58. [SerializeField] private List<int> values;
  59. /// <summary>
  60. /// Initializes a new <see cref="MaxSegment"/> with the specified key and value(s).
  61. /// </summary>
  62. /// <param name="key">The key of the segment. Must be a non-negative number in the range of [0, 32000].</param>
  63. /// <param name="values">The values(s) associated with the key. Each value must be a non-negative number in the range of [0, 32000].</param>
  64. public MaxSegment(int key, List<int> values)
  65. {
  66. this.key = key;
  67. this.values = values;
  68. }
  69. /// <returns>The key of the segment. Must be a non-negative number in the range of [0, 32000].</returns>
  70. public int GetKey()
  71. {
  72. return key;
  73. }
  74. /// <returns>The value(s) associated with the key. Each value must be a non-negative number in the range of [0, 32000].</returns>
  75. public List<int> GetValues()
  76. {
  77. return values;
  78. }
  79. }