dc9cd94e7a9600a0f2d65368c871d79db21d7134
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.testsuites.integration.context.lock.modifier;
23
24 import org.onap.policy.apex.context.ContextRuntimeException;
25
26 /**
27  * The Enum LockType defines the type of lock on a test context album.
28  */
29 public enum LockType {
30
31     NO_LOCK(0) {
32         @Override
33         public AlbumModifier getAlbumModifier() {
34             return NO_LOCK_MODIFER;
35         }
36     },
37     READ_LOCK(1) {
38         @Override
39         public AlbumModifier getAlbumModifier() {
40             return READ_LOCK_MODIFER;
41         }
42     },
43     WRITE_LOCK(2) {
44         @Override
45         public AlbumModifier getAlbumModifier() {
46             return WRITE_LOCK_MODIFER;
47         }
48     },
49     WRITE_LOCK_SINGLE_VALUE_UPDATE(3) {
50         @Override
51         public AlbumModifier getAlbumModifier() {
52             return WRITE_LOCK_SINGLE_VALUE_MODIFER;
53         }
54     };
55
56     private static final AlbumModifier NO_LOCK_MODIFER = new NoLockAlbumModifier();
57     private static final AlbumModifier READ_LOCK_MODIFER = new ReadLockAlbumModifier();
58     private static final AlbumModifier WRITE_LOCK_MODIFER = new WriteLockAlbumModifier();
59     private static final AlbumModifier WRITE_LOCK_SINGLE_VALUE_MODIFER = new SingleValueWriteLockAlbumModifier();
60
61     private final int value;
62
63     /**
64      * Instantiates a new lock type.
65      *
66      * @param value the value
67      */
68     LockType(final int value) {
69         this.value = value;
70     }
71
72     /**
73      * Gets the value.
74      *
75      * @return the value
76      */
77     public int getValue() {
78         return value;
79     }
80
81     /**
82      * Get the lock type given an int value.
83      * @param value the value of lock type
84      * @return the lock type
85      */
86     public static LockType getLockType(final int value) {
87         for (final LockType lockType : LockType.values()) {
88             if (lockType.getValue() == value) {
89                 return lockType;
90             }
91         }
92         throw new ContextRuntimeException("Invalid Lock type value: " + value);
93     }
94
95     /**
96      * Gets the album modifier.
97      *
98      * @return the album modifier
99      */
100     public abstract AlbumModifier getAlbumModifier();
101
102 }