Search Results

Search found 44 results on 2 pages for 'guava'.

Page 1/2 | 1 2  | Next Page >

  • How have Guava unit tests been generated automatically?

    - by dzieciou
    Guava has unit test cases automatically generated: Guava has staggering numbers of unit tests: as of July 2012, the guava-tests package includes over 286,000 individual test cases. Most of these are automatically generated, not written by hand, but Guava's test coverage is extremely thorough, especially for com.google.common.collect. How they were generated? What techniques and technologies were used to design and generate them?

    Read the article

  • How do the versions of Guava work?

    - by Frór
    I would like to use Guava in a project, but my PM doesn't like the "r05" suffix, saying that it looks like it's not stable. In fact, the part I need is only the Google-Collections 1.0 which is now deprecated (my PM doesn't like that word either). So I don't really get the versioning of Guava/Google-Collections. I'm currently doing the development with GC1.0, but if possible I'll switch to a more recent and stable version.

    Read the article

  • Combine guava's ImmutableList and varargs

    - by Stas Kurilin
    I want create constructor that will take one or more integers and save it into field as ImmutableList. According to "The right way to use varargs to pass one or more arguments" by Bloch's Item 42 I create smt like class Foo{ private final ImmutableList<Integer> bar; public Foo(Integer first, Integer... other) { this.bar = ImmutableList.<Integer>builder() .add(first) .addAll(Arrays.asList(other)) .build(); } } Why builder doesn't get generic automatically? And, as it smells. How I can rewrite it?

    Read the article

  • Multimap Space Issue: Guava

    - by Arpssss
    In my Java code, I am using Guavas Multimap (com.google.common.collect.Multimap) by using this: Multimap< Integer, Integer Index = HashMultimap.create() Here, Multimap key is some portion of URL and value is another portion of URL (converted into integer). Now, I assign my JVM 2560 Mb (2.5 GB) heap space (by using Xmx and Xms). However, it can only store 9 millions of such (key,value) pairs of integers (approx 10 million). But, theoretically (according to memory occupied by int) it should store more. Can anybody help me, 1) Why is this happening (means Multimap is taking lots of space) ? I checked my code with out inserting pairs in Multimap, it takes only 1/2 MB space. 2) Is there any other way or home-baked solution to solve this space issue ? More clearly, how to solve this memory issue ? Thanks in advance and any idea is perfectly OK for me.

    Read the article

  • Using "Google Guava" in coding interviews

    - by kbgn27
    I attended a in-person interview recently and performed well. But surprisingly I got rejected. When I asked the HR for reason, he contacted the technical interviewer and told me that I was syntactically wrong while coding. I used Google Guava for coding. So my code looked like this: List<String> items = Lists.newArrayList() instead of List<String> items =new ArrayList<String>(); I know that the code will compile and work as expected.Is it ok to use third party libraries like Google Guava in interviews?

    Read the article

  • How do I prevent use of beta classes from google guava library?

    - by mjlee
    We have been using Google collections in the production for several months. We would like to start using guava for additional functions. However, I'm afraid to bring guava into our product stack b/c some developers may start to use 'beta' classes. We have various unit-tests in our code but at this point, I prefer not to include 'beta' class b/c it is subject to change in the future. Is there any easy way to do detect if the project includes any 'beta' guava classes?

    Read the article

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

    - by Fabian Steeg
    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 InputSupplier<InputStream>() { public InputStream getInput() throws IOException { return inputStream; } }; Background: I'd like to use InputStreams with e.g. Files.copy(...) or ByteStreams.equal(...).

    Read the article

  • Simplifier le code de vos beans Java à l'aide de Commons Lang, Guava et Lombok, par Thierry Leriche-Dessirier

    Bonjour à tous, Je vous propose un article intitulé "Simplifier le code de vos beans Java à l'aide de Commons Lang, Guava et Lombok". Synopsis : Un bean classique, représentant un chien par exemple, peut vite peser des centaines de lignes quand on l'équipe avec les méthodes classiques et indispensables (constructeurs, getters, setters, equals, hashCode, toString, compareTo), même s'il possède peu d'attributs. Dans cet article, nous verrons comment mettre un tel cabot au régime et lui faire une beauté à l'aide de Commons Lang, Guava et Lombok. Nous en profiterons pour comparer ces bibliothèques entre elles et avec le code Java habituel, sans oublier celui qu'Eclipse génère. L'article est disponible ici :

    Read the article

  • Guava 13.0 disponible, cette version du framework Java se concentre sur les Collections et les utilitaires (Base)

    Après seulement quelques mois depuis la release 12, l'équipe Guava nous propose la treizième version de son framework Java. Au programme de Guava 13.0, on note pas mal de travail autour des Collections et les utilitaires (Base), dont voici les ajouts principaux :FluentIterable.toSortedImmutableList et transformAndConcat ; ContiguousSet.create(Range, DiscreteDomain) ; Maps.synchronizedNavigableMap ; Sets.synchronizedNavigableSet ; Ordering.allEqual ; Funnels.asOutputStream, integerFunnel et longFunnel ; DoubleMath.fuzzyCompare et fuzzyEquals ; UnsignedBytes.parseUnsignedByte, toString et MAX_VALUE ; UnsignedInts.decode ; UnsignedLongs.decode ; CycleDetectingLockFactory ;

    Read the article

  • Google collections GWT jar

    - by Sudhir Jonathan
    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 :-/

    Read the article

  • How to check function parameters in Go

    - by deamon
    Guava Preconditions allows to check method parameters in Java easily. public void doUsefulThings(Something s, int x, int position) { checkNotNull(s); checkArgument(x >= 0, "Argument was %s but expected nonnegative", x); checkElementIndex(position, someList.size()); // ... } These check methods raise exceptions if the conditions are not met. Go has no exceptions but indicates errors with return values. So I wonder how an idiomatic Go version of the above code would look like.

    Read the article

  • One liner for getting a sublist from a Set

    - by yegor256
    Is there a one-liner (maybe from Guava or Apache Collections) that gets a sublist from a set. Internally it should do something like this: public <T> List<T> sublist(Set<T> set, int count) { Iterator<T> iterator = set.iterator(); List<T> sublist = new LinkedList<T>(); int pos = 0; while (iterator.hasNext() && pos++ < count) { sublist.add(iterator.next()); } return sublist; } Obviously, if there are not enough elements it has to return as many as possible.

    Read the article

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

    - by Dimitris Andreou
    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 will be enqueued in the intuitive (topological when there are no cycles) order in the ReferenceQueue? I.e. ref(A) before ref(B). I don't know - what if the GC marked a bunch of objects as unreachable, and then enqueued them in no particular order? I was reviewing Finalizer.java of guava, seeing this snippet: private void cleanUp(Reference<?> reference) throws ShutDown { ... if (reference == frqReference) { /* * The client no longer has a reference to the * FinalizableReferenceQueue. We can stop. */ throw new ShutDown(); } frqReference is a PhantomReference to the used ReferenceQueue, so if this is GC'ed, no Finalizable{Weak, Soft, Phantom}References can be alive, since they reference the queue. So they have to be GC'ed before the queue itself can be GC'ed - but still, do we get the guarantee that these references will be enqueued to the ReferenceQueue at the order they get "garbage collected" (as if they get GC'ed one by one)? The code implies that there is some kind of guarantee, otherwise unprocessed references could theoretically remain in the queue. Thanks

    Read the article

  • Capturing Set Behavior with Mutating Elements

    - by Carl
    Using the Guava library, I have the following situation: SetMultimap<ImmutableFoo, Set<Foo>> setMM = HashMultimap.create(); Set<Foo> mask = Sets.newHashSet(); // ... some iteration construct { setMM.put(ImmutableFoo1, Sets.difference(SomeSetFoo1,mask)); setMM.put(ImmutableFoo1, Sets.difference(SomeSetFoo2,mask)); mask.add(someFoo); } that is, the same iteration to create the setMM is also used to create the mask - this can of course result in changes to hashCode()s and create duplicates within the SetMultimap backing. Ideally, I'd like the duplicates to drop without me having to make it happen, and avoid repeating the iteration to separately construct the multimap and mask. Any easy libraries/Set implementations to make that happen? Alternatively, can you identify a better way to drop the duplicates than: for (ImmutableFoo f : setMM.keySet()) setMM.putAll(f,setMM.removeAll(f)); revisiting the elements is probably not a performance problem, since I could combine a separate filter operation that needs to visit all the elements anyway.

    Read the article

  • Essence of BiMap in Google collections

    - by littleEinstein
    I am still quite puzzled at the BiMap in Google collections/Guava. It was claimed that The two bimaps are backed by the same data; any changes to one will appear in the other. I browsed through the source code, and I found the use of delegate in ForwardingMap. But in any actually subclass of StandardBiMap, I do see the data are put into both the forward and reverse map. So what is the essence, and why it claims to have saved space by keeping only one copy of the data? Is it just the actual objects are one set, but two distinct sets of references to these objects are still needed, one set maintained in forward map, and the other in reverse map? private V putInBothMaps(K key, V value, boolean force) { boolean containedKey = containsKey(key); if (containedKey && Objects.equal(value, get(key))) { return value; } if (force) { inverse().remove(value); } else if (containsValue(value)) { throw new IllegalArgumentException( "value already present: " + value); } V oldValue = super.put(key, value); updateInverseMap(key, containedKey, oldValue, value); return oldValue; }

    Read the article

  • Multiple (variant) arguments overloading in Java: What's the purpose?

    - by fortran
    Browsing google's guava collect library code, I've found the following: // Casting to any type is safe because the list will never hold any elements. @SuppressWarnings("unchecked") public static <E> ImmutableList<E> of() { return (ImmutableList<E>) EmptyImmutableList.INSTANCE; } public static <E> ImmutableList<E> of(E element) { return new SingletonImmutableList<E>(element); } public static <E> ImmutableList<E> of(E e1, E e2) { return new RegularImmutableList<E>( ImmutableList.<E>nullCheckedList(e1, e2)); } public static <E> ImmutableList<E> of(E e1, E e2, E e3) { return new RegularImmutableList<E>( ImmutableList.<E>nullCheckedList(e1, e2, e3)); } public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4) { return new RegularImmutableList<E>( ImmutableList.<E>nullCheckedList(e1, e2, e3, e4)); } public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5) { return new RegularImmutableList<E>( ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5)); } public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6) { return new RegularImmutableList<E>( ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5, e6)); } public static <E> ImmutableList<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E e7) { return new RegularImmutableList<E>( ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5, e6, e7)); } public static <E> ImmutableList<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) { return new RegularImmutableList<E>( ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5, e6, e7, e8)); } public static <E> ImmutableList<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) { return new RegularImmutableList<E>( ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5, e6, e7, e8, e9)); } public static <E> ImmutableList<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) { return new RegularImmutableList<E>(ImmutableList.<E>nullCheckedList( e1, e2, e3, e4, e5, e6, e7, e8, e9, e10)); } public static <E> ImmutableList<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11) { return new RegularImmutableList<E>(ImmutableList.<E>nullCheckedList( e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11)); } public static <E> ImmutableList<E> of( E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11, E e12, E... others) { final int paramCount = 12; Object[] array = new Object[paramCount + others.length]; arrayCopy(array, 0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12); arrayCopy(array, paramCount, others); return new RegularImmutableList<E>(ImmutableList.<E>nullCheckedList(array)); } And although it seems reasonable to have overloads for empty and single arguments (as they are going to use special instances), I cannot see the reason behind having all the others, when just the last one (with two fixed arguments plus the variable argument instead the dozen) seems to be enough. As I'm writing, one explanation that pops into my head is that the API pre-dates Java 1.5; and although the signatures would be source-level compatible, the binary interface would differ. Isn't it?

    Read the article

  • multiple keys and values with google-collections

    - by flash3000
    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 integer are the two different values. I have already prepare a code which spilt the lines in chunks. import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class HashMapKey { public static void main(String[] args) throws FileNotFoundException, IOException { String inputFile = "inputData.txt"; BufferedReader br = new BufferedReader(new FileReader(inputFile)); String strLine; while ((strLine = br.readLine()) != null) { String[] line = strLine.replaceAll(" ", "").trim().split(","); for (int i = 0; i < line.length; i++) { System.out.print("[" + line[i] + "]"); } System.out.println(); } } } Unfortunately, I do not know how to save these information in google-collection? Thank you in advance. Best regards,

    Read the article

  • To instantiate BiMap Of google-collections in Java

    - by Masi
    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, Integer>.

    Read the article

  • Google Collections sources don't compile

    - by Carl Rosenberger
    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 AbstractMultimap + 11 similar ones Name clash: The method forcePut(K, V) of type AbstractBiMap has the same erasure as forcePut(Object, Object) of type BiMap but does not override it + 2 similar ones What am I missing? I also wonder if unit tests for these collections are available to the public.

    Read the article

  • Compile Error Using MutableClassToInstanceMap with Generics

    - by user298251
    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<Number> identifiers = MutableClassToInstanceMap.create(); public static void main(String[] args) { ArrayList<Number> numbers = new ArrayList<Number>(); numbers.add(new Integer(5)); TestMutableClassToInstanceMap test = new TestMutableClassToInstanceMap(numbers); } public TestMutableClassToInstanceMap(Collection<Number> numbers){ for (Number number : numbers) { this.identifiers.putInstance(number.getClass(), number); //error here } this.identifiers.putInstance(Double.class, 5.0); // This works } }

    Read the article

  • Find top N elements in a Multiset from Google Collections?

    - by dfrankow
    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 values from the histogram Examples: top 10 URLs, top 10 tags, ... What is the canonical way to do #2 given a Multiset? Here is a blog post about it, but that code is not quite what I want. First, it returns everything, not just top N. Second, it copies (is it possible to avoid a copy?). Third, I usually want a deterministic sort, i.e. tiebreak if counts are equal.

    Read the article

1 2  | Next Page >