me.andrz:map-builder

Fluent builder for Maps in Java.

License

License

GroupId

GroupId

me.andrz
ArtifactId

ArtifactId

map-builder
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

me.andrz:map-builder
Fluent builder for Maps in Java.
Project URL

Project URL

https://github.com/adjohnson916/map-builder-java
Source Code Management

Source Code Management

https://github.com/adjohnson916/map-builder-java

Download map-builder

How to add to project

<!-- https://jarcasting.com/artifacts/me.andrz/map-builder/ -->
<dependency>
    <groupId>me.andrz</groupId>
    <artifactId>map-builder</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/me.andrz/map-builder/
implementation 'me.andrz:map-builder:1.0.0'
// https://jarcasting.com/artifacts/me.andrz/map-builder/
implementation ("me.andrz:map-builder:1.0.0")
'me.andrz:map-builder:jar:1.0.0'
<dependency org="me.andrz" name="map-builder" rev="1.0.0">
  <artifact name="map-builder" type="jar" />
</dependency>
@Grapes(
@Grab(group='me.andrz', module='map-builder', version='1.0.0')
)
libraryDependencies += "me.andrz" % "map-builder" % "1.0.0"
[me.andrz/map-builder "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-all jar 1.3

Project Modules

There are no modules declared in this project.

map-builder-java

Download

Fluent builder for Maps in Java.

Easily initialize (as expressions) or modify java.util.Map instances with a DRY, fluent-style builder pattern. No more repeated variable names, static or instance initializer blocks, or double brace initialization. At least until Java 9's Map.of, and Map.ofEntries with Map.entry.

Use

Build a new map (HashMap by default):

import me.andrz.builder.map.MapBuilder;

// ...

Map<String, Integer> m = new MapBuilder<String, Integer>()
  .put( k1, v1 )
  .p( k2, v2 )
  .putAll( otherMap )
  .pa( otherMap2 )
  .put( mapEntry )
  .p( mapEntry2 )
  .remove( k2 )
  // ...
  .build();

Or, choose a Map implementation by passing its class:

Map<String, Integer> m = new MapBuilder<String, Integer>(LinkedHashMap.class)
  // ...
  .build();

Or, pass an existing map to be modified. This also allows choice of Map implementation:

Map<String, Integer> m = new MapBuilder<String, Integer>(new LinkedHashMap<String, Integer>())
  // ...
  .build();

Install

Maven

<dependencies>
    <dependency>
        <groupId>me.andrz</groupId>
        <artifactId>map-builder</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

Gradle

repositories {
    mavenCentral()
}

dependencies {
    compile 'me.andrz:map-builder:1.0.0'
}

Manual

Download JAR from Maven Central.

References

Versions

Version
1.0.0