Skip to content

Commit 2f13ba2

Browse files
committed
use constructors over static methods
Signed-off-by: Kaushal Kumar <[email protected]>
1 parent a9ba56a commit 2f13ba2

File tree

5 files changed

+11
-28
lines changed

5 files changed

+11
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
- [Rule Based Auto-tagging] Add rule schema for auto tagging ([#17238](https://github.com/opensearch-project/OpenSearch/pull/17238))
1010
- Renaming the node role search to warm ([#17573](https://github.com/opensearch-project/OpenSearch/pull/17573))
1111
- Introduce a new search node role to hold search only shards ([#17620](https://github.com/opensearch-project/OpenSearch/pull/17620))
12-
- Fix systemd integTest on deb regarding path ownership check ([#17641](https://github.com/opensearch-project/OpenSearch/pull/17641))
12+
- Fix systemd integTest on deb regarding path ownership check ([#17641](https://github.com/opensearch-project/OpenSearch/pull/17641))
1313
- Add dfs transformation function in XContentMapValues ([#17612](https://github.com/opensearch-project/OpenSearch/pull/17612))
14-
- Added Kinesis support as a plugin for the pull-based ingestion ([#17615](https://github.com/opensearch-project/OpenSearch/pull/17615)
15-
- [Rule Based Auto-tagging] Add in-memory rule processing service [#17365](https://github.com/opensearch-project/OpenSearch/pull/17365)
14+
- Added Kinesis support as a plugin for the pull-based ingestion ([#17615](https://github.com/opensearch-project/OpenSearch/pull/17615))
15+
- [Rule Based Auto-tagging] Add in-memory rule processing service ([#17365](https://github.com/opensearch-project/OpenSearch/pull/17365))
1616
- [Security Manager Replacement] Create initial Java Agent to intercept Socket::connect calls ([#17724](https://github.com/opensearch-project/OpenSearch/pull/17724))
1717

1818
### Changed

libs/autotagging-commons/src/main/java/org/opensearch/rule/InMemoryRuleProcessingService.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,15 @@ public class InMemoryRuleProcessingService {
3131
private AttributeValueStoreFactory attributeValueStoreFactory;
3232

3333
/**
34-
* Make the instance accessible using static factory method only
35-
*/
36-
private InMemoryRuleProcessingService() {}
37-
38-
/**
39-
* This factory methods creates an instance of InMemoryRuleProcessingService to use auto-tagging framework
34+
* Constrcutor
4035
* @param featureType
4136
* @param attributeValueStoreSupplier
4237
*/
43-
public static InMemoryRuleProcessingService createForFeature(
38+
public InMemoryRuleProcessingService(
4439
FeatureType featureType,
4540
Supplier<AttributeValueStore<String, String>> attributeValueStoreSupplier
4641
) {
47-
InMemoryRuleProcessingService service = new InMemoryRuleProcessingService();
48-
service.attributeValueStoreFactory = AttributeValueStoreFactory.create(featureType, attributeValueStoreSupplier);
49-
return service;
42+
attributeValueStoreFactory = new AttributeValueStoreFactory(featureType, attributeValueStoreSupplier);
5043
}
5144

5245
/**

libs/autotagging-commons/src/main/java/org/opensearch/rule/storage/AttributeValueStoreFactory.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,14 @@ public class AttributeValueStoreFactory {
2222
private final Map<String, AttributeValueStore<String, String>> attributeValueStores = new HashMap<>();
2323

2424
/**
25-
* Making the class to be uninitializable
26-
*/
27-
private AttributeValueStoreFactory() {}
28-
29-
/**
30-
* This should be the first method to be invoked else the factory method will throw an exception
25+
* Constructor
3126
* @param featureType is the feature which are using rule based auto tagging
3227
* @param attributeValueStoreSupplier supplies the feature level AttributeValueStore instance
3328
*/
34-
public static AttributeValueStoreFactory create(
35-
FeatureType featureType,
36-
Supplier<AttributeValueStore<String, String>> attributeValueStoreSupplier
37-
) {
38-
final AttributeValueStoreFactory instance = new AttributeValueStoreFactory();
29+
public AttributeValueStoreFactory(FeatureType featureType, Supplier<AttributeValueStore<String, String>> attributeValueStoreSupplier) {
3930
for (Attribute attribute : featureType.getAllowedAttributesRegistry().values()) {
40-
instance.attributeValueStores.put(attribute.getName(), attributeValueStoreSupplier.get());
31+
attributeValueStores.put(attribute.getName(), attributeValueStoreSupplier.get());
4132
}
42-
return instance;
4333
}
4434

4535
/**

libs/autotagging-commons/src/test/java/org/opensearch/rule/InMemoryRuleProcessingServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class InMemoryRuleProcessingServiceTests extends OpenSearchTestCase {
2727

2828
public void setUp() throws Exception {
2929
super.setUp();
30-
sut = InMemoryRuleProcessingService.createForFeature(WLMFeatureType.WLM, DefaultAttributeValueStore::new);
30+
sut = new InMemoryRuleProcessingService(WLMFeatureType.WLM, DefaultAttributeValueStore::new);
3131
}
3232

3333
public void testAdd() {

libs/autotagging-commons/src/test/java/org/opensearch/rule/storage/AttributeValueStoreFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class AttributeValueStoreFactoryTests extends OpenSearchTestCase {
1919
@Override
2020
public void setUp() throws Exception {
2121
super.setUp();
22-
sut = AttributeValueStoreFactory.create(WLMFeatureType.WLM, () -> new DefaultAttributeValueStore<>());
22+
sut = new AttributeValueStoreFactory(WLMFeatureType.WLM, DefaultAttributeValueStore::new);
2323
}
2424

2525
public void testFeatureLevelStoreInitialisation() {

0 commit comments

Comments
 (0)