github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/description/version_range.go (about)

     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  // Equals returns a bool indicating whether the supplied VersionRange is equal.
    29  func (vr *VersionRange) Equals(other *VersionRange) bool {
    30  	if vr == nil && other == nil {
    31  		return true
    32  	}
    33  	if vr == nil || other == nil {
    34  		return false
    35  	}
    36  	return vr.Min == other.Min && vr.Max == other.Max
    37  }
    38  
    39  // String implements the fmt.Stringer interface.
    40  func (vr VersionRange) String() string {
    41  	return fmt.Sprintf("[%d, %d]", vr.Min, vr.Max)
    42  }