guava

What is the replacement for Sets.newConcurrentHashSet() ?

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...

A modern Java commons framework

Does anybody know of a good common frameworks for Java that has common but tedious utility methods that do things like... ObjectUtil.equalsOrBothNull(obj1,obj2) FormatUtil.formatName(String firstName String middleName, String lastName) AddressUtil.formatAddress(address) etc... It seems like I always end up re-implementing these so...

How to iterate through google collections' Multimap<?, Object> ?

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:...

caching and computing map

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 ...

Setting JAVA5_HOME environment variable on Mac OS 10.5.8?

How does one install set the JAVA5_HOME environment variable for Google Guava libraries on Mac OS 10.5.8? ...

Multimap with HashMultiset for values

Hi, I'm trying to have a (hash-based) Multimap with a (hash-based) Multiset of values for each key. See the example: Multimap<Object, Object> mmap = Multimaps.newMultimap( Maps.<Object, Collection<Object>>newHashMap(), new Supplier<Collection<Object>>() { public Collection<Object> get() { return HashMultiset.create(); ...

passing ImmutableSet in place of Set?

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...

BufferedIterator implementation

Does someone know of an open source BufferedIterator, where the next N elements are eagerly fetched on a background thread? Here is an implementation from a TechRepublic article, but I assume it has not been thoroughly tested. Iterators.buffer(Iterator toBuffer, int bufferSize) would be a nice addition to Guava, has that been considered...

Most of the Iterators and Iterables methods are LAZY! What does this mean.

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,...

How do I efficiently cache objects in Java using available RAM?

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...

Is there an easy way to turn Future<Future<T>> into Future<T>?

I've got some code that submits a request to another thread which may or may not submit that request to yet another thread. That yields a return type of Future<Future<T>>. Is there some non-heinous way to immediately turn this into Future<T> that waits on the completion of the entire future chain? I'm already using the Guava library t...

What is the difference between google's ImmutableList and Collections.unmodifiableList ()?

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 ...

Where's google-collection's LazyMap?

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? ...

Are there (good) tutorials and resources for guava-libraries (not the collection part)?

I still precise that this request doesn't concern the google-collections part of the library which has a lot of resources: I'm speaking essentially about the services and the concurrency part. I couldn't find tutorials regarding guava that aren't fully collections oriented. I know the collections are the most important part of the libra...

Potential use for SoftReference with value (equals) equality

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 ...

Why do ImmutableList.of() and friends prohibit null elements?

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...

filling a collection using an iterator

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? ...

is there java.concurrent.util (or equivalent) for WeakHashMap?

Can the following piece of code be rewritten w/o using Collections.synchronizedMap() yet maintaining correctness at concurrency? `Collections.synchronizedMap(new WeakHashMap<Class, Object>());` i.e. is there something from java.util.concurrent one can use instead? Note that merely replacing with new ConcurrentHashMap<Class, Object>...

Google Collections Suppliers and Find

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. ...

filter and sort list using google collections.

Suppose I have a list (or Set): List<String> testList = Lists.newArrayList("assocX","srcT","destA","srcX", "don't care Y", "garbage", "srcB"); I would like to get back an ImmutableList(Set) that sorts/groups terms in natural order where terms that begin with "src" are first, "assoc" second and "dest" last. If a term does not contain ...