Coverage Summary for Class: ModuleDescription (co.rsk.rpc)
Class |
Class, %
|
Method, %
|
Line, %
|
ModuleDescription |
0%
(0/1)
|
0%
(0/8)
|
0%
(0/34)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 RSK Labs Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package co.rsk.rpc;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 /**
25 * Created by ajlopez on 19/04/2017.
26 */
27 public class ModuleDescription {
28 private String name;
29 private String version;
30 private boolean enabled;
31
32 private List<String> enabledMethods;
33 private List<String> disabledMethods;
34
35 public ModuleDescription(String name, String version, boolean enabled, List<String> enabledMethods, List<String> disabledMethods) {
36 this.name = name;
37 this.version = version;
38 this.enabled = enabled;
39 this.enabledMethods = enabledMethods == null ? new ArrayList<>() : enabledMethods;
40 this.disabledMethods = disabledMethods == null ? new ArrayList<>() : disabledMethods;
41 }
42
43 public String getName() {
44 return this.name;
45 }
46
47 public String getVersion() {
48 return this.version;
49 }
50
51 public boolean isEnabled() {
52 return this.enabled;
53 }
54
55 public List<String> getEnabledMethods() {
56 return this.enabledMethods;
57 }
58
59 public List<String> getDisabledMethods() {
60 return this.disabledMethods;
61 }
62
63 public boolean methodIsInModule(String methodName) {
64 if (methodName == null) {
65 return false;
66 }
67
68 if (!methodName.startsWith(this.name)) {
69 return false;
70 }
71
72 if (methodName.length() == this.name.length()) {
73 return false;
74 }
75
76 if (methodName.charAt(this.name.length()) != '_') {
77 return false;
78 }
79
80 return true;
81 }
82
83 public boolean methodIsEnable(String methodName) {
84 if (!this.isEnabled()) {
85 return false;
86 }
87
88 if (!this.methodIsInModule(methodName)) {
89 return false;
90 }
91
92 if (this.disabledMethods.contains(methodName)) {
93 return false;
94 }
95
96 if (this.enabledMethods.isEmpty() && this.disabledMethods.isEmpty()) {
97 return true;
98 }
99
100 if (this.enabledMethods.contains(methodName)) {
101 return true;
102 }
103
104 if (!this.enabledMethods.isEmpty()) {
105 return false;
106 }
107
108 return true;
109 }
110 }