File: ValueRange.cs

package info (click to toggle)
lwip 2.2.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 10,008 kB
  • sloc: ansic: 109,524; cs: 6,714; sh: 115; makefile: 112; perl: 81
file content (76 lines) | stat: -rw-r--r-- 1,669 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;

namespace Lextm.SharpSnmpLib.Mib
{
    public class ValueRanges: List<ValueRange>
    {
        public bool IsSizeDeclaration { get; internal set; }

        public ValueRanges(bool isSizeDecl = false)
        {
            IsSizeDeclaration = isSizeDecl;
        }

        public bool Contains(Int64 value)
        {
            foreach (ValueRange range in this)
            {
                if (range.Contains(value))
                {
                    return true;
                }
            }

            return false;
        }
    }

    public class ValueRange
    {
        private readonly Int64 _start;
        private readonly Int64? _end;

        public ValueRange(Int64 first, Int64? second)
        {
            _start = first;
            _end   = second;
        }

        public Int64 Start
        {
            get { return _start; }
        }

        public Int64? End
        {
            get { return _end; }
        }

        public bool IntersectsWith(ValueRange other)
        {
            if (this._end == null)
            {
                return other.Contains(this._start);
            }
            else if (other._end == null)
            {
                return this.Contains(other._start);
            }

            return (this._start <= other.End) && (this._end >= other._start);
        }

        public bool Contains(Int64 value)
        {
            if (_end == null)
            {
                return value == _start;
            }
            else
            {
                return (_start <= value) && (value <= _end);
            }
        }
    }
}