🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more
Socket
Book a DemoInstallSign in
Socket

pl.tlinkowski.unij:pl.tlinkowski.unij.service.misc.jdk11

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pl.tlinkowski.unij:pl.tlinkowski.unij.service.misc.jdk11

Universal facade of JDK 9+ API, focused on Collection factory methods

Source
mavenMaven
Version
0.1.3
Version published
Maintainers
1
Source

UniJ: Universal JDK 9+ API Facade

Build (Linux) Build (Windows) Code coverage Codacy grade

Maven Central Javadocs Semantic Versioning Automated Release Notes by gren

Introduction

UniJ targets JDK 8 and is a facade of:

UniJ provides a facade of above-mentioned methods in a similar way that SLF4J (Simple Logging Facade for Java) provides a facade of logging. In both cases, there is an API that can be implemented in many different ways and then be injected at runtime as a Java service.

UniJ consists of three key parts described further on: its API, its bindings, and its bundles.

Note: if you look for a specific UniJ project, consult UniJ project layout.

Analogy

UniJ is to new parts of JDK 9+ API what SLF4J is to logging API — a facade.

Quick Example

JDK 9+
Set<Integer> set = Set.of(1, 2);
List<Integer> list = List.of(1, 2, 1);
Map<Integer, String> map = Map.of(1, "a", 2, "b");

Set.copyOf(list); // ⇒ [1, 2]
Set.of(1, 2, 1); // throws "duplicate element" exception
Set.of(1, 2, null); // throws null-pointer exception
UniJ (JDK 8+)
Set<Integer> set = UniSets.of(1, 2);
List<Integer> list = UniLists.of(1, 2, 1);
Map<Integer, String> map = UniMaps.of(1, "a", 2, "b");

UniSets.copyOf(list); // ⇒ [1, 2]
UniSets.of(1, 2, 1); // throws "duplicate element" exception
UniSets.of(1, 2, null); // throws null-pointer exception

Notes

Method Summary

JDK 9+UniJ (JDK 8+)
typestatic method nametype
List
Set
of, copyOf UniLists
UniSets
Map of, copyOf,
entry, ofEntries
UniMaps
Collectors toUnmodifiableList
toUnmodifiableSet
toUnmodifiableMap
filtering
flatMapping
UniCollectors

Motivation

This library has been designed primarily for:

End Users Stuck on JDK 8

If you're stuck on JDK 8, you can't use JDK 9+'s new methods like List.of, etc.

However, by adding a dependency on a UniJ bundle of your choosing (plus some optional extra dependencies), you can enjoy a JDK 11-like API on JDK 8!

See:

Libraries Targeting JDK 8

If you maintain a library targeting JDK 8, you can't use JDK 9+'s new methods like List.of, etc.

However, by adding a dependency on UniJ User API, you can program to JDK 11-like API!

Note: your users will have to provide implementations of the above-mentioned API (as per Usage for End Users).

See:

API

UniJ has two kind of APIs:

  • User API: utility classes (this is what the user interacts with)
  • Service API: interfaces (this is what the service provider implements)

The call chain looks as follows:

end user ⟷ User API ⟷ Service API ⟷ service provider

In other words, the end user isn't aware of the Service API, and the service provider isn't aware of the User API.

User API

The User API is defined in pl.tlinkowski.unij.api and consists of the following utility classes: UniLists, UniSets, UniMaps and UniCollectors (see Method Summary for details).

This API has strict equivalence to the corresponding JDK API (see API Specification for details).

Service API

Disclaimer: As an end user, you don't need to be concerned with this API.

UniJ Service API is defined in pl.tlinkowski.unij.service.api and consists of the following interfaces:

A module providing implementations of one or more of these interfaces constitutes a binding.

API Specification

UniJ APIs come with a detailed specification for the Service API interfaces. The specification is based on the contract of the original JDK API (expressed mostly in JavaDoc), and tries to follow it as close as possible.

The focal points of the specification are:

  • null treatment (no nulls allowed)
  • duplicate handling (e.g. no duplicates allowed in of methods of UniSets and UniMaps)
  • consistency (e.g. only one empty collection instance)

The specification is fully expressed as the following Spock test classes defined pl.tlinkowski.unij.test:

Read the source of the Spock tests linked above to see what every UniJ binding guarantees.

Bindings

A binding is simply a library with implementation(s) of the Service API.

Note that UniJ supports multiple bindings of the same type at runtime.

Predefined Bindings

UniJ comes with a number of predefined bindings, which can all be found under subprojects/bindings.

Collection Factory API Bindings

UniJ currently provides four types of Collection factory API bindings:

Miscellaneous API Bindings

UniJ currently provides two types of miscellaneous API bindings:

Custom Bindings

Instead of any of the predefined bindings mentioned above, you can create and depend on a custom binding.

See:

Bundles

A UniJ bundle is a module having no source (save for its module-info.java) and depending on the following three modules:

  • pl.tlinkowski.unij.api module (transitive dependency)
  • Collection factory API binding (= one of pl.tlinkowski.unij.service.collect.___ modules)
  • miscellaneous API binding (= one of pl.tlinkowski.unij.service.misc.___ modules)

Predefined Bundles

Currently, UniJ provides the following four bundles:

Usage

See Usage document.

Extra Information

See Extra Information document.

Questions & Answers

See Q&A document.

Changelog

See Changelog document.

Requirements

Usage: JDK 8+.

Building: Gradle 5+, JDK 11+.

About the Author

See my webpage (tlinkowski.pl) or find me on Twitter (@t_linkowski).

FAQs

Package last updated on 28 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts