fun.mike:record-alpha

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

Лицензия

Лицензия

Группа

Группа

fun.mike
Идентификатор

Идентификатор

record-alpha
Последняя версия

Последняя версия

0.0.38
Дата

Дата

Тип

Тип

jar
Описание

Описание

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Ссылка на сайт

Ссылка на сайт

https://github.com/mike706574/java-record
Система контроля версий

Система контроля версий

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

Скачать record-alpha

Как подключить последнюю версию

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

Зависимости

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12

Модули Проекта

Данный проект не имеет модулей.

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.

Версии библиотеки

Версия
0.0.38
0.0.37
0.0.35
0.0.34
0.0.33
0.0.32
0.0.31
0.0.30
0.0.28
0.0.25
0.0.24
0.0.23
0.0.22
0.0.21
0.0.20
0.0.19
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.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1