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