Skip to content
No description, website, or topics provided.
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
README.md
pom.xml

README.md

Queryable Map

Accompanying blog post here

Description

This is a basic implementation of a Java Collection that allows for efficient retrieval of data by multiple attributes present in the data. Example: take the following User entity Class

public class User {
        private String id;
        private String name;
        private List<String> phones;
        private String country;
    
    // getters
}

Here is how to store a collection of Users and then be able to fetch them efficiently either by id, name or by one of their phone numbers:

QueryableMap.Builder<String, User> builder = QueryableMap.newBuilder();
QueryableMap<String, User> map = builder
        .keyFunction(User::getId)
        .addIndex("name", User::getName)
        .addIndex("phone", User::getPhones)
        .build();

// insert users
map.put(new User(...));
map.put(new User(...));
map.put(new User(...));

// fetch user by id
User user1 = map.get("1");

// fetch users by name
Collection<User> usersCalledJohn = map.query("name", "John");

// fetch users by name
Collection<User> usersWithPhone1234 = map.query("phone", "1234");
You can’t perform that action at this time.