com.codepoetics:radioactive

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

GroupId

GroupId

com.codepoetics
ArtifactId

ArtifactId

radioactive
Last Version

Last Version

0.7
Release Date

Release Date

Type

Type

jar
Description

Description

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Source Code Management

Source Code Management

http://github.com/poetix/radioactive

Download radioactive

How to add to project

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

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
com.google.guava : guava jar 18.0

Project Modules

There are no modules declared in this project.

radioactive

A Java 8 library for building, validating, mutating and mapping beans.

Build Status

In Maven:

<dependency>
    <groupId>com.codepoetics</groupId>
    <artifactId>radioactive</artifactId>
    <version>0.7</version>
</dependency>

An Accessor is a Getter paired with a Setter, like so:

public static final Accessor<Person, String> NAME = Accessor.of(Person::getName, Person::setName);
public static final Accessor<Person, Address> ADDRESS = Accessor.of(Person::getAddress, Person::setAddress);

You can use them to build new objects:

Person person = Person.BUILDER.with(
    Person.NAME.of("Arthur Putey"),
    Person.ADDRESS.of(Address.BUILDER.with(
        Address.FIRST_LINE.of("22 Acacia Avenue"),
        Address.SECOND_LINE.of("Sunderland"),
        Address.POSTCODE.of("VB6 5UX"))))
    .get();

to query and modify existing objects:

assertThat(Person.NAME.get(person), equalTo("Arthur Putey"));

assertThat(Person.ADDRESS.join(Address.SECOND_LINE).get(person),
           equalTo("Sunderland"));
           
Person.NAME.set(person, "Angus Yentob");

assertThat(person.getName(), equalTo("Angus Yentob"));

Person.ADDRESS.join(Address.POSTCODE).set(person, "RA8 81T");

assertThat(person.getAddress().getPostCode(), equalTo("RA8 81T"));

to validate objects:

Validator<Person> validator = Validator
        .validating("name", Person.NAME, equalTo("Agnes Phobos"))
        .and("age", Person.AGE, greaterThanOrEqualTo(0));

Valid<Person> validPerson = Valid.validate(new Person("Angus Eros", -2), validator);

assertFalse(validPerson.isValid());
assertFalse(validPerson.get().isPresent());
assertThat(validPerson.validationErrors(), hasItems("name: Angus Eros != Agnes Phobos", "age: -2 < 0"));

and to map from type to type:

Person person1 = new Person();
person1.setName("Antigone");
person1.setAge(30);

Knight bean2 = Mapper.from(Person::getAge).to(Knight::setAge)
        .andFrom(Person::getName).via(String::toUpperCase).to(Knight::setName)
        .andFrom("I seek the grail").to(Knight::setQuest)
        .creatingWith(Knight::new)
        .apply(person1);

assertThat(bean2.getName(), equalTo("ANTIGONE"));
assertThat(bean2.getAge(), equalTo(30));
assertThat(bean2.getQuest(), equalTo("I seek the grail"));

If you've seen any of my other libraries for doing similar things, notably Karg and Octarine, you'll have seen most of this before. Radioactive is a variant specifically for working with old-style "bean" objects with getters and setters, because sometimes you have to and why make it more painful than it needs to be?

Versions

Version
0.7
0.1