Skip to content

[WIP]Load balancing abstract#3054

Closed
CalvinKirs wants to merge 5 commits intoapache:devfrom
CalvinKirs:kris
Closed

[WIP]Load balancing abstract#3054
CalvinKirs wants to merge 5 commits intoapache:devfrom
CalvinKirs:kris

Conversation

@CalvinKirs
Copy link
Copy Markdown
Member

What is the purpose of the pull request

abstract loadbalance select

Brief change log

This pull request is code cleanup without any test coverage.

@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Comment on lines +26 to +45
public abstract class AbstractSelector<T> implements Selector<T>{
@Override
public T select(Collection<T> source) {

if (CollectionUtils.isEmpty(source)) {
throw new IllegalArgumentException("Empty source.");
}

/**
* if only one , return directly
*/
if (source.size() == 1) {
return (T)source.toArray()[0];
}
return doSelect(source);
}

protected abstract T doSelect(Collection<T> source);

}
Copy link
Copy Markdown
Contributor

@yangyichao-mango yangyichao-mango Jun 26, 2020

Choose a reason for hiding this comment

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

What is the purpose of this new AbstractSelector<T> class?
In my opinion, interface default method will be better than abstract method if there is no clear inheritance relation. So is it better o implement select method in Selector<T> as a default method?

是否有必要新建一个 AbstractSelector<T> 类呢?
个人理解,如果后续没有明显的继承关系的话,实现接口的default方法会比抽象类的方法有更多的好处。将 select 方法直接在 Selector<T> 接口中实现会不会更好一些?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you very much for your review, but I personally are not very inclined to implement the default method of the interface. The original intention of the default method is to add new functions to the smooth evolution of the existing interface. It is not very appropriate to put it here. what do you think?

Comment on lines +34 to +43
/**
* if only one , return directly
*/
if (source.size() == 1) {
return (T)source.toArray()[0];
}
return doSelect(source);
}

protected abstract T doSelect(Collection<T> source);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* if only one , return directly
*/
if (source.size() == 1) {
return (T)source.toArray()[0];
}
return doSelect(source);
}
protected abstract T doSelect(Collection<T> source);
/**
* if only one , return directly
*/
if (1 == source.size()) {
return (T)source.toArray()[0];
}
return doSelect(source);
}
protected abstract T doSelect(Collection<T> source);

Copy link
Copy Markdown
Member Author

@CalvinKirs CalvinKirs Jun 27, 2020

Choose a reason for hiding this comment

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

Hello, why do you need to modify this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did it change like this?

Thx.
In my opinion, it's not necessary to change it to this way, but the advantages of doing so are prevent us from coding like this if (source.size() = 1). Just to improve the robustness of the code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for your suggestion, I will finish it later.

@CalvinKirs CalvinKirs changed the title Load balancing abstract [WIP]Load balancing abstract Jun 27, 2020
@CalvinKirs CalvinKirs closed this Jun 28, 2020
qiaozhanwei pushed a commit that referenced this pull request Jun 28, 2020
* Load balancing abstract

* code
smell

* lower weight select
@CalvinKirs CalvinKirs deleted the kris branch July 16, 2020 11:58
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.

2 participants