Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int compareVersion(String s1, String s2) {
        if (s1 == null && s2 == null) {
            return 0;
        } else if (s1 != null && s2 == null) {
            return 1;
        } else if (s1 == null && s2 != null) {
            return -1;
        } else {
            String[] var2 = s1.split("\\.");
            String[] var3 = s2.split("\\.");

            try {
                int var4;
                for (var4 = 0; var4 < var2.length && var4 < var3.length; ++var4) {
                    int var5 = Integer.parseInt(var2[var4]);
                    int var6 = Integer.parseInt(var3[var4]);
                    if (var5 < var6) {
                        return -1;
                    }

                    if (var5 > var6) {
                        return 1;
                    }
                }

                return var2.length > var4 ? 1 : (var3.length > var4 ? -1 : 0);
            } catch (NumberFormatException var7) {
                return s1.compareTo(s2);
            }
        }
    }
}