logo

const class

sys::Version

sys::Obj
  sys::Version
   1  //
   2  // Copyright (c) 2006, Brian Frank and Andy Frank
   3  // Licensed under the Academic Free License version 3.0
   4  //
   5  // History:
   6  //   27 Jul 06  Brian Frank  Creation
   7  //
   8  
   9  **
  10  ** Version is defined as a list of decimal digits separated
  11  ** by the dot.  Convention for Fan pods is a four part version
  12  ** format of 'major.minor.build.patch'.
  13  **
  14  @simple
  15  const final class Version
  16  {
  17  
  18  //////////////////////////////////////////////////////////////////////////
  19  // Constructor
  20  //////////////////////////////////////////////////////////////////////////
  21  
  22    **
  23    ** Parse a string representation into a Version.
  24    ** Throw ParseErr if not a valid version format.
  25    **
  26    static Version fromStr(Str version)
  27  
  28    **
  29    ** Construct with list of integer segments.
  30    ** Throw ArgErr if segments is empty or contains negative numbers.
  31    **
  32    static Version make(Int[] segments)
  33  
  34    **
  35    ** Private constructor
  36    **
  37    private new privateMake()
  38  
  39  //////////////////////////////////////////////////////////////////////////
  40  // Obj Overrides
  41  //////////////////////////////////////////////////////////////////////////
  42  
  43    **
  44    ** Return true if equal segments.
  45    **
  46    override Bool equals(Obj obj)
  47  
  48    **
  49    ** Compare from from most significant segment to least significant
  50    ** segment.
  51    **
  52    ** Examples:
  53    **   1.6 > 1.4
  54    **   2.0 > 1.9
  55    **   1.2.3 > 1.2
  56    **   1.11 > 1.9.3
  57    **
  58    override Int compare(Obj obj)
  59  
  60    **
  61    ** Return toStr.hash
  62    **
  63    override Int hash()
  64  
  65    **
  66    ** The string format is equivalent to segments.join(".")
  67    **
  68    override Str toStr()
  69  
  70  //////////////////////////////////////////////////////////////////////////
  71  // Methods
  72  //////////////////////////////////////////////////////////////////////////
  73  
  74    **
  75    ** Get a readonly list of the integer segments.
  76    **
  77    Int[] segments()
  78  
  79    **
  80    ** Get the first, most significant segment which represents the major version.
  81    **
  82    Int major()
  83  
  84    **
  85    ** Get the second segment which represents the minor version.
  86    ** If return null if less than two segments.
  87    **
  88    Int minor()
  89  
  90    **
  91    ** Get the third segment which represents the build number.
  92    ** If return null if less than three segments.
  93    **
  94    Int build()
  95  
  96    **
  97    ** Get the fourth segment which represents the patch number.
  98    ** If return null if less than four segments.
  99    **
 100    Int patch()
 101  
 102  }