Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPNonBranchNodeListObjectParser.java
1 /*
2  * Copyright (c) 2013 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.pcep.impl.object;
9
10 import java.util.List;
11
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
14 import org.opendaylight.protocol.pcep.PCEPObject;
15 import org.opendaylight.protocol.pcep.impl.PCEPEROSubobjectParser;
16 import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
17 import org.opendaylight.protocol.pcep.object.PCEPNonBranchNodeListObject;
18 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
19
20 public class PCEPNonBranchNodeListObjectParser implements PCEPObjectParser {
21
22         @Override
23         public PCEPNonBranchNodeListObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException {
24                 if (bytes == null || bytes.length == 0)
25                         throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
26
27                 final List<ExplicitRouteSubobject> subobjects = PCEPEROSubobjectParser.parse(bytes);
28                 if (subobjects.isEmpty())
29                         throw new PCEPDeserializerException("Empty Non-Branch Node List Object.");
30
31                 return new PCEPNonBranchNodeListObject(subobjects, processed, ignored);
32         }
33
34         @Override
35         public byte[] put(PCEPObject obj) {
36                 if (!(obj instanceof PCEPNonBranchNodeListObject))
37                         throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPNonBranchNodeListObject.");
38
39                 assert !(((PCEPNonBranchNodeListObject) obj).getSubobjects().isEmpty()) : "Empty Non-Branch Node List Object.";
40
41                 return PCEPEROSubobjectParser.put(((PCEPNonBranchNodeListObject) obj).getSubobjects());
42         }
43
44 }