JType

Library to help creating type objects, by minimize boilerplate code, and helping with io.

License

License

GroupId

GroupId

se.eris
ArtifactId

ArtifactId

jtype
Last Version

Last Version

0.4.1
Release Date

Release Date

Type

Type

jar
Description

Description

JType
Library to help creating type objects, by minimize boilerplate code, and helping with io.
Project URL

Project URL

https://github.com/osundblad/java-type-util
Source Code Management

Source Code Management

https://github.com/osundblad/java-type-util

Download jtype

How to add to project

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

Dependencies

provided (1)

Group / Artifact Type Version
org.jetbrains : annotations jar 15.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

util

Table of Content

  • Usage
  • Wrappers
  • Simple
  • Complex
  • Limits
  • Other Stuff

Usage

Add the following Maven dependency

    <dependency>
        <groupId>se.eris</groupId>
        <artifactId>jtype</artifactId>
        <version>0.4.1</version>
    </dependency>

Simple Wrappers

The most simple usage is to just extend a Wrapper class. The wrapper classes implement the hashCode, equals, and toString methods.

public class Description extends StringWrapper {

    public Description(final String description) {
        super(description);
    }

}

Complex Wrappers

  • DyadWrapper
  • PairWrapper
  • OneOfWrapper
  • ...

Limits

To get some use out of the library you can combine it with a Limit. In this example the description String is limited to max 1000 characters.

public class Description extends StringWrapper {

    public static final int MAX_LENGTH = 1000;

    private static final LimitedString LIMITED_STRING = LimitedString.init()
            .length(MAX_LENGTH).build();

    public Description(final String description) {
        super(LIMITED_STRING.of(description));
    }

}

If no predefined limit matches your requirements you can create your own Limits easily:

Limit<Integer> evenLimit = (item) -> (((item % 2) == 0) ? Optional.empty() : Optional.of(ValidationError.of(item + " is odd")));
LimitedInteger even = LimitedInteger.init().limit(evenLimit).build();
int a = even.of(2);   // a = 2;
int b = even.of(17);  // throws ValidationException

Other Stuff

SOptional

A Serializable Optional until the JCP realizes the mistake and makes Optional serializable. It also takes some useful methods from the Guava Optional.

Versions

Version
0.4.1
0.4
0.3