Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package description |
| 8 | |
| 9 | import "fmt" |
| 10 | |
| 11 | // VersionRange represents a range of versions. |
| 12 | type VersionRange struct { |
| 13 | Min int32 |
| 14 | Max int32 |
| 15 | } |
| 16 | |
| 17 | // NewVersionRange creates a new VersionRange given a min and a max. |
| 18 | func NewVersionRange(min, max int32) VersionRange { |
| 19 | return VersionRange{Min: min, Max: max} |
| 20 | } |
| 21 | |
| 22 | // Includes returns a bool indicating whether the supplied integer is included |
| 23 | // in the range. |
| 24 | func (vr VersionRange) Includes(v int32) bool { |
| 25 | return v >= vr.Min && v <= vr.Max |
| 26 | } |
| 27 | |
| 28 | // String implements the fmt.Stringer interface. |
| 29 | func (vr VersionRange) String() string { |
| 30 | return fmt.Sprintf("[%d, %d]", vr.Min, vr.Max) |
| 31 | } |