Hi,
I am upgrading from Google Collections 0.9 to 1.0. It seems Sets.newConcurrentHashSet() is no longer available. I was using it in the following construct:
public static <K, V> Multimap<K, V> newConcurrentMultimap()
{
return Multimaps.newMultimap( new ConcurrentHashMap<K, Collection<V>>(), new Supplier>()
{
@Overrid...
Before using google collections I had something similar to next code:
private Set<A> aSet = ...;
private Set<B> bSet = ...;
public Foo getFoo (Map<?, List<Bar>> bars, Set<?> set) {
for (Object item : set) {
for (Bar bar : bars.get (item)) {
//build foo;
}
}
...
}
and I was able to make calls like these:...
correlation use case:
read input
if (correlation-id is already generated for this input)
{
lookup the correlation-id from the cache;
return correlation-id;
}
else
{
generate the correlation-id;
cache it;
return correlation-id;
}
Constraints:
- The number of input records can go till 500K so doesn't want ...
I've been reading that ComputingMap only supports identity equality and not the equals(). Can someone clarify why?
...
I have a method that expects a Set parameter. I want to pass in an empty set, and I don't want any side effects on the Set.
I can do this with collections by passing in:
Collections.unmodifiableSet(Sets.newHashSet())
But I want to pass in:
ImmutableSet.of()
If I do the former a Set<Object> is created and I get "method not appli...
1 of the presentation says "These methods are LAZY!"
Iterable transform(Iterable, Function)*
Iterable filter(Iterable, Predicate)*
T find(Iterable<T>, Predicate)
Iterable concat(Iterable<Iterable>)
Iterable cycle(Iterable)
T getOnlyElement(Iterable<T>)
Iterable<T> reverse(List<T>)
Can someone help me understand what they mean by this,...
I need to cache objects in Java using a proportion of whatever RAM is available. I'm aware that others have asked this question, but none of the responses meet my requirements.
My requirements are:
Simple and lightweight
Not dramatically slower than a plain HashMap
Use LRU, or some deletion policy that approximates LRU
I tried Link...
From ImmutableList javadocs:
Unlike
Collections.unmodifiableList(java.util.List),
which is a view of a separate
collection that can still change, an
instance of ImmutableList contains its
own private data and will never
change. ImmutableList is convenient
for public static final lists
("constant lists") and also lets ...
One of my favourites from apache commons-collections was the LazyMap which would use a Transformer to instantiate values on the fly when doing map.get(newKey); // Will not return null!.
Why doesn't google collections have the same?
...
I previously come to the conclusion that if you need a SoftReference with value (equals) based equality then one had a bad design, excepting an interner from this. This is following Google Collections and Guava not including such a class. But I've come across an issue that I think could use such an object.
We have an asset management ...
Summary pretty much says it all. Here's the relevant snippet of code in ImmutableList.createFromIterable():
if (element == null) {
throw new NullPointerException("at index " + index);
}
I've run into this several times and can't see why a general-purpose library function should impose this limitation.
Edit 1: by "general-pur...
Google Collections has an Iterables utility class for taking in a collection and iterable and putting all the elements from iterable into the collection, called addAll. Is there something similar when all you have is an iterator?
...
I'm looking for a Google Collections method that returns the first result of a sequence of Suppliers that doesn't return null.
I was looking at using Iterables.find() but in my Predicate I would have to call my supplier to compare the result against null, and then have to call it again once the find method returned the supplier.
...
Hi,
I'm looking for a implementation of java.util.Queue or something in the Google collection who behave like a Queue, but also ensure that each element of the queue is unique. (all further insertion will have no effect)
It's that possible, or will I have to do it by hand?
For now I'm using a Queue, with a LinkedList implementation, a...
Highly repetitive code is generally a bad thing, and there are design patterns that can help minimize this. However, sometimes it's simply inevitable due to the constraints of the language itself. Take the following example from java.util.Arrays:
/**
* Assigns the specified long value to each element of the specified
* range of the sp...
Is google collections Joiner thread safe?
...
This is a simple problem, but I'm having problems with it...
I'm trying to use Google common collection's Objects.equal() method in a GWT client code, but I'm keep getting the error
"20:12:10.001 [ERROR] [gwt_regex] Line 39: No source code is available for type com.google.common.base.Objects; did you forget to inherit a required module...
It seems like there should be a removalAllOccuring(Collection) (or similiar) method in Multiset. A sort of analog to remove(Object,int) and removeAll(Collection). Short of that method, what is the best way to accomplish its intent. I wrote a small JUnit driver to demonstrate:
/**
* @see http://google-collections.googlecode.com/svn/t...
How can you instantiate a Bimap of Google-collections?
I know the thread.
A sample of my code
import com.google.common.collect.BiMap;
public class UserSettings {
private Map<String, Integer> wordToWordID;
UserSettings() {
this.wordToWordID = new BiMap<String. Integer>();
I get cannot instantiate the type BiMap<String, Intege...
I'm working on a java project that will allows users to parse multiple files with potentially thousands of lines. The information parsed will be stored in different objects, which then will be added to a collection.
Since the GUI won't require to load ALL these objects at once and keep them in memory, I'm looking for an efficient way t...