Skip to content

Utils

Overview

General-purpose utilities used across mango4j modules.

Architecture

  • Conformance and mutation: ObjectMutator, Conformer, @Reduce, @Tolerate, @Text.
  • Masking: Masker implementations, MaskerFactory, MaskingUtils.
  • Date/time: DateUtils, CalendarUtils, Proximity, MovingClock.
  • Mapping: MappingUtils for object-to-map/JSON conversion.
  • URLs and formatting: URLGenerator, QueryParam, MapFormat.
  • Threading and entities: NamedScheduledExecutorBuilder, EntityToStringBuilder.

How to use

Gradle

implementation("ie.bitstep.mango:mango4j-utils:1.0.0")

Maven

1
2
3
4
5
<dependency>
    <groupId>ie.bitstep.mango</groupId>
    <artifactId>mango4j-utils</artifactId>
    <version>1.0.0</version>
</dependency>

Examples

Conformance with @Tolerate and @Reduce

class Category {
    @Tolerate(min = 3, max = 3)
    private String code;

    @Reduce(max = 5)
    private String label;
}

Category category = new Category();
category.setCode("SQL Database");
category.setLabel("Payments Platform");

Conformer.conform(category);

ObjectMutator with HTML escaping

1
2
3
4
5
6
7
8
9
class Message {
    @Text
    private String body;
}

ObjectMutator mutator = new ObjectMutator()
    .on(Text.class, new HtmlEscapeMutator());

mutator.mutate(message);

Masking utilities

String maskedPan = MaskerFactory.getMasker(PanMasker.class).mask("5105105105105100");
String maskedId = new IdMasker("Y").mask("01234567890ABCDEF");

URLGenerator

1
2
3
4
5
String url = URLGenerator.ofURL("http://api.stage.bitstep.ie//mdes/")
    .path("consumer")
    .path("allocate")
    .param("limit", "100")
    .toString();

MappingUtils

Map<String, Object> payload = MappingUtils.fromObjectToMap(somePojo);
String json = MappingUtils.fromObjectToJson(somePojo);

UUIDv7

UUID id = new UUIDv7().generate();

NamedScheduledExecutorBuilder

1
2
3
4
5
ScheduledExecutorService executor = NamedScheduledExecutorBuilder.builder()
    .poolSize(4)
    .threadNamePrefix("crypto-retry")
    .daemon(true)
    .build();