Skip to content

Commit 630a3ee

Browse files
committed
improve javadoc for attribute value store
Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com>
1 parent acdb27c commit 630a3ee

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/rule/storage/AttributeValueStore.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616
public interface AttributeValueStore<K, V> {
1717
/**
18-
* Adds the value to the data structure
18+
* Adds the value to attribute value store
1919
* @param key to be added
2020
* @param value to be added
2121
*/
22-
void add(K key, V value);
22+
void put(K key, V value);
2323

2424
/**
25-
* removes the key and associated value from the data structure
25+
* removes the key and associated value from attribute value store
2626
* @param key to be removed
2727
*/
2828
void remove(K key);
@@ -35,7 +35,7 @@ public interface AttributeValueStore<K, V> {
3535
Optional<V> get(K key);
3636

3737
/**
38-
* Clears all the keys and their associated values from the structure
38+
* Clears all the keys and their associated values from the attribute value store
3939
*/
4040
void clear();
4141

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/rule/storage/DefaultAttributeValueStore.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public DefaultAttributeValueStore(PatriciaTrie<V> trie) {
3838
}
3939

4040
@Override
41-
public void add(K key, V value) {
41+
public void put(K key, V value) {
4242
trie.put(key, value);
4343
}
4444

@@ -54,7 +54,7 @@ public Optional<V> get(String key) {
5454
* It is important to find the largest matching prefix key in the trie efficiently
5555
* Hence we can do binary search
5656
*/
57-
String longestMatchingPrefix = findLongestMatchingPrefix(key);
57+
final String longestMatchingPrefix = findLongestMatchingPrefix(key);
5858

5959
/**
6060
* Now there are following cases for this prefix
@@ -76,12 +76,10 @@ private String findLongestMatchingPrefix(String key) {
7676

7777
while (low < high) {
7878
int mid = low + (high - low + 1) / 2;
79-
String possibleMatchingPrefix = key.substring(0, mid);
80-
8179
/**
8280
* This operation has O(1) complexity because prefixMap returns only the iterator
8381
*/
84-
if (!trie.prefixMap(possibleMatchingPrefix).isEmpty()) {
82+
if (!trie.prefixMap(key.substring(0, mid)).isEmpty()) {
8583
low = mid;
8684
} else {
8785
high = mid - 1;

plugins/workload-management/src/test/java/org/opensearch/plugin/wlm/rule/storage/AttributeValueStoreTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@ public void setUp() throws Exception {
2020
subjectUnderTest = new DefaultAttributeValueStore<>(new PatriciaTrie<>());
2121
}
2222

23-
public void testAdd() {
24-
subjectUnderTest.add("foo", "bar");
23+
public void testPut() {
24+
subjectUnderTest.put("foo", "bar");
2525
assertEquals("bar", subjectUnderTest.get("foo").get());
2626
}
2727

2828
public void testRemove() {
29-
subjectUnderTest.add("foo", "bar");
29+
subjectUnderTest.put("foo", "bar");
3030
subjectUnderTest.remove("foo");
3131
assertEquals(0, subjectUnderTest.size());
3232
}
3333

3434
public void tesGet() {
35-
subjectUnderTest.add("foo", "bar");
35+
subjectUnderTest.put("foo", "bar");
3636
assertEquals("bar", subjectUnderTest.get("foo").get());
3737
}
3838

3939
public void testGetWhenNoProperPrefixIsPresent() {
40-
subjectUnderTest.add("foo", "bar");
41-
subjectUnderTest.add("foodip", "sing");
40+
subjectUnderTest.put("foo", "bar");
41+
subjectUnderTest.put("foodip", "sing");
4242
assertTrue(subjectUnderTest.get("foxtail").isEmpty());
43-
subjectUnderTest.add("fox", "lucy");
43+
subjectUnderTest.put("fox", "lucy");
4444

4545
assertFalse(subjectUnderTest.get("foxtail").isEmpty());
4646
}
4747

4848
public void testClear() {
49-
subjectUnderTest.add("foo", "bar");
49+
subjectUnderTest.put("foo", "bar");
5050
subjectUnderTest.clear();
5151
assertEquals(0, subjectUnderTest.size());
5252
}

0 commit comments

Comments
 (0)