项目作者: io7m

项目描述 :
Typed property handling
高级语言: Java
项目地址: git://github.com/io7m/jproperties.git
创建时间: 2015-08-09T16:33:14Z
项目社区:https://github.com/io7m/jproperties

开源协议:ISC License

下载


jproperties

Maven Central
Maven Central (snapshot)
Codecov
Java Version

com.io7m.jproperties

JVM Platform Status
OpenJDK (Temurin) Current Linux Build (OpenJDK (Temurin) Current, Linux)
OpenJDK (Temurin) LTS Linux Build (OpenJDK (Temurin) LTS, Linux)
OpenJDK (Temurin) Current Windows Build (OpenJDK (Temurin) Current, Windows)
OpenJDK (Temurin) LTS Windows Build (OpenJDK (Temurin) LTS, Windows)

jproperties

Java functions to access values from java.util.Properties collections in
a typed manner.

Features

  • Functions to access java.util.Properties values as typed values.
  • High coverage test suite.
  • OSGi-ready
  • JPMS-ready
  • ISC license.

Usage

The JProperties class contains numerous functions to extract typed values
from a Properties collection:

  1. final var p = new Properties();
  2. p.setProperty("int0", "23");
  3. p.setProperty("b0", "true");
  4. JProperties.getBoolean(p, "b0"); // ⇒ true
  5. JProperties.getBigInteger(p, "int0"); // ⇒ new BigInteger(23)

If a property is not present, or has a value that cannot be parsed as a value
of the requested type, a JPropertyException is raised.

  1. JProperties.getBigInteger(p, "nonexistent") // ⇒ JPropertyNonexistent
  2. JProperties.getBigInteger(p, "b0"); // ⇒ JPropertyIncorrectType

Functions typically have an optional variant that returns an Optional.empty()
value on missing keys (but an exception will still be raised on type errors).

  1. JProperties.getStringOptional(p, "nonexistent") // ⇒ Optional.empty()
  2. JProperties.getStringOptional(p, "b0"); // ⇒ "true"

Functions typically also have a default variant that can return a given
default value if a property is not present (but an exception will still be
raised on type errors).

  1. JProperties.getStringWithDefault(p, "nonexistent", "z") // ⇒ "z"
  2. JProperties.getStringWithDefault(p, "b0", "z"); // ⇒ "true"