OPNFLWPLUG-1071 : Removal of javax.annotation.Nonnnull and replacement of javax.annot...
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / util / VersionAssignableFactory.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.openflowjava.protocol.impl.util;
10
11 import org.eclipse.jdt.annotation.NonNull;
12
13 /**
14  * Abstract factory class to support OF protocol version assigning and reading.
15  */
16 public abstract class VersionAssignableFactory {
17     private Short version;
18
19     /**
20      * Assigns the version.
21      *
22      * @param newVersion OpenFlow protocol version
23      */
24     public void assignVersion(@NonNull final Short newVersion) {
25         if (this.version == null) {
26             this.version = newVersion;
27         } else {
28             throw new IllegalStateException("Version already assigned: " + this.version);
29         }
30     }
31
32     /**
33      * Returns the OpenFlow protocol version.
34      */
35     protected Short getVersion() {
36         return this.version;
37     }
38 }