Bug 4827: MultiPathSupport utilities
[bgpcep.git] / bgp / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / AbstractNumericByteOperandParser.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.protocol.bgp.flowspec;
9
10 import java.util.List;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.NumericOperand;
12
13 /**
14  * Common parent class for numeric byte operands.
15  *
16  * @param <N> numeric operand type
17  */
18 abstract class AbstractNumericByteOperandParser<N, V extends Number> extends AbstractNumericOperandParser<N> {
19
20     @Override
21     public final <T extends N> String toString(final List<T> list) {
22         final StringBuilder buffer = new StringBuilder();
23         boolean isFirst = true;
24         for (final T item : list) {
25             buffer.append(super.toString(getOp(item), isFirst));
26             buffer.append(getValue(item));
27             buffer.append(' ');
28             if (isFirst) {
29                 isFirst = false;
30             }
31         }
32         return buffer.toString();
33     }
34
35     abstract <T extends N> V getValue(final T item);
36
37     abstract <T extends N> NumericOperand getOp(final T item);
38 }