Skip to content

About

black.TypedString: a marker for a type that holds and validates one shaped string. No dependencies, Java 17+.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

TypedString

JitPack

black.TypedString: a marker interface for a type that exists to hold and validate one shaped string, such as a SKU, a MAC address or a host name. It declares nothing; "find implementations" on it is the catalogue of every shaped value in a codebase. One interface, no dependencies, Java 17+.

record Sku(String value) implements TypedString {
	private static final Pattern SHAPE = Pattern.compile("[A-Z]{3}-\\d{6}");

	public Sku {
		if (!SHAPE.matcher(value).matches()) {
			throw new IllegalArgumentException("not a SKU: " + value);
		}
	}

	@Override
	public String toString() {
		return value;
	}
}

See Typed strings: wrap them.

Install

Via JitPack. Use api rather than implementation in a library whose public types implement it.

repositories { maven("https://jitpack.io") }
dependencies { implementation("com.github.Brendan-Black:TypedString:1.0.0") }

black-java's lib carries it too, as a dependency.

Build

./gradlew check checks formatting, compiles with every warning as an error, runs the tests (test/, a plain main(): the interface stays empty, and the example above works as written), and checks the jar holds only TypedString and lists no dependencies.

License

MIT

About

black.TypedString: a marker for a type that holds and validates one shaped string. No dependencies, Java 17+.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages