ValueRange.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Lextm.SharpSnmpLib.Mib
  4. {
  5. public class ValueRanges: List<ValueRange>
  6. {
  7. public bool IsSizeDeclaration { get; internal set; }
  8. public ValueRanges(bool isSizeDecl = false)
  9. {
  10. IsSizeDeclaration = isSizeDecl;
  11. }
  12. public bool Contains(Int64 value)
  13. {
  14. foreach (ValueRange range in this)
  15. {
  16. if (range.Contains(value))
  17. {
  18. return true;
  19. }
  20. }
  21. return false;
  22. }
  23. }
  24. public class ValueRange
  25. {
  26. private readonly Int64 _start;
  27. private readonly Int64? _end;
  28. public ValueRange(Int64 first, Int64? second)
  29. {
  30. _start = first;
  31. _end = second;
  32. }
  33. public Int64 Start
  34. {
  35. get { return _start; }
  36. }
  37. public Int64? End
  38. {
  39. get { return _end; }
  40. }
  41. public bool IntersectsWith(ValueRange other)
  42. {
  43. if (this._end == null)
  44. {
  45. return other.Contains(this._start);
  46. }
  47. else if (other._end == null)
  48. {
  49. return this.Contains(other._start);
  50. }
  51. return (this._start <= other.End) && (this._end >= other._start);
  52. }
  53. public bool Contains(Int64 value)
  54. {
  55. if (_end == null)
  56. {
  57. return value == _start;
  58. }
  59. else
  60. {
  61. return (_start <= value) && (value <= _end);
  62. }
  63. }
  64. }
  65. }