Refactor to remove useless wavelength reference
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / fixedflex / SpectrumInformation.java
1 /*
2  * Copyright © 2020 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 java.math.BigDecimal;
12 import java.math.RoundingMode;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.OchAttributes.ModulationFormat;
14 import org.opendaylight.yangtools.yang.common.Uint32;
15
16 /**
17  * Spectrum information for cross connect and openroadm interfaces management.
18  */
19 public class SpectrumInformation {
20     private Uint32 waveLength;
21     private int lowerSpectralSlotNumber;
22     private int higherSpectralSlotNumber;
23     private BigDecimal width = GridConstant.WIDTH_40;
24     private BigDecimal centerFrequency;
25     private BigDecimal minFrequency;
26     private BigDecimal maxFrequency;
27     private String modulationFormat = ModulationFormat.DpQpsk.name();
28     private int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
29
30     public String getSpectralSlotFormat() {
31         return String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
32                 String.valueOf(lowerSpectralSlotNumber),
33                 String.valueOf(higherSpectralSlotNumber));
34     }
35
36     public String getIdentifierFromParams(String...params) {
37         String joinedParams = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, params);
38         return String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, joinedParams, getSpectralSlotFormat());
39     }
40
41     /**
42      * Get the wavelength.
43      * @return the waveLength
44      */
45     public Uint32 getWaveLength() {
46         return waveLength;
47     }
48
49     /**
50      * Set the wavelength.
51      * @param waveLength the waveLength to set
52      */
53     public void setWaveLength(Uint32 waveLength) {
54         this.waveLength = waveLength;
55         if (waveLength == null || waveLength.longValue() == GridConstant.IRRELEVANT_WAVELENGTH_NUMBER) {
56             scale = GridConstant.FLEX_GRID_FREQUENCY_PRECISION;
57         }
58     }
59
60     /**
61      * Get the lower spectral slot number.
62      * @return the lowerSpectralSlotNumber
63      */
64     public int getLowerSpectralSlotNumber() {
65         return lowerSpectralSlotNumber;
66     }
67
68     /**
69      * Set the lower spectral slot number.
70      * @param lowerSpectralSlotNumber the lowerSpectralSlotNumber to set
71      */
72     public void setLowerSpectralSlotNumber(int lowerSpectralSlotNumber) {
73         this.lowerSpectralSlotNumber = lowerSpectralSlotNumber;
74     }
75
76     /**
77      * Get the higher spectral slot number.
78      * @return the higherSpectralSlotNumber
79      */
80     public int getHigherSpectralSlotNumber() {
81         return higherSpectralSlotNumber;
82     }
83
84     /**
85      * Set the higher spectral slot number.
86      * @param higherSpectralSlotNumber the higherSpectralSlotNumber to set
87      */
88     public void setHigherSpectralSlotNumber(int higherSpectralSlotNumber) {
89         this.higherSpectralSlotNumber = higherSpectralSlotNumber;
90     }
91
92     /**
93      * Get the frequency width.
94      * @return the width
95      */
96     public BigDecimal getWidth() {
97         return width;
98     }
99
100     /**
101      * Set the frequency width.
102      * @param width the width to set
103      */
104     public void setWidth(BigDecimal width) {
105         this.width = width;
106     }
107
108     /**
109      * Get center frequency.
110      * @return the centerFrequency
111      */
112     public BigDecimal getCenterFrequency() {
113         return centerFrequency;
114     }
115
116     /**
117      * Set center frequency.
118      * @param centerFrequency the centerFrequency to set
119      */
120     public void setCenterFrequency(BigDecimal centerFrequency) {
121         this.centerFrequency = centerFrequency.setScale(scale, RoundingMode.HALF_EVEN);
122     }
123
124     /**
125      * Get min frequency.
126      * @return the minFrequency
127      */
128     public BigDecimal getMinFrequency() {
129         return minFrequency;
130     }
131
132     /**
133      * Set min frequency.
134      * @param minFrequency the minFrequency to set
135      */
136     public void setMinFrequency(BigDecimal minFrequency) {
137         this.minFrequency = minFrequency.setScale(scale, RoundingMode.HALF_EVEN);
138     }
139
140     /**
141      * Get max frequency.
142      * @return the maxFrequency
143      */
144     public BigDecimal getMaxFrequency() {
145         return maxFrequency;
146     }
147
148     /**
149      * Set max frequency.
150      * @param maxFrequency the maxFrequency to set
151      */
152     public void setMaxFrequency(BigDecimal maxFrequency) {
153         this.maxFrequency = maxFrequency.setScale(scale, RoundingMode.HALF_EVEN);
154     }
155
156     /**
157      * Get the modulation format.
158      * @return the modulationFormat
159      */
160     public String getModulationFormat() {
161         return modulationFormat;
162     }
163
164     /**
165      * Set the modulation format.
166      * @param modulationFormat the modulationFormat to set
167      */
168     public void setModulationFormat(String modulationFormat) {
169         this.modulationFormat = modulationFormat;
170     }
171
172     /*
173     * (non-Javadoc)
174     *
175     * @see java.lang.Object#toString()
176     */
177     @Override
178     public String toString() {
179         StringBuilder builder = new StringBuilder();
180         builder.append("SpectrumInformation [waveLength=").append(waveLength).append(", lowerSpectralSlotNumber=")
181                 .append(lowerSpectralSlotNumber).append(", higherSpectralSlotNumber=").append(higherSpectralSlotNumber)
182                 .append(", width=").append(width).append(", centerFrequency=").append(centerFrequency)
183                 .append(", minFrequency=").append(minFrequency).append(", maxFrequency=").append(maxFrequency)
184                 .append(", modulationFormat=").append(modulationFormat).append(", scale=").append(scale).append("]");
185         return builder.toString();
186     }
187 }