fun.mike:record

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

GroupId

GroupId

fun.mike
ArtifactId

ArtifactId

record
Last Version

Last Version

0.1.7
Release Date

Release Date

Type

Type

jar
Description

Description

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

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

Source Code Management

http://github.com/mike706574/java-record/tree/master

Download record

How to add to project

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

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

record

Maven Central Javadocs

A friendly heterogeneous map class for Java.

Examples

Import it:

import fun.mike.record;

Make a Record by passing alternating keys and values:

Record rec = Record.of("str", "bar",
                       "integ", 5,
                       "bigdec", new BigDecimal("1.0"),
                       "boole", true,
                       "long", 5L,
                       "list", Arrays.asList("foo", "bar"),
                       "map", new HashMap<>());

Pull out values without casting:

String str = rec.getString("str");
// => "bar"

Integer integ = rec.getInteger("integ");
// => 5

BigDecimal bigdec = rec.getBigDecimal("bigdec");
// => 1.0

Boolean boole = rec.getBoolean("boole");
// => true

BigDecimal bigdec = rec.getLong("bigdec");
// => 1.0

List<String> = rec.getList("list"); // => [foo, bar]
// => [foo, bar]

Map<String, String> = rec.getMap("map");
// => {}

Get java.util.Optionals instead:

rec.optionalString("str").orElse("baz");
// => "bar"

rec.optionalString("wat").orElse("baz");
// => "baz"

rec.optionalInteger("wat").orElseThrow(() => new RuntimeException("wat"));
// => RuntimeException: wat

Here are all the access methods available:

Class Value java.util.Optional
java.lang.String getString optionalString
java.lang.Boolean getBoolean optionalBoolean
java.lang.Integer getInteger optionalInteger
java.lang.Long getLong optionalLong
java.lang.Float getFloat optionalFloat
java.lang.Double getDouble optionalDouble
java.math.BigDecimal getBigDecimal optionalBigDecimal
java.util.Date getDate optionalDate
java.util.List getList optionalList
java.util.Map getMap optionalMap
fun.mike.Record getRecord optionalRecord

A fun.mike.record.TypeMismatchException is thrown when the present value doesn't match the expected type:

Integer str = rec.getInteger("str");
=> fun.mike.record.TypeMismatchException: Value "foo" of class "java.lang.String" for key "str" must be an integer.

Records extend java.util.LinkedHashMap<String, Object>:

Object str = rec.get("str");
// => "bar"

Object str = rec.get("wat");
// => null

So they're mutable:

Record rec = Record.of("a", 1, "b", 2, "c", 3);
// => {a=1, b=2, c=3}

rec.put("d", "3");
// => {a=1, b=2, c=3, d=4}

rec
// => {a=1, b=2, c=3, d=4}

But you can use assoc, dissoc, and select to avoid mutation:

Record rec = Record.of("a", 1, "b", 2, "c", 3);
// => {a=1, b=2, c=3}

Record withD = rec.assoc("d", 4);
// => {a=1, b=2, c=3, d=4}

Record withoutA = rec.dissoc("a");
// => {b=2, c=3}

Record aAndB = rec.select("a", "b");
// => {a=1, b=2}

rec
// => {a=1, b=2, c=3}

Or use set to do a lot of mutation at once:

Record rec = Record.of("a", 1, "b", 2, "c", 3);
// => {a=1, b=2, c=3}

rec.set("b", 3, "c", 4, "d", 5, "e", 6);
// => {a=1, b=3, c=4, d=5, e=6}

rec
// => {a=1, b=3, c=4, d=5, e=6}

Build

CircleCI

Copyright and License

The use and distribution terms for this software are covered by the Eclipse Public License 1.0 which can be found in the file epl-v10.html at the root of this distribution. By using this softwaer in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.

Versions

Version
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0