Skip to content

Commit c33ab09

Browse files
committed
chore: fixed qulice warnings
1 parent 13413e0 commit c33ab09

File tree

4 files changed

+130
-73
lines changed

4 files changed

+130
-73
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<plugin>
7878
<groupId>com.qulice</groupId>
7979
<artifactId>qulice-maven-plugin</artifactId>
80+
<version>0.22.2</version>
8081
<configuration>
8182
<license>file:${basedir}/LICENSE</license>
8283
</configuration>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2024 Decision-Driven Development
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package ru.ewc.spv.core;
26+
27+
import java.util.ArrayList;
28+
import java.util.List;
29+
import java.util.stream.Stream;
30+
31+
/**
32+
* I am an in-memory storage for the stored values.
33+
*
34+
* @since 0.0.1
35+
*/
36+
public class InMemoryStorage {
37+
/**
38+
* The next set identifier.
39+
*/
40+
private long next;
41+
42+
/**
43+
* The stored values.
44+
*/
45+
private final List<StoredValue> stored = new ArrayList<>(0);
46+
47+
/**
48+
* Adds a new specification to the storage.
49+
*
50+
* @param spec The specification to be added.
51+
*/
52+
public void add(final StoredValue spec) {
53+
this.stored.add(
54+
new StoredValue(
55+
this.setIdFor(spec),
56+
spec.property(),
57+
spec.value()
58+
)
59+
);
60+
}
61+
62+
/**
63+
* Returns all properties for a given set as a list.
64+
*
65+
* @param set The set's identifier.
66+
* @return A list of properties.
67+
*/
68+
public List<StoredValue> getAsList(final String set) {
69+
return this.allPropertiesFor(set).toList();
70+
}
71+
72+
/**
73+
* Returns all properties for a given set.
74+
*
75+
* @param set The set's identifier.
76+
* @return A stream of properties.
77+
*/
78+
private Stream<StoredValue> allPropertiesFor(final String set) {
79+
return this.stored.stream()
80+
.filter(specification -> set.equals(specification.set()));
81+
}
82+
83+
/**
84+
* Sets the identifier for a given specification. Returns a new ID if it's not specified in the
85+
* spec.
86+
*
87+
* @param spec The specification.
88+
* @return The identifier.
89+
*/
90+
private String setIdFor(final StoredValue spec) {
91+
final String result;
92+
if (spec.set() == null) {
93+
result = String.valueOf(++this.next);
94+
} else {
95+
result = spec.set();
96+
}
97+
return result;
98+
}
99+
100+
}

src/main/java/ru/ewc/spv/core/Storage.java

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/test/java/ru/ewc/spv/core/StorageTest.java renamed to src/test/java/ru/ewc/spv/core/InMemoryStorageTest.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,50 @@
2828
import org.hamcrest.Matchers;
2929
import org.junit.jupiter.api.Test;
3030

31-
public class StorageTest {
31+
/**
32+
* I am a test for the {@link InMemoryStorage} class.
33+
*
34+
* @since 0.0.1
35+
*/
36+
final class InMemoryStorageTest {
3237
@Test
3338
void shouldGetSetsWithSingleProperties() {
34-
final Storage actual = defaultStorage();
39+
final InMemoryStorage actual = defaultStorage();
3540
MatcherAssert.assertThat(
3641
"The storage property for the first set should be fetched",
37-
actual.get("1"),
38-
Matchers.equalTo(new StoredValue("1", "Property", "Value"))
42+
actual.getAsList("1"),
43+
Matchers.allOf(
44+
Matchers.iterableWithSize(1),
45+
Matchers.hasItems(new StoredValue("1", "Property", "Value"))
46+
)
3947
);
4048
MatcherAssert.assertThat(
4149
"The storage property for the second set should be fetched",
42-
actual.get("2"),
43-
Matchers.equalTo(new StoredValue("2", "NewProp", "NewValue"))
50+
actual.getAsList("2"),
51+
Matchers.allOf(
52+
Matchers.iterableWithSize(1),
53+
Matchers.hasItems(new StoredValue("2", "NewProp", "NewValue"))
54+
)
4455
);
4556
}
4657

4758
@Test
4859
void shouldGetSetWithMultipleProperties() {
49-
final Storage actual = defaultStorage();
60+
final InMemoryStorage actual = defaultStorage();
5061
MatcherAssert.assertThat(
5162
"Should fetch all properties of a set",
5263
actual.getAsList("3"),
53-
Matchers.hasItems(
54-
new StoredValue("3", "Property", "ValueTheThird"),
55-
new StoredValue("3", "AnotherProp", "AnotherValue")
64+
Matchers.allOf(
65+
Matchers.iterableWithSize(2),
66+
Matchers.hasItems(
67+
new StoredValue("3", "Property", "ValueTheThird"),
68+
new StoredValue("3", "AnotherProp", "AnotherValue")
69+
)
5670
)
5771
);
5872
}
5973

60-
private static Storage defaultStorage() {
74+
private static InMemoryStorage defaultStorage() {
6175
return storageWith(
6276
new StoredValue(null, "Property", "Value"),
6377
new StoredValue(null, "NewProp", "NewValue"),
@@ -66,10 +80,10 @@ private static Storage defaultStorage() {
6680
);
6781
}
6882

69-
private static Storage storageWith(StoredValue... specifications) {
70-
final Storage target = new Storage();
71-
for (StoredValue specification : specifications) {
72-
target.add(specification);
83+
private static InMemoryStorage storageWith(final StoredValue... specifications) {
84+
final InMemoryStorage target = new InMemoryStorage();
85+
for (final StoredValue spec : specifications) {
86+
target.add(spec);
7387
}
7488
return target;
7589
}

0 commit comments

Comments
 (0)