FBT Core Java

Foundational Java Library

License

License

Categories

Categories

Java Languages
GroupId

GroupId

com.funbasetools
ArtifactId

ArtifactId

fbt-core-java
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

FBT Core Java
Foundational Java Library
Project URL

Project URL

https://github.com/funbasetools/fbt-core-java
Source Code Management

Source Code Management

https://github.com/funbasetools/fbt-core-java

Download fbt-core-java

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
org.apache.commons : commons-lang3 jar 3.9
commons-io : commons-io jar 1.3.2

test (2)

Group / Artifact Type Version
junit : junit jar 4.13
org.mockito : mockito-core jar 3.1.0

Project Modules

There are no modules declared in this project.

FunBaseTools core library for Java

Release Build

FunBaseTools Core Lib provides a functional and multipurpose library for Java developers.

How to install it

  • Using maven:
<dependency>
    <groupId>com.funbasetools</groupId>
    <artifactId>fbt-core-java</artifactId>
    <version>latest</version>
</dependency>
  • You also can download the latest sources from the release badge above.

Features

The library has a set of useful features to apply functional programming to Java projects. Below you can see some utilities:

Lazy Evaluation

import com.funbasetools.Lazy;

class MyClass {

    // This field value will be computed only when used the first time
    private final Lazy<String> lazyField = Lazy.of(() -> {

        // Perform a very complicated and big computation
        return "This result will be computed only the first time";
    });

    public String getResult() {
        return lazyField.get();
    }
}

Streams

import com.funbasetools.collections.Stream;
import com.funbasetools.collections.Streams;

class MyClass {

    // natural numbers stream
    private final Stream<Integer> naturals = Streams.from(1);

    // factorial stream
    private final Stream<Integer> factorial = getFactorial();

    // fibonacci stream
    private final Stream<Integer> fibonacci = getFibonacci();
    
    public void testNaturals() {
        final Stream<Integer> evens = naturals.filter(i -> i % 2 == 0);
        final Stream<Integer> odds = naturals.filter(i -> i % 2 != 0);

        assert evens.corresponds(Streams.of(2, 4, 6, 8, 10, 12, 14, 16, 18, 20));
        assert odds.corresponds(Streams.of(1, 3, 5, 7, 9, 11, 13, 15, 17, 19));
    }
    
    public void testFactorial() {
        assert factorial
                .corresponds(Streams.of(1, 2, 6, 24, 120, 720, 5040, 40320, 362880));
    }
    
    public void testFibonacci() {
        assert factorialStream
                .corresponds(Streams.of(1, 1, 2, 3, 5, 8, 13, 21, 34));
    }

    // private methods    

    /**
    /* Creates a stream of pairs with the current fibonacci value and the next natural number, 
    /* after multiplying the pair, the result is the next factorial value.
    /* Awesome!!!
    */
    private Stream<Integer> getFactorial() {
        return Streams
                .ofNullable(1, () -> factorialStream
                    .zip(naturalStream.getTail())
                    .map(pair -> pair.getRight() * pair.getLeft())
                );
    }

    /**
    /* Creates a stream of pairs with the current and next fibonacci values and then adds the pair values.
    /* The result is the next fibonacci number.
    /* Wonderful right?
    */
    private Stream<Integer> getFibonacci() {
        return Streams
                .ofNullable(1, 1)
                .append(() -> fibonacci
                    .zip(fibonacci.getTail())
                    .map(pair -> pair.getLeft() + pair.getRight())
                );
    }
}

And more...

Also, you can find:

  • Try, Success and Failures monads
  • Function, Supply and Consumer extended types and their throwing exception similar
  • Codecs
  • Basic security API

Take a look to the unit tests of the library for more use cases and examples.


Donate

com.funbasetools

FunBaseTools

Versions

Version
0.1.1