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

Queryable Map

Accompanying blog post here


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
        .addIndex("name", User::getName)
        .addIndex("phone", User::getPhones)

// 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.