Skip to content

Commit

Permalink
v8.3.0 (#150)
Browse files Browse the repository at this point in the history
* fix: πŸ› lenses methods returns impls, nullpointer compose

Closes: #149

* ci: 🎑 release v8.3.0

pom, changes and readme
  • Loading branch information
imrafaelmerino committed Aug 14, 2020
1 parent ca746d3 commit 7fa7f5c
Show file tree
Hide file tree
Showing 21 changed files with 185 additions and 123 deletions.
11 changes: 5 additions & 6 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# JSON-VALUES
## v8.2.2 ( Tue Aug 04 2020 15:37:27 GMT+0200 (Central European Summer Time) )
## v8.3.0 ( Fri Aug 14 2020 02:37:38 GMT+0200 (Central European Summer Time) )


## Features
- 🎸 Lens,Option and Prism are public
([5bd2459d](https://github.com/imrafaelmerino/json-values/commit/5bd2459db0551e7b2da182e45965242e1b69ce3f))
- 🎸 TesProperty class to do property based testing
([6ba34465](https://github.com/imrafaelmerino/json-values/commit/6ba34465163e23e7ecd18525424129757f4bfc1c))
## Bug Fixes
- πŸ› lenses methods returns impls, nullpointer compose
([be84679e](https://github.com/imrafaelmerino/json-values/commit/be84679e796dea2f883363470338265c32d14b7b))




4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

[![Javadocs](https://www.javadoc.io/badge/com.github.imrafaelmerino/json-values.svg)](https://www.javadoc.io/doc/com.github.imrafaelmerino/json-values)
[![Maven](https://img.shields.io/maven-central/v/com.github.imrafaelmerino/json-values/8.2.2)](https://search.maven.org/artifact/com.github.imrafaelmerino/json-values/8.2.2/jar)
[![Maven](https://img.shields.io/maven-central/v/com.github.imrafaelmerino/json-values/8.3.0)](https://search.maven.org/artifact/com.github.imrafaelmerino/json-values/8.3.0/jar)
[![](https://jitpack.io/v/imrafaelmerino/json-values.svg)](https://jitpack.io/#imrafaelmerino/json-values)

[![Gitter](https://badges.gitter.im/json-values/community.svg)](https://gitter.im/json-values/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Expand Down Expand Up @@ -214,7 +214,7 @@ Add the following dependency to your building tool:
<dependency>
<groupId>com.github.imrafaelmerino</groupId>
<artifactId>json-values</artifactId>
<version>8.2.2</version>
<version>8.3.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.github.imrafaelmerino</groupId>
<artifactId>json-values</artifactId>
<packaging>jar</packaging>
<version>8.2.2</version>
<version>8.3.0</version>

<name>json-values</name>
<description>json-values is a functional Java library to work with immutable jsons using persistent data structures.</description>
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/jsonvalues/JsArrayLens.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
package jsonvalues;


import static java.util.Objects.requireNonNull;

/**
Represent a Lens which focus is an array located at a path in a Json
@param <S> the type of the whole part, an array or an object */
class JsArrayLens<S extends Json<S>> extends Lens<S, JsArray> {
JsArrayLens(final JsPath path) {
super(json -> json.getArray(path),
a -> json -> json.set(path,
a)
super(json -> requireNonNull(json).getArray(path),
a -> json -> requireNonNull(json).set(path,
a
)
);
}

@Override
public <B> Lens<S, B> compose(final Lens<JsArray, B> other) {
return new Lens<>(this.get.andThen(other.get),
b -> s -> {
JsArray o = this.get.apply(requireNonNull(s));
JsArray newO = other.set.apply(requireNonNull(b))
.apply(o == null ? JsArray.empty() : o);
return this.set.apply(newO)
.apply(s);
}
);
}
}
6 changes: 4 additions & 2 deletions src/main/java/jsonvalues/JsBigIntLens.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

import java.math.BigInteger;

import static java.util.Objects.requireNonNull;

/**
Represent a Lens which focus is a biginteger number located at a path in a Json
@param <S> the type of the whole part, an array or an object */
class JsBigIntLens<S extends Json<S>> extends Lens<S, BigInteger> {
JsBigIntLens(final JsPath path) {
super(json -> json.getBigInt(path),
n -> json -> json.set(path,
super(json -> requireNonNull(json).getBigInt(path),
n -> json -> requireNonNull(json).set(path,
JsBigInt.of(n))
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/jsonvalues/JsBinaryLens.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package jsonvalues;


import static java.util.Objects.requireNonNull;

/**
Represent a Lens which focus is an array of bytes located at a path in a Json
@param <S> the type of the whole part, an array or an object */
public class JsBinaryLens<S extends Json<S>> extends Lens<S, byte[]> {
JsBinaryLens(final JsPath path) {
super(json -> json.getBinary(path),
o -> json -> json.set(path,
super(json -> requireNonNull(json).getBinary(path),
o -> json -> requireNonNull(json).set(path,
JsBinary.of(o))
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/jsonvalues/JsBoolLens.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package jsonvalues;


import static java.util.Objects.requireNonNull;

/**
* Represent a Lens which focus is a boolean located at a path in a Json
*
* @param <S> the type of the whole part, an array or an object
*/
class JsBoolLens<S extends Json<S>> extends Lens<S, Boolean> {
JsBoolLens(final JsPath path) {
super(json -> json.getBool(path),
n -> json -> json.set(path, JsBool.of(n))
super(json -> requireNonNull(json).getBool(path),
n -> json -> requireNonNull(json).set(path, JsBool.of(n))
);
}
}
6 changes: 4 additions & 2 deletions src/main/java/jsonvalues/JsDecimalLens.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import java.math.BigDecimal;

import static java.util.Objects.requireNonNull;

/**
Represent a Lens which focus is a decimal number located at a path in a Json
@param <S> the type of the whole part, an array or an object */
class JsDecimalLens<S extends Json<S>> extends Lens<S, BigDecimal> {
JsDecimalLens(final JsPath path) {
super(json -> json.getBigDec(path),
n -> json -> json.set(path,
super(json -> requireNonNull(json).getBigDec(path),
n -> json -> requireNonNull(json).set(path,
JsBigDec.of(n))
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/jsonvalues/JsDoubleLens.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package jsonvalues;


import static java.util.Objects.requireNonNull;

/**
Represent a Lens which focus is a double number located at a path in a Json
@param <S> the type of the whole part, an array or an object */
class JsDoubleLens<S extends Json<S>> extends Lens<S, Double> {
JsDoubleLens(final JsPath path) {
super(json -> json.getDouble(path),
n -> json -> json.set(path,
JsDouble.of(n))
super(json -> requireNonNull(json).getDouble(path),
n -> json -> requireNonNull(json).set(path,
JsDouble.of(n)
)
);
}
}
6 changes: 4 additions & 2 deletions src/main/java/jsonvalues/JsInstantLens.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

import java.time.Instant;

import static java.util.Objects.requireNonNull;

/**
Represent a Lens which focus is an Instant located at a path in a Json
@param <S> the type of the whole part, an array or an object */
public class JsInstantLens<S extends Json<S>> extends Lens<S, Instant> {
JsInstantLens(final JsPath path) {
super(json -> json.getInstant(path),
o -> json -> json.set(path,
super(json -> requireNonNull(json).getInstant(path),
o -> json -> requireNonNull(json).set(path,
JsInstant.of(o))
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/jsonvalues/JsIntLens.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package jsonvalues;

import static java.util.Objects.requireNonNull;

/**
* Represent a Lens which focus is an integer number located at a path in a Json
*
* @param <S> the type of the whole part, an array or an object
*/
class JsIntLens<S extends Json<S>> extends Lens<S, Integer> {
JsIntLens(final JsPath path) {
super(json -> json.getInt(path),
n -> json -> json.set(path, JsInt.of(n))
super(json -> requireNonNull(json).getInt(path),
n -> json -> requireNonNull(json).set(path, JsInt.of(n))
);
}
}
6 changes: 4 additions & 2 deletions src/main/java/jsonvalues/JsLongLens.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package jsonvalues;

import static java.util.Objects.requireNonNull;

/**
Represent a Lens which focus is a long number located at a path is a Json
@param <S> the type of the whole part, an array or an object */
class JsLongLens<S extends Json<S>> extends Lens<S, Long> {
JsLongLens(final JsPath path) {
super(json -> json.getLong(path),
n -> json -> json.set(path,
super(json -> requireNonNull(json).getLong(path),
n -> json -> requireNonNull(json).set(path,
JsLong.of(n))
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jsonvalues/JsObj.java
Original file line number Diff line number Diff line change
Expand Up @@ -1938,5 +1938,7 @@ private Trampoline<JsObj> unionAll(final JsObj a,
}




}

23 changes: 20 additions & 3 deletions src/main/java/jsonvalues/JsObjLens.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
package jsonvalues;


import static java.util.Objects.requireNonNull;

/**
Represent a Lens which focus is a json object located at a path is a Json
@param <S> the type of the whole part, an array or an object */
public class JsObjLens<S extends Json<S>> extends Lens<S, JsObj> {
class JsObjLens<S extends Json<S>> extends Lens<S, JsObj> {
JsObjLens(final JsPath path) {
super(json -> json.getObj(path),
o -> json -> json.set(path,
super(json -> requireNonNull(json).getObj(path),
o -> json -> requireNonNull(json).set(path,
o)
);
}


@Override
public <B> Lens<S, B> compose(final Lens<JsObj, B> other) {
return new Lens<>(this.get.andThen(other.get),
b -> s -> {
JsObj o = this.get.apply(requireNonNull(s));
JsObj newO = other.set.apply(requireNonNull(b))
.apply(o == null ? JsObj.empty() : o);
return this.set.apply(newO)
.apply(s);
}
);
}

}
Loading

0 comments on commit 7fa7f5c

Please sign in to comment.