forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexRegistry.java
136 lines (120 loc) · 3.55 KB
/
IndexRegistry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2uct.packages;
import com.magento.idea.magento2uct.versioning.indexes.data.ApiCoverageStateIndex;
import com.magento.idea.magento2uct.versioning.indexes.data.DeprecationStateIndex;
import com.magento.idea.magento2uct.versioning.indexes.data.ExistenceStateIndex;
import com.magento.idea.magento2uct.versioning.processors.ApiCoverageIndexProcessor;
import com.magento.idea.magento2uct.versioning.processors.DeprecationIndexProcessor;
import com.magento.idea.magento2uct.versioning.processors.ExistenceIndexProcessor;
import com.magento.idea.magento2uct.versioning.processors.IndexProcessor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jetbrains.annotations.NotNull;
public enum IndexRegistry {
DEPRECATION(
DeprecationStateIndex.class,
new DeprecationIndexProcessor(),
SupportedVersion.getSupportedVersions().toArray(new String[0])
),
EXISTENCE(
ExistenceStateIndex.class,
new ExistenceIndexProcessor(),
SupportedVersion.getSupportedVersions().toArray(new String[0])
),
API_COVERAGE(
ApiCoverageStateIndex.class,
new ApiCoverageIndexProcessor(),
SupportedVersion.getSupportedVersions().toArray(new String[0])
);
private final String key;
private final Class<?> type;
private final IndexProcessor processor;
private final String[] versions;
IndexRegistry(
final Class<?> type,
final IndexProcessor processor,
final String... versions
) {
this.type = type;
this.processor = processor;
this.versions = Arrays.copyOf(versions, versions.length);
key = this.toString();
}
/**
* Get index key.
*
* @return String
*/
public String getKey() {
return key;
}
/**
* Get index type.
*
* @return Class[?]
*/
public Class<?> getType() {
return type;
}
/**
* Get index processor.
*
* @return IndexProcessor
*/
public IndexProcessor getProcessor() {
return processor;
}
/**
* Get registered versions.
*
* @return List[String]
*/
public List<String> getVersions() {
return Arrays.asList(versions);
}
/**
* Get registry record by index class.
*
* @param indexClass Class
*
* @return IndexRegistry
*/
public static IndexRegistry getRegistryInfoByClass(final @NotNull Class<?> indexClass) {
for (final IndexRegistry registeredIndexData : IndexRegistry.values()) {
if (indexClass.equals(registeredIndexData.getType())) {
return registeredIndexData;
}
}
return null;
}
/**
* Get registry record by index key.
*
* @param key String
*
* @return IndexRegistry
*/
public static IndexRegistry getRegistryInfoByKey(final @NotNull String key) {
try {
return IndexRegistry.valueOf(key);
} catch (IllegalArgumentException exception) {
return null;
}
}
/**
* Get list of available indexes names.
*
* @return List[String]
*/
public static List<String> getIndexList() {
final List<String> list = new ArrayList<>();
for (final IndexRegistry index : IndexRegistry.values()) {
list.add(index.getKey());
}
return list;
}
}