Iterables.getLast() provides an efficient way of getting the last item
from a collection, without the need to duplicate it.
Change-Id: I49b0bc827bffc0adb616cf516438bad7526ad141
Signed-off-by: Robert Varga <rovarga@cisco.com>
package org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy;
package org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy;
-import java.util.ArrayList;
+import com.google.common.collect.Iterables;
import java.util.Collection;
import java.util.Collection;
import java.util.Map;
public class LastCandidateSelectionStrategy extends AbstractEntityOwnerSelectionStrategy {
import java.util.Map;
public class LastCandidateSelectionStrategy extends AbstractEntityOwnerSelectionStrategy {
- public LastCandidateSelectionStrategy(long selectionDelayInMillis) {
+ public LastCandidateSelectionStrategy(final long selectionDelayInMillis) {
super(selectionDelayInMillis);
}
@Override
super(selectionDelayInMillis);
}
@Override
- public String newOwner(Collection<String> viableCandidates, Map<String, Long> statistics) {
- List<String> candidates = new ArrayList<>(viableCandidates);
- return candidates.get(candidates.size()-1);
+ public String newOwner(final Collection<String> viableCandidates, final Map<String, Long> statistics) {
+ return Iterables.getLast(viableCandidates);