Skip to content

Commit 19889ea

Browse files
jknackEdgar Espina
authored andcommitted
remove javaslang dependency fix jooby-project#757
1 parent d32be28 commit 19889ea

File tree

138 files changed

+5123
-5359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+5123
-5359
lines changed

jooby/pom.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
45

56
<parent>
67
<groupId>org.jooby</groupId>
@@ -117,10 +118,10 @@
117118
<optional>true</optional>
118119
</dependency>
119120

120-
<!-- javaslang -->
121+
<!-- funzy -->
121122
<dependency>
122-
<groupId>io.javaslang</groupId>
123-
<artifactId>javaslang</artifactId>
123+
<groupId>org.jooby</groupId>
124+
<artifactId>funzy</artifactId>
124125
</dependency>
125126

126127
<!-- Guava -->

jooby/src/main/java/org/jooby/Cookie.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,8 @@
206206
import com.google.common.base.Splitter;
207207
import com.google.common.base.Strings;
208208
import com.google.common.io.BaseEncoding;
209-
import javaslang.Tuple;
210-
import javaslang.Tuple2;
211-
import javaslang.control.Try;
209+
import static java.util.Objects.requireNonNull;
210+
import org.jooby.funzy.Throwing;
212211
import org.jooby.internal.CookieImpl;
213212

214213
import javax.crypto.Mac;
@@ -225,8 +224,6 @@
225224
import java.util.regex.Pattern;
226225
import java.util.stream.Collectors;
227226

228-
import static java.util.Objects.requireNonNull;
229-
230227
/**
231228
* Creates a cookie, a small amount of information sent by a server to
232229
* a Web browser, saved by the browser, and later sent back to the server.
@@ -267,13 +264,13 @@ public interface Cookie {
267264
* separated by <code>&amp;</code>. Also, <code>k</code> and <code>v</code> are decoded using
268265
* {@link URLDecoder}.
269266
*/
270-
public static final Function<String, Map<String, String>> URL_DECODER = value -> {
267+
Function<String, Map<String, String>> URL_DECODER = value -> {
271268
if (value == null) {
272269
return Collections.emptyMap();
273270
}
274-
Function<String, String> decode = v -> Try
275-
.of(() -> URLDecoder.decode(v, StandardCharsets.UTF_8.name()))
276-
.get();
271+
Throwing.Function<String, String> decode = v -> URLDecoder
272+
.decode(v, StandardCharsets.UTF_8.name());
273+
277274
return Splitter.on('&')
278275
.trimResults()
279276
.omitEmptyStrings()
@@ -283,21 +280,22 @@ public interface Cookie {
283280
Iterator<String> it = Splitter.on('=').trimResults().omitEmptyStrings()
284281
.split(v)
285282
.iterator();
286-
Tuple2<String, String> t2 = Tuple
287-
.of(decode.apply(it.next()), it.hasNext() ? decode.apply(it.next()) : null);
288-
return t2;
283+
return new String[]{
284+
decode.apply(it.next()),
285+
it.hasNext() ? decode.apply(it.next()) : null
286+
};
289287
})
290-
.filter(it -> Objects.nonNull(it._2))
291-
.collect(Collectors.toMap(it -> it._1, it -> it._2));
288+
.filter(it -> Objects.nonNull(it[1]))
289+
.collect(Collectors.toMap(it -> it[0], it -> it[1]));
292290
};
293291

294292
/**
295293
* Encode a hash into cookie value, like: <code>k1=v1&amp;...&amp;kn=vn</code>. Also,
296294
* <code>key</code> and <code>value</code> are encoded using {@link URLEncoder}.
297295
*/
298-
public static final Function<Map<String, String>, String> URL_ENCODER = value -> {
299-
Function<String, String> encode = v -> Try
300-
.of(() -> URLEncoder.encode(v, StandardCharsets.UTF_8.name())).get();
296+
Function<Map<String, String>, String> URL_ENCODER = value -> {
297+
Throwing.Function<String, String> encode = v -> URLEncoder
298+
.encode(v, StandardCharsets.UTF_8.name());
301299
return value.entrySet().stream()
302300
.map(e -> new StringBuilder()
303301
.append(encode.apply(e.getKey()))

jooby/src/main/java/org/jooby/Env.java

Lines changed: 18 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,13 @@
203203
*/
204204
package org.jooby;
205205

206+
import com.google.common.base.Splitter;
207+
import com.google.common.collect.ImmutableList;
208+
import com.google.inject.Key;
209+
import com.google.inject.name.Names;
210+
import com.typesafe.config.Config;
206211
import static java.util.Objects.requireNonNull;
212+
import org.jooby.funzy.Throwing;
207213

208214
import java.util.Arrays;
209215
import java.util.Collections;
@@ -218,19 +224,8 @@
218224
import java.util.function.BinaryOperator;
219225
import java.util.function.Consumer;
220226
import java.util.function.Function;
221-
import java.util.function.Predicate;
222227
import java.util.function.Supplier;
223228

224-
import com.google.common.base.Splitter;
225-
import com.google.common.collect.ImmutableList;
226-
import com.google.inject.Key;
227-
import com.google.inject.name.Names;
228-
import com.typesafe.config.Config;
229-
230-
import javaslang.API;
231-
import javaslang.control.Option;
232-
import javaslang.control.Try.CheckedConsumer;
233-
234229
/**
235230
* Allows to optimize, customize or apply defaults values for application services.
236231
*
@@ -520,11 +515,11 @@ default Env build(final Config config) {
520515
String name = config.hasPath("application.env") ? config.getString("application.env") : "dev";
521516
return new Env() {
522517

523-
private ImmutableList.Builder<CheckedConsumer<Registry>> start = ImmutableList.builder();
518+
private ImmutableList.Builder<Throwing.Consumer<Registry>> start = ImmutableList.builder();
524519

525-
private ImmutableList.Builder<CheckedConsumer<Registry>> started = ImmutableList.builder();
520+
private ImmutableList.Builder<Throwing.Consumer<Registry>> started = ImmutableList.builder();
526521

527-
private ImmutableList.Builder<CheckedConsumer<Registry>> shutdown = ImmutableList.builder();
522+
private ImmutableList.Builder<Throwing.Consumer<Registry>> shutdown = ImmutableList.builder();
528523

529524
private Map<String, Function<String, String>> xss = new HashMap<>();
530525

@@ -564,35 +559,35 @@ public String toString() {
564559
}
565560

566561
@Override
567-
public List<CheckedConsumer<Registry>> stopTasks() {
562+
public List<Throwing.Consumer<Registry>> stopTasks() {
568563
return shutdown.build();
569564
}
570565

571566
@Override
572-
public Env onStop(final CheckedConsumer<Registry> task) {
567+
public Env onStop(final Throwing.Consumer<Registry> task) {
573568
this.shutdown.add(task);
574569
return this;
575570
}
576571

577572
@Override
578-
public Env onStart(final CheckedConsumer<Registry> task) {
573+
public Env onStart(final Throwing.Consumer<Registry> task) {
579574
this.start.add(task);
580575
return this;
581576
}
582577

583578
@Override
584-
public LifeCycle onStarted(final CheckedConsumer<Registry> task) {
579+
public LifeCycle onStarted(final Throwing.Consumer<Registry> task) {
585580
this.started.add(task);
586581
return this;
587582
}
588583

589584
@Override
590-
public List<CheckedConsumer<Registry>> startTasks() {
585+
public List<Throwing.Consumer<Registry>> startTasks() {
591586
return this.start.build();
592587
}
593588

594589
@Override
595-
public List<CheckedConsumer<Registry>> startedTasks() {
590+
public List<Throwing.Consumer<Registry>> startedTasks() {
596591
return this.started.build();
597592
}
598593

@@ -679,80 +674,6 @@ default <T> Optional<T> ifMode(final String name, final Supplier<T> fn) {
679674
return Optional.empty();
680675
}
681676

682-
/**
683-
* Produces a {@link API.Match} of the current {@link Env}.
684-
*
685-
* <pre>
686-
* String accessKey = env.match()
687-
* .when("dev", () {@literal ->} "1234")
688-
* .when("stage", () {@literal ->} "4321")
689-
* .when("prod", () {@literal ->} "abc")
690-
* .get();
691-
* </pre>
692-
*
693-
* @return A new matcher.
694-
*/
695-
default API.Match<String> match() {
696-
return API.Match(name());
697-
}
698-
699-
/**
700-
* Produces a {@link API.Match} of the current {@link Env}.
701-
*
702-
* <pre>
703-
* String accessKey = env.when("dev", () {@literal ->} "1234")
704-
* .when("stage", () {@literal ->} "4321")
705-
* .when("prod", () {@literal ->} "abc")
706-
* .get();
707-
* </pre>
708-
*
709-
* @param name A name to test for.
710-
* @param fn A callback function.
711-
* @param <T> A resulting type.
712-
* @return A new matcher.
713-
*/
714-
default <T> Option<T> when(final String name, final Supplier<T> fn) {
715-
return match().option(API.Case(API.$(name), fn));
716-
}
717-
718-
/**
719-
* Produces a {@link API.Match} of the current {@link Env}.
720-
*
721-
* <pre>
722-
* String accessKey = env.when("dev", "1234")
723-
* .when("stage", "4321")
724-
* .when("prod", "abc")
725-
* .get();
726-
* </pre>
727-
*
728-
* @param name A name to test for.
729-
* @param result A constant value to return.
730-
* @param <T> A resulting type.
731-
* @return A new matcher.
732-
*/
733-
default <T> Option<T> when(final String name, final T result) {
734-
return match().option(API.Case(API.$(name), result));
735-
}
736-
737-
/**
738-
* Produces a {@link API.Match} of the current {@link Env}.
739-
*
740-
* <pre>
741-
* String accessKey = env.when("dev", () {@literal ->} "1234")
742-
* .when("stage", () {@literal ->} "4321")
743-
* .when("prod", () {@literal ->} "abc")
744-
* .get();
745-
* </pre>
746-
*
747-
* @param predicate A predicate to use.
748-
* @param result A constant value to return.
749-
* @param <T> A resulting type.
750-
* @return A new matcher.
751-
*/
752-
default <T> Option<T> when(final Predicate<String> predicate, final T result) {
753-
return match().option(API.Case(predicate, result));
754-
}
755-
756677
/**
757678
* @return XSS escape functions.
758679
*/
@@ -786,16 +707,16 @@ default Function<String, String> xss(final String... xss) {
786707
/**
787708
* @return List of start tasks.
788709
*/
789-
List<CheckedConsumer<Registry>> startTasks();
710+
List<Throwing.Consumer<Registry>> startTasks();
790711

791712
/**
792713
* @return List of start tasks.
793714
*/
794-
List<CheckedConsumer<Registry>> startedTasks();
715+
List<Throwing.Consumer<Registry>> startedTasks();
795716

796717
/**
797718
* @return List of stop tasks.
798719
*/
799-
List<CheckedConsumer<Registry>> stopTasks();
720+
List<Throwing.Consumer<Registry>> stopTasks();
800721

801722
}

0 commit comments

Comments
 (0)