Use cqengine for collection retrieval.

  java

Background

If there is a need to search and match in memory, cqengine can be used to efficiently search java collections.

maven

        <dependency>
            <groupId>com.googlecode.cqengine</groupId>
            <artifactId>cqengine</artifactId>
            <version>2.9.2</version>
        </dependency>

Declaration and initialization

IndexedCollection<Demo> demos = new ConcurrentIndexedCollection<Demo>();
demos.addAll(.....);

Set index type

import static com.googlecode.cqengine.query.QueryFactory.attribute;
final Attribute<Demo, String> NAME = attribute("name", Demo::getName);
reportItems.addIndex(SuffixTreeIndex.onAttribute(NAME));

Search

import static com.googlecode.cqengine.query.QueryFactory.contains;
Query<Demo> query = contains(NAME,key);
ResultSet<Demo> resultSet = demos.retrieve(query);

doc