Skip to content

Commit

Permalink
Use convenience factory methods for collections
Browse files Browse the repository at this point in the history
Use convenience factory methods for collections instead of double brace initialization.
  • Loading branch information
marschall committed Nov 15, 2024
1 parent 7c8c244 commit 811b763
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static Map<String, Object> buildPersonAsMap() {
person.put("lastName", "Smith");
person.put("age", 25);

Map<String, Object> address = Optional.of(new HashMap<String, Object>()).get();
Map<String, Object> address = new HashMap<>();
address.put("streetAddress", "21 2nd Street");
address.put("city", "New York");
address.put("state", "NY");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,7 @@ void testGeneratorBuf() {
@Test
void testBufferPoolFeature() {
final JsonParserTest.MyBufferPool bufferPool = new JsonParserTest.MyBufferPool(1024);
Map<String, Object> config = new HashMap<String, Object>() {{
put(BufferPool.class.getName(), bufferPool);
}};
Map<String, Object> config = Map.of(BufferPool.class.getName(), bufferPool);

JsonGeneratorFactory factory = Json.createGeneratorFactory(config);
JsonGenerator generator = factory.createGenerator(new StringWriter());
Expand All @@ -518,9 +516,7 @@ void testBufferSizes() {
JsonBuilderFactory bf = Json.createBuilderFactory(null);
for(int size=10; size < 1000; size++) {
final JsonParserTest.MyBufferPool bufferPool = new JsonParserTest.MyBufferPool(size);
Map<String, Object> config = new HashMap<String, Object>() {{
put(BufferPool.class.getName(), bufferPool);
}};
Map<String, Object> config = Map.of(BufferPool.class.getName(), bufferPool);
JsonGeneratorFactory gf = Json.createGeneratorFactory(config);

StringBuilder sb = new StringBuilder();
Expand Down
12 changes: 3 additions & 9 deletions impl/src/test/java/org/eclipse/parsson/tests/JsonParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,7 @@ boolean isRecycleCalled() {
@Test
void testBufferPoolFeature() {
final MyBufferPool bufferPool = new MyBufferPool(1024);
Map<String, Object> config = new HashMap<String, Object>() {{
put(BufferPool.class.getName(), bufferPool);
}};
Map<String, Object> config = Map.of(BufferPool.class.getName(), bufferPool);

JsonParserFactory factory = Json.createParserFactory(config);
try (JsonParser parser = factory.createParser(new StringReader("[]"))) {
Expand All @@ -711,9 +709,7 @@ void testBufferSizes() {
Random r = new Random(System.currentTimeMillis());
for(int size=100; size < 1000; size++) {
final MyBufferPool bufferPool = new MyBufferPool(size);
Map<String, Object> config = new HashMap<String, Object>() {{
put(BufferPool.class.getName(), bufferPool);
}};
Map<String, Object> config = Map.of(BufferPool.class.getName(), bufferPool);
JsonParserFactory factory = Json.createParserFactory(config);

StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -790,9 +786,7 @@ void testIntegerUsingStandardBuffer() throws Throwable {
void testStringUsingBuffers() throws Throwable {
for(int size=20; size < 500; size++) {
final MyBufferPool bufferPool = new MyBufferPool(size);
Map<String, Object> config = new HashMap<String, Object>() {{
put(BufferPool.class.getName(), bufferPool);
}};
Map<String, Object> config = Map.of(BufferPool.class.getName(), bufferPool);
JsonParserFactory factory = Json.createParserFactory(config);

StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ void testDuplicateKeysLast() {
void testEmptyStringUsingBuffers() throws Throwable {
for(int size=20; size < 500; size++) {
final JsonParserTest.MyBufferPool bufferPool = new JsonParserTest.MyBufferPool(size);
Map<String, Object> config = new HashMap<String, Object>() {{
put(BufferPool.class.getName(), bufferPool);
}};
Map<String, Object> config = Map.of(BufferPool.class.getName(), bufferPool);
JsonReaderFactory factory = Json.createReaderFactory(config);

StringBuilder sb = new StringBuilder();
Expand Down

0 comments on commit 811b763

Please sign in to comment.