Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mrtimeey/object-finder

Library for finding objects in complex data structures
https://github.com/mrtimeey/object-finder

Last synced: 11 days ago
JSON representation

Library for finding objects in complex data structures

Awesome Lists containing this project

README

        

# object-finder [![CI](https://github.com/MrTimeey/object-finder/actions/workflows/mvn-build.yml/badge.svg?branch=main)](https://github.com/MrTimeey/object-finder/actions/workflows/mvn-build.yml?query=branch%3Amain) [![Maven Central](https://img.shields.io/maven-central/v/io.github.mrtimeey/object-finder.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.github.mrtimeey%22%20AND%20a:%22object-finder%22) [![Javadocs](http://www.javadoc.io/badge/io.github.mrtimeey/object-finder.svg)](http://www.javadoc.io/doc/io.github.mrtimeey/object-finder)
The object-finder provides utility functions to identify specific objects in complex data structures.
* [Object-Finder's goals](#goals)
* [TL;DR](#tldr)
* [Longer example](./exampleUseCase.md)
* [Quickstart](#quickstart)

## Object-Finder's goal

Object-Finder's ambition is to provide simple utility methods to find specific objects in complex data structures.
The idea is that you don't want to navigate through the object over and over again.
Finding various objects in a complex object often leads to multiple same looking methods and duplicated code.

The Object-Finder wants to simply your code.

## TL;DR

*Important:*

The returned object is a new instance and no reference from provided root object.
Changing the returned object will not affect the base object.
There will be an additional API-endpoint soon.

### Get object by field
```java
Pair location = Pair.of("id", "02f26e1b-e548-440d-8bfc-559d7c9fb1bd");
Optional result = FindObjectUtils.find(baseObject, location, CalculationPart.class);
assertThat(result).isPresent();
```

### Get object by nested object value
```java
Pair location = Pair.of("information/key", "SPECIAL_DISCOUNT");
Optional result = FindObjectUtils.find(baseObject, location, CalculationPart.class);
assertThat(result).isPresent();
```

### Get object by string in list
```java
Pair location = Pair.of("names[]", "specialDiscount");
Optional result = FindObjectUtils.find(baseObject, location, CalculationPart.class);
assertThat(result).isPresent();
```

### Get object by nested object value in list
```java
Pair location = Pair.of("properties[id]", "d9c40d29-e828-4c15-9519-29891496ec8e");
Optional result = FindObjectUtils.find(baseObject, location, CalculationPart.class);
assertThat(result).isPresent();
```

### Get all objects by nested object value

```java
Pair location = Pair.of("information/key", "SPECIAL_DISCOUNT");
List result = FindObjectUtils.findAll(baseObject, location, CalculationPart.class);
assertThat(result).hasSize(2);
```

## Quickstart

Add Maven Dependency:
```xml

io.github.mrtimeey
object-finder
1.0.1

```