I have the following code:
private SetMultimap<String, Dynamic> dynamicFields = TreeMultimap.create(Ordering.natural(), new Comparator<Dynamic>() {
@Override
public int compare(Dynamic o1, Dynamic o2) {
return o1.getTitle().compareTo(o2.getTitle());
}
});
which gives me the following exception.
IllegalAnnotationsException S...
Hi,
I am looking for sample code which explains Guava ForwardingList class. Basically I am implementing a custom ArrayList class which will be used to solve this requirement mentioned in my earlier SO question. I never used Google collection before. But by just looking at the JavaDoc of ForwardingList, I think I can implement my custom ...
Here is some code I've been twiddling with to try and lazily fill in fields in object, mostly for object factories in JUnit but it could be quite a useful method to have.
private void lazyObjectFill(Object profil) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
final Method[] list = profil.ge...
The guava-libraries have a class Ordering. I'm wondering if it's thread safe.
For example, can it be used as a static variable?
public static Ordering<String> BY_LENGTH_ORDERING = new Ordering<String>() {
public int compare(String left, String right) {
return Ints.compare(left.length(), right.length());
}
};
...
I am looking for a function that will partition a list into fixed size sublists, exactly what Lists.partition from Google Collections library does.
I couldn't find such method in the Scala Collections API. Am I missing something?
...
Hi.
I have read many people really like the MapMaker of Google Guava (Collections), however I cannot see any good uses of it.
I have read the javadoc, and it says that it behaves like ConcurrentHashMap. It also says new MapMaker().weakKeys().makeMap() can almost always be used as a drop-in replacement for WeakHashMap.
However, reading...
Hello everybody.
Like the title says, i would like to get a thread-safe HashSet using Guava Collections.
Can you help me?
Thanks!
...
Which is the best way you think to use Guava? Since, in the web site, the guys say that the interfaces are subject to change till they release 1.0. Taking this into account, the code you write shouldn't depend directly on those interfaces, so, are you wrapping all the Guava code you call into some kind of layer or facade in our project...
How can we do that with Guava? Notice the presence of List<K> in the return type since many keys can map to the same value in any normal map.
public static <K, V> Map<V, List<K>> inverse(Map<K, V> map){
Map<V, List<K>> result = new LinkedHashMap<V, List<K>>();
for (Map.Entry<K, V> entry : map.entrySet()) {
if(!result.con...
Are the slides of the presentation linked from the Google collections page available somewhere as pdf or so on the web ? I.e. I'm looking for the slides of the overview video as it is easier to search e.g. a pdf than a video...
I know that Google collections is now part of Guava Libraries but the 'PDF Slides of a recent presentation' ar...
I just came across this answer in SO where it is mentioned that the Google-collections MapMaker is awesome.I went through the documentation but couldn't really figure out where i can use it.Can any one point out some scenario's where it would be appropriate to use a MapMaker.
...
I was just looking at Guava's ImmutableList and I noticed that the of() method was overloaded 12 times.
It looks to me that all they needed was:
static <E> ImmutableList<E> of();
static <E> ImmutableList<E> of(E element); // not even necessary
static <E> ImmutableList<E> of(E... elements);
What's the reason for having so many similar...
I'd like to know what is there a better way to find the first value greater than an inputted value in a large SortedMap instead of looping through all values in my example below. Or if SortedMap is a the best structure to use for this.
Could this be achieved using google-collections?
Thanks in advance
public class mapTest {
public sta...
I have had a quick scan of the guava api and the new collection types it provides(multimap and bimap for example appear useful) and I am thinking of including the library in the project(s) I work on. However, I also have a reticence to include libraries willy-nilly if they are of no great benefit and learning the features wastes valuab...
I'm trying to use Guava in a GWT project without success (a HashMultimap, to be precise). I get a never-ending list of stacktraces for classes:
com.google.common.collect.ComparisonChain
com.google.common.collect.ForwardingSortedSetMultimap
com.google.common.collect.Ordering
...
Each stack trace is along the lines of:
line xx: the ...
Do any of you know of a Java Map or similar standard data store that automatically purges entries after a given timeout? Preferably in an open source library that is accessible via maven?
I know of ways to implement the functionality myself and have done it several times in the past, so I'm not asking for advice in that respect, but for...
Is there a way of achieving the below using Guava?
//anything better than using Files.append() in a loop?
org.apache.commons.io.FileUtils.writeLines(File file, Collection lines, String lineEnding);
//gives a byte[] that is fed to Files.write(byte[] from, File to)
org.apache.commons.lang.SerializationUtils.serialize(Serializable obj)
...
I need combination of Google Collection ImmutableMap and LinkedHashMap immutable map with defined iteration order. It seems that ImmutableMap itself actually has defined iteration order, at least its documentation says:
An immutable, hash-based Map with reliable user-specified iteration order.
However there are no more details. Q...
I've been looking at the problem of writing a concurrent Multimap, and I have an implementation backed by the Google Guava AbstractSetMultimap and a MapMaker computing map that creates on demand the values-collections as a set view over a ConcurrentHashMap. With some care over the view collections and various wrappers, I think this gets ...
I was impressed by google's MapMaker design.I would like to know what is the name of the pattern that is used here ?
( What i think is it's somewhat like decorator pattern but in which we don't have to wrap the object in other object to extend the functionality,but I can't figure out exactly what sort of pattern it is. )
MapMaker Objec...