GithubHelp home page GithubHelp logo

domain-primitives-api's Introduction

Domain Primitives API

Name Sate
CircleCI CircleCI
SonarQube Quality Bugs Code Smells

This project provides a set of base classes that can be used when building domain primitives. The base classes come into three flavours:

  1. lang
  2. optional
  3. mandatory

The lang set of base classes represents domain primitives that are based on the Java primitives, such as int and long. The optional and mandatory set of base classes represents options such as Integer or String, where the optional version allows nulls while the mandatory peer does not allow nulls.

For example, say we have a class that has two fields, title and name. The title field is optional while the name field is mandatory,

public class Person {
  private final PersonTitle title;
  private final PersonName name;

}

The Person uses two domain primitive classes, the PersonTitle and the PersonName. The PersonTitle should accept nulls and thus it is optional.

import java.util.Optional;
import com.google.common.base.Preconditions;

import com.javacreed.api.domain.primitives.optional.StringBasedDomainPrimitive;

public class PersonTitle extends StringBasedDomainPrimitive {

    private static final PersonTitle EMPTY = new PersonTitle(Optional.empty());

    public static PersonTitle empty() {
        return EMPTY;
    }

    public static PersonTitle ofNullable(String value) {
        if(value == null){
            return empty();
        }

        return of(value);
    }

    public static PersonTitle of(String value) throws NullPointerException {
        Preconditions.checkNotNull(value);
        return new PersonTitle(Optional.of(value));
    }

    private PersonTitle(Optional<String> value) {
        super(value);
    }
}

The PersonName class, on the other hand, is mandatory.

import com.google.common.base.Preconditions;

import com.javacreed.api.domain.primitives.mandatory.StringBasedDomainPrimitive;

public class PersonName extends StringBasedDomainPrimitive {

    public static PersonName of(String value) throws NullPointerException {
        Preconditions.checkNotNull(value);
        return new PersonName(value);
    }

    private PersonName(String value) {
        super(value);
    }
}

Will add more to this page later on.

domain-primitives-api's People

Contributors

albertattard avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.