Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [guava]

The Guava project is a set of Java core libraries. They include collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O etc.

0
votes
1answer
44 views

Collect all items containing a word to a Multimap

I have a simple class like class Item { Set<String> wordSet() {...} } So each item has a set of words and I need ...
2
votes
2answers
129 views

“Compress” the entry set of Integers in a Map<String, Integer> to values incrementing by 1

What I'm trying to achieve is the following: Given a Map, where the values may contain duplicates, I want to change the values so that they are incrementing by 1, starting from 1. Example: ...
3
votes
2answers
191 views

Generating a string in a particular format by reading data from a map

I have a processToTaskIdHolder Map which contains processId as the key and taskId as the ...
1
vote
0answers
73 views

Sorted set a Queue

I needed a data structure offering both poll returning the smallest element and fast contains. A ...
2
votes
1answer
162 views

Send records and retry them if acknowledgement is not received

I am using below class to send data to our messaging queue by using socket either in a synchronous way or asynchronous way as ...
0
votes
1answer
1k views

Comparing unordered list in java

I want to compare two unordered list and currently I am doing it in the following way. Is there a better way to do this as I am repeating my code twice (for null check & then converting to a Set). ...
5
votes
1answer
577 views

Strongly connected component finding based on the guava graph library with Kosaraju

I have been writing a small compiler generator for which I need to solve the strongly connected component problem. As the Guava library contains, to my knowledge, no implementation for that problem, I ...
1
vote
1answer
331 views

Implementing feature hashing using guava

I am trying to implement feature hashing in Java. For this I am trying to use Hashing functions from guava. This is how I am doing it now: ...
2
votes
1answer
57 views

Parse the response from http call and populate multiple maps

I have to parse a response after making HTTP call on the server. If the response is not successful then try another server otherwise parse the successful response and populate two ...
5
votes
2answers
508 views

Send records and retry them if acknowledgement is not received

I am working on a project where I need to consume lot of records and then I am sending these records to some other system which uses zeromq. Here is the flow: Store all the incoming records in a CHM ...
4
votes
1answer
114 views

Validate the inputs and perform actions accordingly

I have a consumer which is listening to Kafka and from which I am getting avro GenericRecord. Now basis on GenericRecord ...
4
votes
1answer
107 views

Using two maps and making a new map by applying all the transformations

I have two JSON and each JSON I am loading in a Map. First JSON { "abc": "2", "plmtq": "hello+world", "lndp": "def+ooo", "yyt": "opi" } I am ...
3
votes
2answers
544 views

Caching all the prepared statements in thread safe way

I have a below Singleton class where in my getStatement method, I populate a CHM by doing if check. ...
1
vote
0answers
69 views

Storing large maps in memory

Context of the problem: I have a very large graph that cost about 4GB to store. About 3M nodes and 34M edges. My program takes this large graph and recursively builds smaller graphs from it. At each ...
1
vote
1answer
3k views

Validate a string for positive number and normal string

I have a method in which I am accepting a String clientid and that has below requirements: clientid can be a positive number ...
1
vote
0answers
533 views

Purging elements from the map if it reaches a memory size limit

I have implemented a LRU cache using ConcurrentLinkedHashMap. In the same map, I am purging events if my map reaches a particular limit as shown below. I have a ...
0
votes
2answers
92 views

Combining several collections into one

Is there a way to rewrite this code to make it more laconic? I'm using Java 6. ...
4
votes
1answer
2k views

Validating a string for a positive number, null/empty string

I have a method in which I am accepting a String clientId and that has below requirements: clientId can be a positive number ...
22
votes
3answers
8k views

Synchronous / asynchronous REST client

I have working code with original design, and now I had a slight design change so trying to code review that as well. I already had code review on my original design here. Original Design: I am ...
6
votes
3answers
3k views

Text file manipulation with Java 8 and Guava

I am trying to do some translation of text files. I have a translation .csv file and a file I need to translate (tab delimited). The translation is creating a file with an extra column of the ...
5
votes
1answer
319 views

Multi-threaded bitcoin vanity address generator written in Java

The application leverages the bitcoinj library to generate a vanity bitcoin address. A vanity address is simply a bitcoin address that contains a personalized string. I would like some critical ...
6
votes
1answer
1k views

Efficient top k words using MultiMap (Google Guava ext lib JAR)

Basic algorithm: Open document/huge text file Use Map and List to separate the words. \$O(K)\$ time complexity (TC) considering ...
7
votes
1answer
736 views

Designing yet another coffee machine, Lombok style

After reading Designing a coffee machine, I decided to implement the same problem as an exercise to get to know Guava and Lombok. I used the problem statement from the given question: Design ...
5
votes
2answers
134 views

BitSet wrapper to act as a sieve abstraction

This is a BitSet wrapper class to act as a Sieve abstraction for a prime calculator. Review for performance and Java/Java 8/Guava best practices. ...
4
votes
0answers
186 views

Wavefront-Reader (.obj) in Java - Part 1

I want to implement a wavefront-reader in Java. Therefore I've created some classes to extract a Vector3f and Vector2f (I use ...
3
votes
2answers
5k views

Checking if an element sastifying a condition in a list comes before another of a different condition

This is for Java 6 and uses Guava. It's a little ugly and I'm worried I missed some obvious way to do it a lot better. If there is more than one element satisfying either condition I am saying it's ...
3
votes
1answer
2k views

Functionality for automatic retry after exception

I have made the following system to automatically retry network calls if some exception is thrown. (Earlier posted on stackOverFlow, solution inspired by what @Boris answered) ...
5
votes
1answer
5k views

Receiving a JSON string response from a URL

I am using RestTemplate as my HttpClient to execute a URL while the server will return a JSON string as the response. The ...
6
votes
1answer
311 views

Calling other machines from the LinkedList if one is blocked or down

This is a follow on to : Simplifying asynchronous "executeAsync" method along with "onFailure" callback. I am using AsyncRestTemplate as my <...
2
votes
2answers
92 views

Writing an API for checked subtraction

I have to write an API for checked subtraction where the input minuend can be < 0 but subtrahend can't be < 0. I think I've covered all the cases of underflow and overflow. With given conditions ...
4
votes
1answer
353 views

Logging using function as decorator in Guava

I needed to add a logger into my flow based on FluentIterable from the Guava library. I have a lot of functions and in some cases I would like to add logging when ...
11
votes
2answers
5k views

Efficient way of sorting a List based on multiple properties using Google Guava

I'm using Google Guava 17.0 library. I have a class named AroundBust containing only two properties id of type ...
10
votes
2answers
840 views

Twitter Streaming Client - Round#2

I've been experimenting with the Twitter Streaming API and would like some critical feedback. Specifically code correctness, code smells, overall structure, and my usage of collections and queues. ...
10
votes
3answers
275 views

Solve the game “Flux”

The Program I wrote this program as an answer to a question I thought of for Programming Puzzles and Code Golf. To avoid cross-posting, I will only summarize the requirements: Solve a game in a 3x4 ...
2
votes
1answer
116 views

Decoding big text input: potential concurrency bugs?

The code here will be directly pasted from this project. Quick summary: it is related to a Stack Overflow question. So, basically, all the code below aims to implement ...
8
votes
1answer
431 views

Cache<Long, BlockingDeque<Peer>> combined with Striped<ReadWriteLock>: is it thread-safe

I've implemented PeersContainer class with all operations that I need. I need something like multimap in concurrent environment, moreover I need remove entities ...
2
votes
0answers
264 views

Converting SpriteSheet Metadata .txt to .yaml

For practice I decided that I wanted to write an animation class for SpriteSheets. The problem is that a single Sprite can have different widths depending on the action they are drawn to act. A tool ...
5
votes
1answer
1k views

One-line initialisation for a constant list with all entries except one from another list

I'm looking to simplify the initialisation of the second constant, preferably to just one line. Any ideas? Anything from Guava or JDK (up to 1.6) is ok to use. ...
5
votes
2answers
139 views

Simplify finding indices of all instances of certain characters in a string

I have a string util method for finding potential "wrapping points" in a string. For example, if " " and "-" are considered ...
5
votes
1answer
6k views

Better code for converting a char to its UTF-8 percent encoding representation?

This is working code for a URI template (RFC 6570) implementation; when the character to render is not within a specific character set, it is needed to grab the UTF-8 representation of that character ...
7
votes
2answers
509 views

Helper class to memoize DateFormats application-wide

Premise Consider the following method: static String formatMyDate(Date date) { return new SimpleDateFormat("yyyy-MM-dd").format(date); } It's often ...
7
votes
1answer
3k views

Ability to forget the memoized supplier value

Guava has a feature request which is asking to provide the ability to forget memoized value on a given supplier. On top on that I needed another functionality where if during the calculation of ...
2
votes
2answers
422 views

At most one LocalDate per month in a list

I'm implementing argument check in a method where one parameter is a List of LocalDate objects (from Joda-Time). I want to make ...