Parameter Validation Utils

Validating input parameters of methods and constructors is a recurring and stupid task, especially when you are writing public APIs. This module tries to ease your life a bit by providing a static validateThat() method, allowing you to throw IllegalArgumentExceptions using hamcrest matchers.

Лицензия

Лицензия

Группа

Группа

info.gehrels
Идентификатор

Идентификатор

parameter-validation
Последняя версия

Последняя версия

1.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

Parameter Validation Utils
Validating input parameters of methods and constructors is a recurring and stupid task, especially when you are writing public APIs. This module tries to ease your life a bit by providing a static validateThat() method, allowing you to throw IllegalArgumentExceptions using hamcrest matchers.
Ссылка на сайт

Ссылка на сайт

https://github.com/BGehrels/parameter-validation
Система контроля версий

Система контроля версий

https://github.com/BGehrels/parameter-validation

Скачать parameter-validation

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/info.gehrels/parameter-validation/ -->
<dependency>
    <groupId>info.gehrels</groupId>
    <artifactId>parameter-validation</artifactId>
    <version>1.1</version>
</dependency>
// https://jarcasting.com/artifacts/info.gehrels/parameter-validation/
implementation 'info.gehrels:parameter-validation:1.1'
// https://jarcasting.com/artifacts/info.gehrels/parameter-validation/
implementation ("info.gehrels:parameter-validation:1.1")
'info.gehrels:parameter-validation:jar:1.1'
<dependency org="info.gehrels" name="parameter-validation" rev="1.1">
  <artifact name="parameter-validation" type="jar" />
</dependency>
@Grapes(
@Grab(group='info.gehrels', module='parameter-validation', version='1.1')
)
libraryDependencies += "info.gehrels" % "parameter-validation" % "1.1"
[info.gehrels/parameter-validation "1.1"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.hamcrest : hamcrest-core jar [1.2,1.3)

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.11

Модули Проекта

Данный проект не имеет модулей.

Parameter validation using Hamcrest matchers

Validating input parameters of methods and constructors is a recurring and stupid task, especially when you are writing public APIs. This module tries to ease your life a bit by providing a static validateThat() method, allowing you to throw IllegalArgumentExceptions using hamcrest matchers.

Using the matchers is as easy as

import static info.gehrels.parameterValidation.MatcherValidation.validateThat;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.isEmptyOrNullString;

...

public MyConstructor(String name) {
	this.name = validateThat(name, not(isEmptyOrNullString()));
}

or

validateThat("parameter 'name has an invalid value", name, not(isEmptyOrNullString()));

If it fails to validate the parameter, an Exception is thrown:

Exception in thread "main" java.lang.IllegalArgumentException: parameter 'name has an invalid value
Expected: not (null or an empty string)
     but: was null
	at info.gehrels.parameterValidation.MatcherValidation.validateThat(MatcherValidation.java:40)
	...

How to get this?

You will find the lib at Maven Central. Just add the following lines to your pom.xml:

<dependency>
	<groupId>info.gehrels</groupId>
    <artifactId>parameter-validation</artifactId>
	<version>1.1</version>
</dependency>

How is it licensed?

Since the code ist mostly copied from the original Hamcrest sources, i do not claim copyright myself. The code therefore falls under Hamcrests BSD 3-Clause License. It may be found at https://raw.github.com/hamcrest/JavaHamcrest/master/LICENSE.txt

Версии библиотеки

Версия
1.1
1.0