map-support-alpha

Map utilities.

License

License

GroupId

GroupId

fun.mike
ArtifactId

ArtifactId

map-support-alpha
Last Version

Last Version

0.0.17
Release Date

Release Date

Type

Type

jar
Description

Description

map-support-alpha
Map utilities.
Project URL

Project URL

https://github.com/mike706574/java-map-support
Source Code Management

Source Code Management

http://github.com/mike706574/java-map-support/tree/master

Download map-support-alpha

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
fun.mike : url-validation jar 0.0.1

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

map-support

Maven Central Javadocs

Map utilities for Java.

Examples

Factory methods

Unmodifiable maps

Use fun.mike.map.alpha.Factory/mapOf to make unordered unmodifiable maps.

import static fun.mike.map.alpha.Factory.mapOf;

Map<String, Integer> map = mapOf("foo", 1,
                                 "bar", 2);

// => {bar=2, foo=1} (java.util.Collections$UnmodifiableMap from java.util.HashMap)

Ordered unmodifiable maps

Use fun.mike.map.alpha.Factory/orderedMapOf to make ordered unmodifiable maps.

import static fun.mike.map.alpha.Factory.orderedMapOf;

Map<String, Integer> map = orderedMapOf("foo", 1,
                                        "bar", 2);

// => {foo=1, bar=2} (java.util.Collections$UnmodifiableMap from java.util.LinkedHashMap)

Mutable maps

Use fun.mike.map.alpha.MutableFactory/mutableMapOf to make unordered mutable maps.

import static fun.mike.map.alpha.Factory.mutableMapOf;

Map<String, Integer> map = mutableMapOf("foo", 1,
                                        "bar", 2);

// => {bar=2, foo=1} (java.util.HashMap)

Ordered mutable maps

Use fun.mike.map.alpha.MutableFactory/mutableMapOf to make ordered mutable maps.

import static fun.mike.map.alpha.MutableFactory.mutableOrderedMapOf;

Map<String, Integer> map = mutableOrderedMapOf("foo", 1,
                                               "bar", 2);

// => {foo=1, bar=2} (java.util.LinkedHashMap)

Access

Use fun.mike.map.alpha.Get to get validated values from maps.

Anything

import static fun.mike.map.alpha.Get.required;

Map<String, Object> map = mapOf("foo", "bar");

required(map, "foo");
// => "bar"

required(map, "baz");
// => java.util.NoSuchElementException: Missing required value for key "baz".

Strings

Required strings:

import static fun.mike.map.alpha.Get.requiredString;

Map<String, Object> map = mapOf("ok", "foo",
                                "text", 1);

requiredString(map, "ok");
// => "foo"

requiredString(map, "missing");
// => java.util.NoSuchElementException: Missing required string value for key "missing".

requiredString(map, "text");
// => java.lang.IllegalArgumentException: Value "1" of class "java.lang.Integer" for key "text" must be a string.

Populated strings:

import static fun.mike.map.alpha.Get.populatedString;

Map<String, Object> map = mapOf("ok", "foo",
                                "empty", " ",
                                "text", 1);

populatedString(map, "ok");
// => "foo"

populated(map, "missing");
    // => java.util.NoSuchElementException: Missing required string value for key "missing".

populated(map, "empty");
// => java.util.NoSuchElementException: Value " " for key "empty" must be populated.

populatedString(map, "text");
// => java.lang.IllegalArgumentException: Value "1" of class "java.lang.Integer" for key "text" must be a string.

String URLs:

import static fun.mike.map.alpha.Get.populatedString;

Map<String, Object> map = mapOf("valid", "http://foo.com",
                                "invalid", "hewa:/ea90mS-fwa");

populatedString(map, "valid");
// => "http://foo.com",

populatedString(map, "invalid");
// => java.lang.IllegalArgumentException: Invalid URL value "hewa:/ea90mS-fwa" for key "foo": Scheme "hewa" not allowed. Allowed schemes: http, https

Build

CircleCI

Copyright and License

This project is licensed under the terms of the Apache 2.0 license.

Versions

Version
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1