guava

Is there a concise way to create an InputSupplier for an InputStream in Google Guava?

There are a few factory methods in Google Guava to create InputSuppliers, e.g. from a byte[]: ByteStreams.newInputStreamSupplier(bytes); Or from a File: Files.newInputStreamSupplier(file); Is there a similar way to to create an InputSupplier for a given InputStream? That is, a way that's more concise than an anonymous class: new...

Is Joiner thread safe?

Is google collections Joiner thread safe? ...

Using Google Common Collection in GWT

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

removing a collection's occurrences from a Multiset

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

To instantiate BiMap Of google-collections in Java

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

Compile Error Using MutableClassToInstanceMap with Generics

I am getting the following compile error "The method putInstance(Class, T) in the type MutableClassToInstanceMap is not applicable for the arguments (Class, Number)" on the putInstance method call. Does anyone know what I am doing wrong?? Thanks! public class TestMutableClassToInstanceMap { public final MutableClassToInstanceMap<Nu...

Does GC guarantee that cleared References are enqueued to ReferenceQueue in topological order?

Say there are two objects, A and B, and there is a pointer A.x --> B, and we create, say, WeakReferences to both A and B, with an associated ReferenceQueue. Assume that both A and B become unreachable. Intuitively B cannot be considered unreachable before A is. In such a case, do we somehow get a guarantee that the respective references...

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

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

multiple keys and values with google-collections

Hello, I would like use google-collection in order to save the following file in a Hash with multiple keys and values Key1_1, Key2_1, Key3_1, data1_1, 0, 0 Key1_2, Key2_2, Key3_2, data1_2, 0, 0 Key1_3, Key2_3, Key3_3, data1_3, 0, 0 Key1_4, Key2_4, Key3_4, data1_4, 0, 0 The first three columns are the different keys and the last two in...

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

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

Java: how to use Google's HashBiMap?

Keys are a file and a word. The file gives all words inside the file. The word gives all files having the word. I am unsure of the domain and co-domain parts. I want K to be of the type <String> and V to be of type <HashSet<FileObject>>. public HashBiMap<K<String>,V<HashSet<FileObject>>> wordToFiles = new HashBiMap<K<St...

Java: how to use 3rd-party library?

The code shows compilation with the -cp trigger but not running. Apparently, it cannot find the HashMultimap. Classpath problem? $ javac -cp google-collect-1.0.jar MultiThing.java $ java -cp google-collect-1.0.jar MultiThing Exception in thread "main" java.lang.NoClassDefFoundError: MultiThing Caused by: java.lang.ClassNotFoundExcept...

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

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

Where do I get the google artifact from?

Hi, So I'm trying to build guava from source with maven2 but it seems to need the 'google' artifact as parent. Where is the upstream website of this artifact? (yes, I need the source, not just the artifact). Thanks, red ...

Google Collections sources don't compile

I just downloaded the Google Collections sources and imported them into a new Eclipse project with JDK 1.6. They don't compile for a couple of reasons: javax.annotation.Nullable can not be found javax.annotation.ParametersAreNonnullByDefault can not be found Cannot reduce the visibility of the inherited method #createCollection() from A...