Fix bug in FixedFlexImpl and its use by renderer
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / fixedflex / FixedFlexImpl.java
1 /*
2  * Copyright © 2017 Orange, 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
9 package org.opendaylight.transportpce.common.fixedflex;
10
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 public final class FixedFlexImpl implements FixedFlexInterface {
15     private static final Logger LOG = LoggerFactory.getLogger(FixedFlexImpl.class);
16     private long index;
17     private double centerFrequency;
18     private double start;
19     private double stop;
20     private double wavelength;
21
22     public FixedFlexImpl(Long index, double centreFrequency, double start, double stop, double wavelength) {
23         this.index = index;
24         this.centerFrequency = centreFrequency;
25         this.start = start;
26         this.stop = stop;
27         this.wavelength = wavelength;
28     }
29
30     public FixedFlexImpl() {
31         this.index = 0L;
32         this.centerFrequency = 0;
33         this.start = 0;
34         this.stop = 0;
35         this.wavelength = 0;
36     }
37
38     public FixedFlexImpl(long wlIndex) {
39         this.index = wlIndex;
40         this.centerFrequency = 196.1 - (wlIndex - 1) * 0.05;
41         this.start = this.centerFrequency - 0.025;
42         this.stop = this.centerFrequency + 0.025;
43         this.wavelength = 1528.77 + ((wlIndex - 1) * 0.39);
44     }
45
46     @Override
47     /**
48      * @param index Wavelength number
49      * @return Returns FixedFlexImp object with the calculated result.
50      **/
51     public FixedFlexImpl getFixedFlexWaveMapping(long wlIndex) {
52         FixedFlexImpl fixedFlex = new FixedFlexImpl();
53         fixedFlex.centerFrequency = 196.1 - (wlIndex - 1) * 0.05;
54         fixedFlex.wavelength = 1528.77 + ((wlIndex - 1) * 0.39);
55         fixedFlex.start = fixedFlex.centerFrequency - 0.025;
56         fixedFlex.stop = fixedFlex.centerFrequency + 0.025;
57         return fixedFlex;
58     }
59
60     public double getCenterFrequency() {
61         return centerFrequency;
62     }
63
64     public double getStart() {
65         return start;
66     }
67
68     public long getIndex() {
69         return index;
70     }
71
72     public double getStop() {
73         return stop;
74     }
75
76     public double getWavelength() {
77         return wavelength;
78     }
79 }