Java Version Convert To VersionToString(long uVersion)

Here you can find the source of VersionToString(long uVersion)

Description

Version To String

License

Open Source License

Declaration

public static String VersionToString(long uVersion) 

Method Source Code

//package com.java2s;
/*/* w w  w  .j  a  v  a 2 s. c  om*/
  KeePass Password Safe - The Open-Source Password Manager
  Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>
    
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
    
  This program 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.  See the
  GNU General Public License for more details.
    
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

public class Main {
    public static String VersionToString(long uVersion) {
        return VersionToString(uVersion, 1);
    }

    public static String VersionToString(long uVersion, boolean bEnsureAtLeastTwoComp) {
        return VersionToString(uVersion, (bEnsureAtLeastTwoComp ? 2 : 1));
    }

    public static String VersionToString(long uVersion, int uMinComp) {
        StringBuilder sb = new StringBuilder();
        int uComp = 0;

        for (int i = 0; i < 4; ++i) {
            if (uVersion == 0L)
                break;

            short us = (short) (uVersion >> 48);

            if (sb.length() > 0)
                sb.append('.');

            sb.append(us);
            ++uComp;

            uVersion <<= 16;
        }

        while (uComp < uMinComp) {
            if (sb.length() > 0)
                sb.append('.');

            sb.append('0');
            ++uComp;
        }

        return sb.toString();
    }
}

Related

  1. versionStringToNumber(String versionStr)
  2. versionToCode(String version)
  3. versionToSegments(String versionString, int idx, int i)
  4. versionToString(int version)
  5. versiontostring(int vv)