Questions tagged [groovy]

Groovy is an object-oriented programming language for the Java platform. It is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk. It can be used as a scripting language for the Java Platform.

Filter by
Sorted by
Tagged with
1 vote
0 answers
76 views

Test-case runner for Jenkins

I am new to groovy/jenkins. I am using active choices parameter (projects) and active choices reactive parameter (testcases). The code below will loop thru ...
2 votes
0 answers
38 views

Find Invalid User Relationships in User to Manager Map (validate map as valid tree structure with no circular relationships)

We have a new service where an admin can upload a spreadsheet of new users they want to add to our application. During our processing we make a union map of all the users both existing and new ...
5 votes
1 answer
64 views

Design - prevent multiple nesting in function

I have a function written in Groovy which needs to save a record and also return response from the server. Function is working fine, but I am not happy with the design because I have a problem with ...
  • 183
2 votes
1 answer
318 views

Jenkins Declarative pipeline for multi-branch pipleline

I am working on setting up automated build and deploy jobs in jenkins for a php based project. I would like some feedback on my Jenkinsfile. Specifically regarding the parallelization, the (in my ...
  • 129
4 votes
1 answer
739 views

Groovy script to get average price per group from different data arrays

I've been trying to learn Groovy lately and I tried to solve a problem which involves designing a routine that will calculate the average Product price per Group. I have the following data: ...
1 vote
2 answers
2k views

Replace each element in a list [closed]

Here is how to transform a Zorglub (it is an API that I can not modify): Zorglub transformedZorglub = zorglub.transform() I am given a ...
0 votes
1 answer
82 views

Spring: Creating a Mutable Common Command Object or Controller Interceptor

I'm integrating with a 3rd party vendor that has Users and Organizations in it. My tool is a user administration tool that ...
  • 191
4 votes
0 answers
165 views

File operations using Groovy

The idea is to read a file - "data" - and write the information to a new file - "output" - only if it meets the criteria (if the resource usage is more than a configured threshold). Content of the ...
1 vote
0 answers
134 views

Display multiple video in video tag using timeduration in Grails Application

I've requirements to display video of some time duration in video tag. I've written following code for the same in my grails application. videoFeed.gsp ...
2 votes
0 answers
276 views

Groovy Map/Reduce for Jenkins DSL

Jenkins DSL doesn't support collect and inject from what I can tell (I get missing method exceptions when I try), so I ...
  • 30.7k
1 vote
2 answers
184 views

Is this FizzBuzz code idiomatic Groovy?

I'm new to Groovy but have some experience with Java, C and Python. I'd appreciate your feedback on Groovy style and features in this FizzBuzz code. Review Checklist Is it idiomatic Groovy code? Can ...
  • 619
1 vote
1 answer
285 views

Extract attachment between MIME boundary markers

I am trying to extract invoice which is surrounded between a boundary keyword in groovy, in the below example boudary key word is a92720f5836d4daaa4251e805cba228b ...
  • 717
2 votes
1 answer
12k views

Groovy optimize method to convert JSON to map

I have this method which creates a map from a JSON request parameter. Right now I've hard-coded JSON keys to convert it to map. Can it be converted to a generic method which converts a request's JSON ...
  • 717
1 vote
1 answer
66 views

Finding duplicate invoices

I have a invoiceList which is a List<Map<String:String>> and am trying to find out if all the invoices have same <...
  • 717
2 votes
1 answer
277 views

Combine lists of objects with no duplicates

I have 2 groovy sql resultset, I need to combine the result set so that project_no should be unique and case_no can have ...
  • 121
4 votes
1 answer
218 views

More groovifed way of sublist with varying range

Student list of 50 students and a teacher list of 3 teachers. Section XML as the output where each teacher is assigned to a section, and up to 20 students are assigned in that section. Need to loop ...
  • 141
3 votes
1 answer
93 views

Converting regular text phrase to Pig Latin in Groovy

Am I using the best conventions or are there better ways? ...
2 votes
0 answers
94 views

Rijndael key expansion

I am writing Rijndael for academic purpose, following wikipedia's description. https://en.wikipedia.org/wiki/Rijndael_key_schedule I would like to know, if up to this point it is correct, both from ...
  • 21
29 votes
2 answers
300 views

Simon, Mat's Mug, what's the (rating) difference?

This is a part of the code for the almighty bot @Duga (That's me!). Every evening, 15 minutes before "RELOAD" (00:00 UTC), I post the reputation differences for some Code Review users. Example ...
  • 564
10 votes
2 answers
38k views

Preventing XSS attacks in a Spring MVC application controller

One of the URL in my application is vulnerable to XSS attack, so I am handling it in the below way. I created a util class: ...
  • 717
0 votes
1 answer
93 views

Groovy pathfinding algorithm

I have created a bit of path-finding code in response to this code golf question. Since this is one of my first large bits of code in Groovy that I have written, I would like to see how I could ...
  • 1,690
0 votes
1 answer
56 views

Dynamic field performance

A have a model with a dynamic field like so: ...
7 votes
1 answer
157 views

Sentence building DSL

Cardshifter is an online trading card game, made by a gang of Code Review community members. Cards can have a bunch of different, and sometimes complex effects, and descriptions for these are ...
  • 2,641
6 votes
1 answer
121 views

Grooving Project Euler # 8

I recently watched a video course on groovy and started working on some of the Project euler problems to flex my groovy* muscle. (This is problem #8) The four adjacent digits in the 1000-digit number ...
  • 1,690
15 votes
2 answers
787 views

Builder pattern for users in document database

I'm attempting to make a builder pattern that makes sense and is practical for storing user data in a flexible way in a document database. The DB I chose is MongoDB, and I'm using its Java API ...
  • 20.3k
5 votes
0 answers
1k views

A Groovier way of inserting and updating database records

I've written a simple little Groovy class handling my database interactions. All it has to do is check if a row exists in a target table with primary key values which match those of an incoming map. ...
  • 1,182
12 votes
0 answers
193 views

Multithreaded Groovy Mandelbrot

Seeing as it's October, I thought I'd do the community challenge. Due to my inexperience coding in Groovy, I decided to give Groovy a go. I'm not sure how well I followed Groovy conventions, and the ...
  • 3,255
3 votes
1 answer
36 views

Optimize time for file download

This is the working code snippet to download file from a URL. I want to know if there is any optimization I can do to download the file faster. ...
  • 250
7 votes
1 answer
1k views

Generation of Groovy source from parent Java class

I use Groovy to write business rules into big, long term Java software. Use Groovy in object way, that is not as groovy Script, but every elementary groovy source overrides some Java API class. i.e. <...
  • 171
3 votes
0 answers
24 views

Submitting forms on pages linked from a main page

In this scenario, the main page contains a list of links to the subpages. The requirement is to navigate to each page (if a condition passes) and perform some actions. I have written the loop using ...
  • 215
4 votes
1 answer
150 views

Scissors: A fluent API for manipulating lists using the familiar copy-cut-and-paste

What I've hastily named the Scissors API brings the cut-copy-paste paradigm made popular by word processors to the realm of list processing. The Scissors API is fluent, provides methods to manipulate ...
-1 votes
1 answer
161 views

Is my Binary tree correct?

I have been watching this video: https://www.youtube.com/watch?v=M6lYob8STMI And here is the code of it in groovy (just the add method): ...
's user avatar
25 votes
1 answer
477 views

A Groovy Election

Implementing the July 2015 Community Challenge seemed relevant considering it is election time. I decided to go with the strategy pattern as this can be implemented in many different ways. I did my ...
7 votes
2 answers
302 views

Generating random HearthStone cards: Preparing the training data

For a little toy project of mine I need to have data available in a certain format in order to be able to feed into a Recurrent Neural Network (Long short term memory), it uses HearthStone card data ...
  • 10.6k
4 votes
2 answers
576 views

Slurp JSON trading cards to valid HTML

For Cardshifter TCG we pretty frequently update our list of available cards, so I tried to think of a way to make it easy to transform an exported JSON file containing all the cards into a decent HTML ...
  • 20.3k
8 votes
2 answers
4k views

Registration, login and logout in a Grails application

I'm completely new to Groovy, but have many years of Java experience, and recently I have started working on a Grails application, currently it contains the following: User and Person domain classes ...
  • 10.6k
7 votes
2 answers
111 views

Append user input to a database

This is my first time writing a Swing+Groovy application that successfully inserts data to SQL tables. It may look like example code, but it is more test code, as I will eventually expand this to a ...
  • 20.3k
7 votes
1 answer
186 views

Do you Connect with my Groove?

I'm new at groovy, and this is my first time writing a database connection script. It may seem like example code, but it is more like test code. It works as posted, and I'm planning to use this as a ...
  • 20.3k
4 votes
1 answer
25 views

GroupBy field with and without white spaces

I have these invoices listed: ...
  • 717
1 vote
2 answers
99 views

Counting only weekend days between two timestamps

I am fairly new to the Groovy arena. I recently modified some code to add the following block. This code is added to remove dates we were supposed to remove from the total counts. This data goes on ...
3 votes
1 answer
5k views

Regex to extract selective lines

I have a list of error messages: ...
  • 717
4 votes
1 answer
361 views

Groovy Map<String,List<Map<String,String>>> data manipulation method optimization

Am trying to update the Map<String,List<Map<String,String>>> invoices with the invoiceErrors as below ...
  • 717
1 vote
2 answers
218 views

Groovy method optimization to build <String, List<List>> tokens

I have a string array: ...
  • 717
3 votes
1 answer
12k views

Filtering a list based on conditions

I'm currently filtering a list based on several conditions, which may or may not be present: ...
3 votes
2 answers
423 views

FizzBuzz-type program that reads/writes to Excel

I'm new to Groovy, and coming from PHP it's been a rough transition. The code below works. However, I would appreciate feedback on how better to write it and follow good practice with Groovy. I ...
2 votes
2 answers
656 views

Remove list of files from another list of files by their name

In groovy I have a list of files A and also another list of files B. I want to remove all the files from A that have a filename that also occurs in the list of files B. I wrote the following code: <...
3 votes
1 answer
56 views

Move a line in a file

In Groovy 1.8.6 I need to move a line just before another one. I'm interested in any improvements. ...
2 votes
0 answers
198 views

Using my own Optional type with fold method in groovy

I have written an Optional type in groovy roughly based on java8s Optional. I implemented and use a fold method and would like to know if it can be improved. First, ...
3 votes
1 answer
34 views

Comparing a list of messages with a list inside an object

...
0 votes
1 answer
233 views

Object with highest count in a Groovy list

I have a list of Parcel objects and am trying to write a closure that picks the parcel object with highest count: ...
  • 717