-
Notifications
You must be signed in to change notification settings - Fork 64
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
java semver #1
Conversation
🎉 感谢提交Pull Request!请稍等片刻,我们已经将其提交到CI进行检查,一旦有结果会立即通知您! |
恭喜你,你的提交 b3664d0 已经通过我们的CI检查:Your tests passed on CircleCI! 👍 它会被自动merge后revert。请不要骄傲,继续挑战! |
恭喜你,你的提交 b3664d0 已经通过我们的CI检查:Your tests passed on CircleCI! 👍 它会被自动merge后revert。请不要骄傲,继续挑战! |
} | ||
|
||
@Override | ||
public int compareTo(Version o) { |
There was a problem hiding this comment.
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掉的。
There was a problem hiding this comment.
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
不能进行正确的比较。
There was a problem hiding this comment.
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
,但是这个算法会比较1210
和1100
,然后得到错误的结果。
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: innnerVersion
-> innerVersion
.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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来多此一举?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
�我想把所有的结果放在一起,根据 versions.length 做匹配。还有就是习惯一个函数 只有一个入口和一个出口
There was a problem hiding this comment.
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;
}
No description provided.