Questions tagged [apache-commons-collection]

Commons-Collections builds upon the Java collection classes by providing new interfaces, implementations and utilities.

Features listed from home page

  • Bag interface for collections that have a number of copies of each object
  • Buffer interface for collections that have a well defined removal order, like FIFOs
  • BidiMap interface for maps that can be looked up from value to key as well and key to value
  • MapIterator interface to provide simple and quick iteration over maps
  • Type checking decorators to ensure that only instances of a certain type can be added
  • Transforming decorators that alter each object as it is added to the collection
  • Composite collections that make multiple collections look like one
  • Ordered maps and sets that retain the order elements are added in, including an LRU based map
  • Identity map that compares objects based on their identity (==) instead of the equals method
  • Reference map that allows keys and/or values to be garbage collected under close control
  • Many comparator implementations
  • Many iterator implementations
  • Adapter classes from array and enumerations to collections
  • Utilities to test or create typical set-theory properties of collections such as union, intersection, and closure
74 questions
5
votes
7 answers

One liner for getting a sublist from a Set

Is there a one-liner (maybe from Guava or Apache Collections) that gets a sublist from a set. Internally it should do something like this: public List sublist(Set set, int count) { Iterator iterator = set.iterator(); List sublist…
yegor256
  • 102,010
  • 123
  • 446
  • 597
4
votes
1 answer

Apache Commons MultiMap is deprecated, what should I use now?

Apache Commons' MultiMap interface with its MultiValueMap implementation is deprecated since version 4.1. And MultiHashMap seems to go entirely... What should I use as an alternative?
WhiteWalker
  • 365
  • 2
  • 5
  • 14
4
votes
1 answer

Java 8 Stream filter with comparator

I want to filter list of MyObject based on values field. In this case: if any value on MyObject::getValues is less than given value, than the predicate is false. I haven't found the way to do it with Stream API, so I tried ComparatorPredicate by…
4
votes
5 answers

Java Composite List

I'm looking for a opensource library that has an implementation of a composite list. I need a list that reads its values from some other lists and can be constructed something like this:List list1 = new ArrayList(); list1.add("0"); List list2 = new…
AmanicA
  • 4,659
  • 1
  • 34
  • 49
4
votes
3 answers

Using a MultiValueMap from Apache Commons Collections

Given below an example of org.apache.commons.collections.map.MultiValueMap (from commons-collections-3.2.1) Map multiValueMap = MultiValueMap.decorate(new HashMap()); multiValueMap.put("orderId",…
Tiny
  • 27,221
  • 105
  • 339
  • 599
4
votes
2 answers

Java Collection for special scrolling, circular queue

I'm looking for something similar to ConcurrentLinkedQueue, but with the following behaviors: When I peek()/poll() the queue, it retrieves the HEAD, does not remove it, and then subsequently advances the HEAD one node towards the TAIL When the HEAD…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
3
votes
2 answers

Java: Commons-Collections generics: How to get custom transformer to work

Hi i am using commons collections generics 4.01. I have a dto object. Class PricingDto { private Double tax; private Double price; private Double tip; // getters and setters } i have a list of List pricingDtos =…
Chun ping Wang
  • 3,879
  • 12
  • 42
  • 53
3
votes
1 answer

Getting all objects with same key from a MultiValueMap

I have a MultiValueMap from which I am trying to get [print for the purpose of this question] out all the paths which were put in the map using the same key. This is my current solution: MultiValueMap duplicates =…
Pétur Ingi Egilsson
  • 4,368
  • 5
  • 44
  • 72
3
votes
2 answers

A Map> implementation, exposing a view Map of "last values"

I'm looking at various google-collections (or also Apache commons collections) classes, and I'd fancy some help in finding the most appropriate Map implementation for my use case. I'm not interested in home-grown maps. Here are some requirements: I…
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
3
votes
1 answer

Comparator/Comparable/ComparatorChain questions

I'm working on implementing a hierarchy which deals with Comparator and the Comparable interface. Couple of things that are unclear to me: If I'm adding comparators to a comparator chain, what exactly does this piece of code…
Mike
  • 825
  • 3
  • 12
  • 30
2
votes
1 answer

FifoBuffer - apache common collections 4 replacements

I want to upgrade to apache.commons.collections4, but some classes as CircularFifoBuffer and UnboundedFifoBuffer are dropped import org.apache.commons.collections.buffer.CircularFifoBuffer; What are the right replacements for such classes? Found…
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
2
votes
2 answers

Sort Apache Commons MultiValuedMap by Key

I would like to know how to sort Apache Commons MultiValuedMap by Key. The below is the key class used. public class VssKey implements Comparable { private String funCode; private String varntCode; private String itemNb; …
Sudarsan A
  • 55
  • 1
  • 5
2
votes
3 answers

How can I remove the old vulnerable Apache commons collection version dependency from my project's maven dependency tree?

My Java app project is being managed by Maven. My project has a few library dependencies depending again on Apache commons collection 3.2.1 which is vulnerable - e.g. Apache commons configuration, velocity, etc. (I can see it is being used by…
hotohoto
  • 490
  • 8
  • 20
2
votes
2 answers

BeanToPropertyValueTransformer and commons-collections4

In commons-collections 3.2.1 the following one-liner worked nicely to retrieve the myProperty values of the objects inside myCollection: Collection myTypes = (Collection) CollectionUtils.collect(myCollection, new…
2
votes
1 answer

ClassNotFoundException on TomEE 1.6.0.2 for org.apache.commons.collections4 classes

When trying to use classes of the org.apache.commons.collections4 jar in my web application deployed on TomEE 1.6.0.2 (Tomcat 7.0.53) I get a ClassNotFoundException. I stripped down the web application to just one simple HttpServlet doing nothing…