Adding part-1 of naming micro-service code.
[ccsdk/apps.git] / ms / neng / src / main / java / org / onap / ccsdk / apps / ms / neng / core / policy / PolicySequence.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK.apps
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.apps.ms.neng.core.policy;
22
23 /**
24  * Represents a sequence object in the policy, as a POJO.
25  */
26 public class PolicySequence {
27     /**
28      * The type of the policy sequence. 
29      */
30     public enum Type { 
31         ALPHA, NUMERIC 
32     }
33
34     private long startValue;
35     private long increment;
36     private long length;
37     private Long maxValue;
38     private String maxValueString;
39     private Type type = Type.NUMERIC;
40     private String scope;
41     private String key;
42     private String value;
43     private Long lastReleaseSeqNumTried;
44
45     public long getStartValue() {
46         return startValue;
47     }
48
49     public void setStartValue(long startValue) {
50         this.startValue = startValue;
51     }
52
53     public long getIncrement() {
54         return increment;
55     }
56
57     public void setIncrement(long increment) {
58         this.increment = increment;
59     }
60
61     public long getLength() {
62         return length;
63     }
64
65     public void setLength(long length) {
66         this.length = length;
67     }
68
69     /**
70      * Generate and return the maximum value for the sequence.
71      */
72     public long getMaxValue() {
73         if (this.maxValue == null) {
74             int base = 10;
75             if (this.type == Type.ALPHA) {
76                 base = 36;
77             }
78             if (this.maxValueString != null) {
79                 try {
80                     this.maxValue = Long.valueOf(this.maxValueString, base);
81                 } catch (Exception e) {
82                     this.maxValue = null;
83                 }
84             }
85             if (this.maxValue == null) {
86                 long length = this.length;
87                 if (length <= 0) {
88                     length = 3;
89                 }
90                 this.maxValue = (long) Math.pow(base, length) - 1;
91             }
92         }
93         return maxValue;
94     }
95
96     public void setMaxValue(long maxValue) {
97         this.maxValue = maxValue;
98     }
99
100     public String getMaxValueString() {
101         return maxValueString;
102     }
103
104     public void setMaxValueString(String maxValueString) {
105         this.maxValueString = maxValueString;
106     }
107
108     public Type getType() {
109         return type;
110     }
111
112     public void setType(Type type) {
113         this.type = type;
114     }
115
116     /**
117      * Sets the type.
118      */
119     public void setType(String typeStr) {
120         if ("numeric".equalsIgnoreCase(typeStr)) {
121             setType(Type.NUMERIC);
122         } else if ("alpha-numeric".equalsIgnoreCase(typeStr)) {
123             setType(Type.ALPHA);
124         }
125     }
126
127     public String getScope() {
128         return scope;
129     }
130
131     public void setScope(String scope) {
132         this.scope = scope;
133     }
134
135     public String getValue() {
136         return value;
137     }
138
139     public void setValue(String value) {
140         this.value = value;
141     }
142
143     public String getKey() {
144         return key;
145     }
146
147     public void setKey(String key) {
148         this.key = key;
149     }
150
151     public Long getLastReleaseSeqNumTried() {
152         return lastReleaseSeqNumTried;
153     }
154
155     public void setLastReleaseSeqNumTried(Long lastReleaseSeqNumTried) {
156         this.lastReleaseSeqNumTried = lastReleaseSeqNumTried;
157     }
158 }