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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* VersionString.cs
* Copyright © 2011 kbinani
*
* This file is part of org.kbinani.cadencii.
*
* org.kbinani.cadencii is free software; you can redistribute it and/or
* modify it under the terms of the GPLv3 License.
*
* org.kbinani.cadencii is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
package org.kbinani.cadencii;
import org.kbinani.*;
#else
using System;
namespace org
{
namespace kbinani
{
namespace cadencii
{
#endif
/// <summary>
/// メジャー,マイナー,およびメンテナンス番号によるバージョン番号を表すクラス
/// </summary>
#if JAVA
class VersionString implements Comparable<VersionString>
#else
class VersionString : IComparable<VersionString>
#endif
{
/// <summary>
/// メジャーバージョンを表す
/// </summary>
public int major;
/// <summary>
/// マイナーバージョンを表す
/// </summary>
public int minor;
/// <summary>
/// メンテナンス番号を表す
/// </summary>
public int build;
/// <summary>
/// コンストラクタに渡された文字列のキャッシュ
/// </summary>
private String mRawString = "0.0.0";
/// <summary>
/// 「メジャー.マイナー.メンテナンス」の記法に基づく文字列をパースし,新しいインスタンスを作成します
/// </summary>
/// <param name="str"></param>
public VersionString( String s )
{
mRawString = s;
String[] spl = PortUtil.splitString( s, '.' );
if ( spl.Length >= 1 ) {
try {
major = str.toi( spl[0] );
} catch ( Exception ex ) {
}
}
if ( spl.Length >= 2 ) {
try {
minor = str.toi( spl[1] );
} catch ( Exception ex ) {
}
}
if ( spl.Length >= 3 ) {
try {
build = str.toi( spl[2] );
} catch ( Exception ex ) {
}
}
}
/// <summary>
/// このインスタンス生成時に渡された文字列を取得します
/// </summary>
/// <returns></returns>
public String getRawString()
{
return mRawString;
}
/// <summary>
/// このインスタンスを文字列で表現したものを取得します
/// </summary>
/// <returns></returns>
public String toString()
{
return major + "." + minor + "." + build;
}
/// <summary>
/// このインスタンスと,指定したバージョンを比較します
/// </summary>
/// <param name="item"></param>
/// <returns>このインスタンスの表すバージョンに対して,指定したバージョンが同じであれば0,新しければ正の値,それ以外は負の値を返します</returns>
public int compareTo( VersionString item )
{
if ( item == null ) {
return -1;
}
if ( this.major == item.major ) {
if ( this.minor == item.minor ) {
return this.build - item.build;
} else {
return this.minor - item.minor;
}
} else {
return this.major - item.major;
}
}
#if !JAVA
public override String ToString()
{
return this.toString();
}
public int CompareTo( VersionString item )
{
return this.compareTo( item );
}
#endif
}
#if !JAVA
}
}
}
#endif
|