Fix findbug and checkstyle issues
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / impl / add / n / paths / AbstractNPathsRouteEntry.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.protocol.bgp.mode.impl.add.n.paths;
10
11 import com.google.common.collect.ImmutableList;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathAbstractRouteEntry;
15 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
16 import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
17
18 abstract class AbstractNPathsRouteEntry extends AddPathAbstractRouteEntry {
19     private final long npaths;
20
21     AbstractNPathsRouteEntry(final Long npaths) {
22         this.npaths = npaths;
23     }
24
25     @Override
26     public final boolean selectBest(final long localAs) {
27         final List<AddPathBestPath> newBestPathList = new ArrayList<>();
28         final List<RouteKey> keyList = this.offsets.getRouteKeysList();
29         final long maxSearch = this.npaths < this.offsets.size()
30                 && this.npaths != 0 ? this.npaths : this.offsets.size();
31         for (long i = 0; i < maxSearch; ++i) {
32             final AddPathBestPath newBest = selectBest(localAs, keyList);
33             newBestPathList.add(newBest);
34             keyList.remove(newBest.getRouteKey());
35         }
36         return isBestPathNew(ImmutableList.copyOf(newBestPathList));
37     }
38 }