From 0000f31baa84721fa2aebca37f8e5b352e002e4e Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 29 Feb 2016 12:45:52 +0100 Subject: [PATCH] Do not duplicate candidate list 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 --- .../LastCandidateSelectionStrategy.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/LastCandidateSelectionStrategy.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/LastCandidateSelectionStrategy.java index ea7deb5693..73236c234c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/LastCandidateSelectionStrategy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/LastCandidateSelectionStrategy.java @@ -8,19 +8,17 @@ 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.List; import java.util.Map; public class LastCandidateSelectionStrategy extends AbstractEntityOwnerSelectionStrategy { - public LastCandidateSelectionStrategy(long selectionDelayInMillis) { + public LastCandidateSelectionStrategy(final long selectionDelayInMillis) { super(selectionDelayInMillis); } @Override - public String newOwner(Collection viableCandidates, Map statistics) { - List candidates = new ArrayList<>(viableCandidates); - return candidates.get(candidates.size()-1); + public String newOwner(final Collection viableCandidates, final Map statistics) { + return Iterables.getLast(viableCandidates); } } -- 2.36.6