google-collections

java.lang.ClassNotFoundException using google commons

I have two classes inside a package. Both call a method from another class, one works perfectly fine and the other gives the error java.lang.ClassNotFoundException and the error java.lang.NoClassDefFoundError: com/google/common/base/Predicate The class path should be the same for both as they are in he same package so I can't figure o...

Is there a fast concat method for linked list in Java?

How can I concat two linked lists in O(1) with Java via jdk1.6, google or apache commons collection or whatever? E.g. in the jdk there is only the addAll method which is O(n). Another feature I miss is to concat two lists where each of them could be in inverse order. To illustrate this assume two lists a->b->c and e->f->g could merged ...

Does Google Collections API have an equivalent of the Ruby Enumerable#inject method?

I read through the javadoc and couldn't find anything that resembles it. ...

How to multithread collection iteration operating on a predicate?

For sake of abstraction, let's assume that I have a Map<Double, Collection<Employee>> where key is salary threshold. Or for people familiar with Google collections it would be as Multimap I want to do a database lookup for each Employee's salary and if it's less than the salary threshold remove the employee it from the collection. ...

Give me a practical use-case of Multi-set

I would like to know a few practical use-cases (if they are not related/tied to any programming language it will be better).I can associate Sets, Lists and Maps to practical use cases. For example if you wanted a glossary of a book where terms that you want are listed alphabetically and a location/page number is the value, you would us...

Iterables.find and Iterators.find - instead of throwing exception, get null

I'm using google-collections and trying to find the first element that satisfies Predicate if not, return me 'null'. Unfortunately, Iterables.find and Iterators.find throws NoSuchElementException when no element is found. Now, I am forced to do Object found = null; if ( Iterators.any( newIterator(...) , my_predicate ) { found = It...

Compiling Java code in terminal having a Jar in CLASSPATH

How can you compile the code using javac in a terminal by using google-collections in CLASSPATH? Example of code trying to compile using javac in a terminal (works in Eclipse) import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; public class Locate { ... BiMap<MyFile, Integer> rankingToResult = Hash...

is guava-libraries available in maven repo?

I am looking to find guava-libraries in maven repository. It looks like guava is adding more features to google-collections library. ...

Google collections GWT jar

Has anyone had any luck rolling a custom GWT jar for Google Collections / Guava? I've tried uncommenting the relevant ant tasks and running them, but I just get empty folders in the JAR. Can't seem to get the include rules right :-/ ...

Lazy non-modifiable list in Google Collections

I was looking for a decent implementation of a generic lazy non-modifiable list implementation to wrap my search result entries. The unmodifiable part of the task is easy as it can be achieved by Collections.unmodifiableList() so I only need to sort out the the lazy part. Surprisingly, google-collections doesn't have anything to offer; ...

Get minvalue of a Map(Key,Double)

Hi all, is there a method (maybe with Google Collections) to obtain the min value of a Map(Key, Double) In traditional way, I would have to sort the map according to the values, and take the first/last one. thanks ...

Proper usage of Java Weak Reference in case of nested collections

I need to define a weak reference Map, whose value is a Set. I use Google collections' MapMaker, like this: Map<Class<? extends Object>, Set<Foo>> map = new MapMaker().weakKeys().weakValues().makeMap(); So, for Set<Foo>, can I use a normal HashSet? Or, do I have to create a weak HashSet, like this: Collections.newSetFromMap(new WeakH...

Can you use "parenthesis" on Predicate operations

I can't see any way to build a Predicate that uses parenthesis to control logical order. Is there one? Say I want to do something like Predicate <= mumble and (foo or baz) A simple Predicates.and or a Predicates.or has no equivalent that says "foo or baz" and with mumble. Is this possible? ...

Soft/Weak key MapMAker with equals for key

Dear all, I need a Concurrent Hash Map with Weak or Soft keys were the equality is equals and not ==. For this kind of keys, google collection chooses == by default. Is there a way to override this choice? How should I proceed? Best regards, Nicolas. ...

How to sort a Map<Key, Value> on the values in Java with google collections ordering function

How to sort a map(?,B) on the values in Java with google collections ordering function, if B is a class, which has a field of type double, which should be used for ordering. ...

java.lang.ClassNotFoundException

Hey everyone, I have a java project that I'm working on which was working until a few days ago. I'm not sure what I did to my Eclipse set-up to hose it but now I'm getting a java.lang.ClassNotFoundException when I try to run some code that accesses the google finance api. I've built a small test application that uses the google finance ...

Find top N elements in a Multiset from Google Collections?

A Google Collections Multiset is a set of elements each of which has a count (i.e. may be present multiple times). I can't tell you how many times I want to do the following Make a histogram (exactly Multiset) Get the top N elements by count from the histogram Examples: top 10 URLs (by # times mentioned), top 10 tags (by # times app...

Why doesn't Google's Multimap's entries() method return Key/Collection pairs?

I would like to be able to retrieve from my com.google.collections.Multimap<A, B> a Collection<Entry<A, Collection<B>>> which I expected from the entries() method, but in fact it returns a Collection<Entry<A, B>>. Is there a method which does what I want? Currently I'm iterating like this: for (A key: mmap.keySet()) { Collection<B...

How to create a Multimap<K,V> from a Map<K, Collection<V>> ?

I didn't find such a multimap construction... When i want to do this, I iterate over the map, and populate the multimap. Is there an other way ?? final Map<String, Collection<String>> map = ImmutableMap.<String, Collection<String>>of( "1", Arrays.asList("a", "b", "c", "c")); System.out.println(Multimaps.forMap(map)); final ...

Why does Iterables.find() in Guava throw NoSuchElementException, instead of returning null?

I love Google Guava and use it a lot, but there is one method I always find me writing.. public static <T> T tryFind(Iterable<T> iterable, Predicate<T> predicate){ for(T t : iterable){ if(predicate.apply(t)){ return t; } } return null; } To me this seems to be a very useful addition to...