Skip to content

Commit

Permalink
9.0.2 (#166)
Browse files Browse the repository at this point in the history
* feat: 🎸 map function JsInstant

* fix: πŸ› -1 index must point to the last element of an array

* ci: 🎑 9.0.2 version

* test: πŸ’ set element at -1 index
  • Loading branch information
imrafaelmerino committed Feb 14, 2021
1 parent d93516f commit dabb2c4
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 34 deletions.
15 changes: 8 additions & 7 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# JSON-VALUES
## v9.0.1 ( Sun Jan 31 2021 11:53:55 GMT+0100 (Central European Standard Time) )
## v9.0.2 ( Sun Feb 14 2021 16:13:16 GMT+0100 (Central European Standard Time) )

## Features
- 🎸 new method toPrettyString
([586aaf4a](https://github.com/imrafaelmerino/json-values/commit/586aaf4aa9e8fd9b3e0bd962866a702a23a2156d))

## Refactor
- πŸ’‘ remove public modifier from classes
([67904797](https://github.com/imrafaelmerino/json-values/commit/67904797ea1096810d97385fbf2dbe083d1a1348))
## Bug Fixes
- πŸ› -1 index must point to the last element of an array
([3fe0ff1e](https://github.com/imrafaelmerino/json-values/commit/3fe0ff1e3dfb1231ae258bbde8402a9fd53e6960))

## Features
- 🎸 map function JsInstant
([15bb08a1](https://github.com/imrafaelmerino/json-values/commit/15bb08a14568ff108349b4f4559ae7642868790c))



Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[![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/9.0.1)](https://search.maven.org/artifact/com.github.imrafaelmerino/json-values/9.0.1/jar)
[![Maven](https://img.shields.io/maven-central/v/com.github.imrafaelmerino/json-values/9.0.2)](https://search.maven.org/artifact/com.github.imrafaelmerino/json-values/9.0.2/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 @@ -178,7 +178,7 @@ Add the following dependency to your building tool:
<dependency>
<groupId>com.github.imrafaelmerino</groupId>
<artifactId>json-values</artifactId>
<version>9.0.1</version>
<version>9.0.2</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>9.0.1</version>
<version>9.0.2</version>
<name>json-values</name>
<description>json-values is a functional Java library to work with immutable jsons using persistent data structures.</description>
<url>https://github.com/imrafaelmerino/json-values</url>
Expand Down
30 changes: 8 additions & 22 deletions src/main/java/jsonvalues/JsArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -1531,42 +1531,28 @@ else if (head.equals(otherHead))
}

private Vector<JsValue> nullPadding(final int index,
final Vector<JsValue> arr,
Vector<JsValue> arr,
final JsValue e,
final JsValue pad
) {
assert arr != null;
assert e != null;

return nullPaddingTrampoline(index,
arr,
e,
pad
);
}
if (index == -1) return arr.append(e);
if (index == arr.size()) return arr.append(e);

private Vector<JsValue> nullPaddingTrampoline(final int i,
Vector<JsValue> arr,
final JsValue e,
final JsValue pad
) {

if (i == arr.size()) return arr.append(e);

if (i == -1) return arr.update(seq.size() - 1,
e
);

if (i < arr.size()) return arr.update(i,
if (index < arr.size()) return arr.update(index,
e
);
for (int j = arr.size(); j < i; j++) {
for (int j = arr.size(); j < index; j++) {
arr = arr.append(pad);
}
return arr.append(e);

}



@SuppressWarnings("squid:S00117") // ARRAY_AS is a perfectly fine name
private JsArray union(JsArray a,
JsArray b,
Expand Down Expand Up @@ -1610,7 +1596,7 @@ private JsArray unionAll(final JsArray a,
);

}
else if(!otherHead.isNothing() && head.isNothing()) result = result.append(otherHead);
else if (!otherHead.isNothing() && head.isNothing()) result = result.append(otherHead);
}

return result;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/jsonvalues/JsInstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

import static java.util.Objects.requireNonNull;

Expand All @@ -29,6 +30,10 @@ private JsInstant(final Instant value) {
this.value = value;
}

public JsInstant map(Function<Instant,Instant> fn){
return JsInstant.of(Objects.requireNonNull(fn).apply(value));
}

/**
prism between the sum type JsValue and JsInstant
*/
Expand Down
32 changes: 30 additions & 2 deletions src/test/java/jsonvalues/TestJsArray.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package jsonvalues;



import com.sun.org.apache.bcel.internal.generic.ANEWARRAY;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Base64;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.util.Arrays;
import java.util.Base64;
import java.util.Optional;
import java.util.function.Function;

Expand Down Expand Up @@ -1310,4 +1310,32 @@ public void test_filter_all_keys() {
array.filterKeys((k, v) -> false)
);
}

@Test
public void test_minus_one_index_points_last_element() {

JsArray array = JsArray.of(1,
2,
3
);

Assertions.assertTrue(array.getInt(-1) == 3);
}


@Test
public void test_set_minus_one_index_points_last_element() {

JsArray array = JsArray.of(1,
2,
3
);

JsArray newArray = array.set(JsPath.fromIndex(-1),
JsInt.of(4)
);
Assertions.assertTrue(4 == newArray.getInt(3)
);

}
}

0 comments on commit dabb2c4

Please sign in to comment.