Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java semver #1

Merged
merged 1 commit into from
Jul 16, 2019
Merged

java semver #1

merged 1 commit into from
Jul 16, 2019

Conversation

slTrust
Copy link
Contributor

@slTrust slTrust commented Jul 16, 2019

No description provided.

@hcsp-bot
Copy link
Contributor

🎉 感谢提交Pull Request!请稍等片刻,我们已经将其提交到CI进行检查,一旦有结果会立即通知您!

@hcsp-bot
Copy link
Contributor

恭喜你,你的提交 b3664d0 已经通过我们的CI检查:Your tests passed on CircleCI!

👍 它会被自动merge后revert。请不要骄傲,继续挑战!

@hcsp-bot
Copy link
Contributor

恭喜你,你的提交 b3664d0 已经通过我们的CI检查:Your tests passed on CircleCI!

👍 它会被自动merge后revert。请不要骄傲,继续挑战!

@hcsp-bot hcsp-bot merged commit bdcf8c6 into master Jul 16, 2019
hcsp-bot added a commit that referenced this pull request Jul 16, 2019
This reverts commit bdcf8c6.
}

@Override
public int compareTo(Version o) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compareTo方法可以直接调用innnerVersion.compareTo(o. innnerVersion),无需自己实现。

另外。。你这个实现我目测有问题,虽然我不十分确定。我会加个测试把你这个实现fail掉的。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和我猜的一样,你的这个实现对于1.2.101.10不能进行正确的比较。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.2.10应该小于1.10,但是这个算法会比较12101100,然后得到错误的结果。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我在修正一下!!!

*/
private static final String REGEX_VERSION = "\\d+(\\.\\d+){0,2}";
private String revisedVersion;
com.github.zafarkhaja.semver.Version innnerVersion;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: innnerVersion -> innerVersion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这 一定是手抖或者眼花了!!!

}
}

return map.get(versions.length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是在干什么?直接

        switch (versions.length){
            case 1:{
                return versions[0]+".0.0";
            }
            case 2:{
                return versions[0] + "." + versions[1] + ".0";
            }
            case 3:{
                return version;
            }
        }

不就完了?为啥要搞个map来多此一举?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

�我想把所有的结果放在一起,根据 versions.length 做匹配。还有就是习惯一个函数 只有一个入口和一个出口

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一个入口一个出口这件事情和Map没关系啊,你完全可以写成

    private static String getRevisedVersion(String version){
        String [] versions = version.split("\\.");
        String result = null;
        switch (versions.length){
            case 1:{
                result = versions[0]+".0.0";
                break;
            }
            case 2:{
                result = versions[0] + "." + versions[1] + ".0";
                break;
            }
            case 3:{
                result = version;
                break;
            default:// 虽然我知道你上面用正则判断了,但是我还是感到没有default是不安全的,万一你正则写的有问题呢?
            }
            return result;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants