2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import com.google.common.primitives.UnsignedInteger;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 final class ComplexRouteEntry extends AbstractRouteEntry {
17 private static final MapEntryNode[] EMPTY_VALUES = new MapEntryNode[0];
18 private MapEntryNode[] values = EMPTY_VALUES;
21 protected int addRoute(final UnsignedInteger routerId, final NodeIdentifier attributesIdentifier, final NormalizedNode<?, ?> data) {
22 final OffsetMap oldMap = getOffsets();
23 final int offset = super.addRoute(routerId, attributesIdentifier, data);
24 final OffsetMap newMap = getOffsets();
26 if (!newMap.equals(oldMap)) {
27 this.values = newMap.expand(oldMap, this.values, offset);
30 newMap.setValue(this.values, offset, data);
35 protected MapEntryNode createValue(final PathArgument routeId) {
36 final OffsetMap map = getOffsets();
37 final int offset = map.offsetOf(getBestRouterId());
38 return map.getValue(this.values, offset);
42 boolean removeRoute(final UnsignedInteger routerId) {
43 final OffsetMap map = getOffsets();
44 final int offset = map.offsetOf(routerId);
45 final boolean ret = removeRoute(routerId, offset);
46 this.values = map.removeValue(this.values, offset);