-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
优化网卡地址优先级 #1986
优化网卡地址优先级 #1986
Conversation
fix #1874. |
Codecov Report
@@ Coverage Diff @@
## master #1986 +/- ##
============================================
- Coverage 57.54% 50.18% -7.36%
- Complexity 1120 1978 +858
============================================
Files 193 400 +207
Lines 5940 12349 +6409
Branches 636 1275 +639
============================================
+ Hits 3418 6197 +2779
- Misses 2259 5693 +3434
- Partials 263 459 +196
Continue to review full report at Codecov.
|
List<NetworkInterface> nis = interfaces == null ? Collections.<NetworkInterface>emptyList() | ||
: Collections.list(interfaces); | ||
//sort the network interfaces according to the index asc | ||
Collections.sort(nis, new Comparator<NetworkInterface>() { |
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.
can be replaced with list.sort
?
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.
can be replaced with lambda?
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.
of course! but apollo-core is <java.version>1.7</java.version> in pom.xml.
Consider compatibility,i don't use lambda.
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.
Got it
if (nis1.getIndex() > nis2.getIndex()) { | ||
return 1; | ||
} else { | ||
return -1; |
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.
do we need a case to return 0?
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 0 is invalid。
this is results on my computer。
return 0:
name:utun0 (utun0)------index = 18
name:awdl0 (awdl0)------index = 12
name:en5 (en5)------index = 8
name:en0 (en0)------index = 10
name:lo0 (lo0)------index = 1
return -1:
name:lo0 (lo0)------index = 1
name:en5 (en5)------index = 8
name:en0 (en0)------index = 10
name:awdl0 (awdl0)------index = 12
name:utun0 (utun0)------index = 18
I don't know why return 0 sorting does not take effect.....
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.
normally we would return 3 values for a comparison between variable a
and b
1
means a > b0
means a = b-1
means a < b
I'm not saying we should change the statement return -1
to return 0
, what I mean by do we need a case to return 0?
is I'm not sure if there is a case that nis1.getIndex() == nis2.getIndex()
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.
I know.Maybe this can be replaced by "Integer.compare(nis1.getIndex(), nis2.getIndex())"
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.
LGTM
优化网卡地址优先级,index低的网卡地址优先级高
index低的网卡地址优先级高