GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - j-util/optional-map: Optional-based read access for Java Map. A small utility built for fun.

BranchesTags
Open more actions menu

Latest commit

 

History

12 Commits
12 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.mvn/wrapper
.mvn/wrapper
 
 
src
src
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
mvnw
mvnw
 
 
mvnw.cmd
mvnw.cmd
 
 
pom.xml
pom.xml
 
 

Repository files navigation

optional-map

Maven Central Javadoc Build

Small Java 8+ utility for null-safe Optional access to Map values. Built for fun.

Replace:

Optional<String> name = Optional.ofNullable(map.get("user-1"));

with:

Optional<String> name = OptionalMaps.getOptional(map, "user-1");

Installation

Maven:

<dependency>
  <groupId>io.github.j-util</groupId>
  <artifactId>optional-map</artifactId>
  <version>1.0.0</version>
</dependency>

Maven Central

Usage

Use OptionalMaps.getOptional(map, key) when you only need one lookup:

Map<String, String> names = new HashMap<String, String>();
names.put("user-1", "Ada");

Optional<String> name = OptionalMaps.getOptional(names, "user-1");

Use OptionalMaps.wrap(map) when you want a Map view with an extra getOptional method:

Map<String, String> names = new HashMap<String, String>();
OptionalMap<String, String> optionalNames = OptionalMaps.wrap(names);

optionalNames.put("user-1", "Ada");
Optional<String> name = optionalNames.getOptional("user-1");

Null Values

getOptional returns Optional.empty() both when the key is absent and when the key is present with a null value. You still need to use containsKey to distinguish those cases.

Build

./mvnw test

About

Optional-based read access for Java Map. A small utility built for fun.

central.sonatype.com/artifact/io.github.j-util/optional-map

Topics

javajava-librarymaven-central

Resources

Readme
Apache-2.0 license

Security policy

Security policy
Activity
Custom properties

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.