INT-3528 Use Collections min and max methods where appropriate
JIRA: https://jira.spring.io/browse/INT-3528 Use `min` and `max` methods instead of sorting an entire collection to get the minimum or maximum element. Change other inline `Comparator<?>`s to the `final` fields
This commit is contained in:
committed by
Artem Bilan
parent
252c53db4c
commit
6f7a8e3002
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.redis.store;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -45,6 +46,15 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class RedisChannelPriorityMessageStore extends RedisChannelMessageStore implements PriorityCapableChannelMessageStore {
|
||||
|
||||
private final Comparator<String> keysComparator = new Comparator<String>() {
|
||||
|
||||
@Override
|
||||
public int compare(String s1, String s2) {
|
||||
return s2.compareTo(s1);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public RedisChannelPriorityMessageStore(RedisConnectionFactory connectionFactory) {
|
||||
super(connectionFactory);
|
||||
}
|
||||
@@ -111,13 +121,7 @@ public class RedisChannelPriorityMessageStore extends RedisChannelMessageStore i
|
||||
Assert.isInstanceOf(String.class, key);
|
||||
list.add((String) key);
|
||||
}
|
||||
Collections.sort(list, new Comparator<String>() {
|
||||
|
||||
@Override
|
||||
public int compare(String s1, String s2) {
|
||||
return s2.compareTo(s1);
|
||||
}
|
||||
});
|
||||
Collections.sort(list, this.keysComparator);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user