Multiple indexes for a Java Collection - most basic solution?

后端 未结 14 1786
小鲜肉
小鲜肉 2020-11-29 22:08

I\'m looking for the most basic solution to create multiple indexes on a Java Collection.

Required functionality:

  • When a Value is removed, all index en
14条回答
  •  被撕碎了的回忆
    2020-11-29 22:41

    If you want multiple indexes on your data, you can create and maintain multiple hash maps or use a library like Data Store:

    https://github.com/jparams/data-store

    Example:

    Store store = new MemoryStore<>() ;
    store.add(new Person(1, "Ed", 3));
    store.add(new Person(2, "Fred", 7));
    store.add(new Person(3, "Freda", 5));
    store.index("name", Person::getName);
    Person person = store.getFirst("name", "Ed");
    

    With data store you can create case-insensitive indexes and all sorts of cool stuff. Worth checking out.

提交回复
热议问题