Search Results

Search found 595 results on 24 pages for 'groovy'.

Page 7/24 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • How can I dynamically override a class's "each" method in Groovy?

    - by rewbs
    Groovy adds each() and a number of other methods to java.lang.Object. I can't figure out how to use the Groovy metaclass to dynamically replace the default each() on a Java class. I can see how to add new methods: MyJavaClass.metaClass.myNewMethod = { closure -> /* custom logic */ } new MyJavaClass().myNewMethod { item -> println item } // runs custom logic But it seems the same approach doesn't work when overriding methods: MyJavaClass.metaClass.each = { closure -> /* custom logic */ } new MyJavaClass().each { item -> println item } // runs Object.each() What am I doing wrong? How can I dynamically override each() in Groovy?

    Read the article

  • Aside from performance concerns, is Java still chosen over Groovy/JRuby etc.?

    - by yar
    [This is an empirical question about the state-of-the-art: I am NOT asking if Java is cooler or less cool than the dynamic languages that work in the JVM.] Aside from cases where performance is a main decision factor, do companies/developers still willingly chose Java over Groovy, JRuby or JPython? Personal Note: The reason I am asking is that, while I do some subset of my professional work in Ruby (not JRuby, for now), in my personal projects I use Java. While I have written non-trivial apps in Groovy, I prefer Java, but I wonder if I should just get over it and do everything in Groovy. I like Java because I feel that static typing saves me time and aids refactoring. (No, I am not familiar with Scala.) However, I feel that this very empirical, on-topic programming question may inform my decision.

    Read the article

  • Groovy as a substitute for Java when using BigDecimal?

    - by geejay
    I have just completed an evaluation of Java, Groovy and Scala. The factors I considered were: readability, precision The factors I would like to know: performance, ease of integration I needed a BigDecimal level of precision. Here are my results: Java void someOp() { BigDecimal del_theta_1 = toDec(6); BigDecimal del_theta_2 = toDec(2); BigDecimal del_theta_m = toDec(0); del_theta_m = abs(del_theta_1.subtract(del_theta_2)) .divide(log(del_theta_1.divide(del_theta_2))); } Groovy void someOp() { def del_theta_1 = 6.0 def del_theta_2 = 2.0 def del_theta_m = 0.0 del_theta_m = Math.abs(del_theta_1 - del_theta_2) / Math.log(del_theta_1 / del_theta_2); } Scala def other(){ var del_theta_1 = toDec(6); var del_theta_2 = toDec(2); var del_theta_m = toDec(0); del_theta_m = ( abs(del_theta_1 - del_theta_2) / log(del_theta_1 / del_theta_2) ) } Note that in Java and Scala I used static imports. Java: Pros: it is Java Cons: no operator overloading (lots o methods), barely readable/codeable Groovy: Pros: default BigDecimal means no visible typing, least surprising BigDecimal support for all operations (division included) Cons: another language to learn Scala: Pros: has operator overloading for BigDecimal Cons: some surprising behaviour with division (fixed with Decimal128), another language to learn

    Read the article

  • Scriptom (groovy) leaves Excel process running - am I doing something wrong?

    - by Alex Stoddard
    I am using the Scriptom extension to Groovy 1.7.0 to automate some processing using Excel 2007 under Windows XP. This always seems to leave an Excel process running despite my calling quit on the excel activeX object. (There is a passing reference to this phenomenon in the Scriptom example documentation too.) Code looks like: import org.codehaus.groovy.scriptom.ActiveXObject; def xls = new ActiveXObject("Excel.Application") xls.Visible = true // do xls stuff xls.Quit() The visible excel window does disappear but an EXCEL process is left in the task manager (and more processes pile up with each run of the script). There are no error message or exceptions. Can anyone explain why the Excel process is left behind and is there any way to prevent it from happening?

    Read the article

  • How to copy a subset from an array of strings to an array of ints using Groovy?

    - by Cuga
    I have a String array in a Groovy class (args to a main method): String[] args I'd like to convert the 3rd to the last element into a new array of ints. Is there an easier way to do this in Groovy other than: final int numInts = args.length - 2 final int [] intArray = new int[numInts] for (int i = 2; i < args.length; i++) { intArray[i-2]=Integer.parseInt(args[i]) } I wanted to do: final int numInts = args.length - 2 final int [] intArray = new int[numInts] System.arraycopy(args, 2, intArray, 0, numInts) But it throws a class cast exception. Thanks!

    Read the article

  • What makes Groovy+Grails a more productive setup than J2EE?

    - by Pradyumna
    I'm coming across references to 'Grails' and 'Groovy' quite often these days.. mostly on how great a productivity booster it is as opposed to standard J2EE, or things like JSF, Struts etc.. And there's also an impressive set of case studies in support of this on their web site too. So I just thought I would explore some of it.. As I start off on this, I was curious if there was any material (link, blog, article, paper..) that explains what are the special features in Grails+Groovy (and not found elsewhere, in the J2EE world) that makes it a more productive environment to work in? Thanks!

    Read the article

  • What's special about currying or partial application?

    - by Vigneshwaran
    I've been reading articles on Functional programming everyday and been trying to apply some practices as much as possible. But I don't understand what is unique in currying or partial application. Take this Groovy code as an example: def mul = { a, b -> a * b } def tripler1 = mul.curry(3) def tripler2 = { mul(3, it) } I do not understand what is the difference between tripler1 and tripler2. Aren't they both the same? The 'currying' is supported in pure or partial functional languages like Groovy, Scala, Haskell etc. But I can do the same thing (left-curry, right-curry, n-curry or partial application) by simply creating another named or anonymous function or closure that will forward the parameters to the original function (like tripler2) in most languages (even C.) Am I missing something here? There are places where I can use currying and partial application in my Grails application but I am hesitating to do so because I'm asking myself "How's that different?" Please enlighten me.

    Read the article

  • Java compiler rejects variable declaration with parameterized inner class

    - by Johansensen
    I have some Groovy code which works fine in the Groovy bytecode compiler, but the Java stub generated by it causes an error in the Java compiler. I think this is probably yet another bug in the Groovy stub generator, but I really can't figure out why the Java compiler doesn't like the generated code. Here's a truncated version of the generated Java class (please excuse the ugly formatting): @groovy.util.logging.Log4j() public abstract class AbstractProcessingQueue <T> extends nz.ac.auckland.digitizer.AbstractAgent implements groovy.lang.GroovyObject { protected int retryFrequency; protected java.util.Queue<nz.ac.auckland.digitizer.AbstractProcessingQueue.ProcessingQueueMember<T>> items; public AbstractProcessingQueue (int processFrequency, int timeout, int retryFrequency) { super ((int)0, (int)0); } private enum ProcessState implements groovy.lang.GroovyObject { NEW, FAILED, FINISHED; } private class ProcessingQueueMember<E> extends java.lang.Object implements groovy.lang.GroovyObject { public ProcessingQueueMember (E object) {} } } The offending line in the generated code is this: protected java.util.Queue<nz.ac.auckland.digitizer.AbstractProcessingQueue.ProcessingQueueMember<T>> items; which produces the following compile error: [ERROR] C:\Documents and Settings\Administrator\digitizer\target\generated-sources\groovy-stubs\main\nz\ac\auckland\digitizer\AbstractProcessingQueue.java:[14,96] error: improperly formed type, type arguments given on a raw type The column index of 96 in the compile error points to the <T> parameterization of the ProcessingQueueMember type. But ProcessingQueueMember is not a raw type as the compiler claims, it is a generic type: private class ProcessingQueueMember <E> extends java.lang.Object implements groovy.lang.GroovyObject { ... I am very confused as to why the compiler thinks that the type Queue<ProcessingQueueMember<T>> is invalid. The Groovy source compiles fine, and the generated Java code looks perfectly correct to me too. What am I missing here? Is it something to do with the fact that the type in question is a nested class? (in case anyone is interested, I have filed this bug report relating to the issue in this question) Edit: Turns out this was indeed a stub compiler bug- this issue is now fixed in 1.8.9, 2.0.4 and 2.1, so if you're still having this issue just upgrade to one of those versions. :)

    Read the article

  • Grails: Querying Associations causes groovy.lang.MissingMethodException

    - by Paul
    Hi, I've got an issue with Grails where I have a test app with: class Artist { static constraints = { name() } static hasMany = [albums:Album] String name } class Album { static constraints = { name() } static hasMany = [ tracks : Track ] static belongsTo = [artist: Artist] String name } class Track { static constraints = { name() lyrics(nullable: true) } Lyrics lyrics static belongsTo = [album: Album] String name } The following query (and a more advanced, nested association query) works in the Grails Console but fails with a groovy.lang.MissingMethodException when running the app with 'run-app': def albumCriteria = tunehub.Album.createCriteria() def albumResults = albumCriteria.list { like("name", receivedAlbum) artist { like("name", receivedArtist) } // Fails here maxResults(1) } Stacktrace: groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: (tunehub.LyricsService$_getLyrics_closure1_closure2) values: [tunehub.LyricsService$_getLyrics_closure1_closure2@604106] Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), trim() at tunehub.LyricsService$_getLyrics_closure1.doCall(LyricsService.groovy:61) at tunehub.LyricsService$_getLyrics_closure1.doCall(LyricsService.groovy) (...truncated...) Any pointers?

    Read the article

  • How to set the build.xml for the Groovy Antbuilder?

    - by Jan
    I want to execute a build.xml (Ant buildfile) from using GMaven (Maven Plugin for inline executing of Groovy in a POM). Since I have to execute the buildfile several times using the maven-antrun-plugin is not an option at the moment. I take a list of properties (environment and machine names) from an xml file and want to execute ant builds for each of those machines. I found the executeTarget method in the javadocs but not how to set the location of the buildfile. How can I do that - and is this enough? What I have looks as follows: <plugin> <groupId>org.codehaus.groovy.maven</groupId> <artifactId>gmaven-plugin</artifactId> <executions> <execution> <id>some ant builds</id> <phase>process-sources</phase> <goals> <goal>execute</goal> </goals> <configuration> <source> def ant = new AntBuilder() def machines = new XmlParser().parse(new File(project.build.outputDirectory + '/MachineList.xml')); machines.children().each { log.info('Creating machine description for ' + it.Id.text() + ' / ' + it.Environment.text()); ant.project.setProperty('Environment',it.Environment.text()); ant.project.setProperty('Machine',it.Id.text()); // What's missing? ant.project.executeTarget('Tailoring'); } log.info('Ant has finished.') </source> </configuration> </execution> </executions> </plugin>

    Read the article

  • Null Safe dereferencing in Java like ?. in Groovy using Maybe monad

    - by Sathish
    I'm working on a codebase ported from Objective C to Java. There are several usages of method chaining without nullchecks dog.collar().tag().name() I was looking for something similar to safe-dereferencing operator ?. in Groovy instead of having nullchecks dog.collar?.tag?.name This led to Maybe monad to have the notion of Nothing instead of Null. But all the implementations of Nothing i came across throw exception when value is accessed which still doesn't solve the chaining problem. I made Nothing return a mock, which behaves like NullObject pattern. But it solves the chaining problem. Is there anything wrong with this implementation of Nothing? [http://github.com/sathish316/jsafederef/blob/master/src/s2k/util/safederef/Nothing.java] As far as i can see 1. It feels odd to use mocking library in code 2. It doesn't stop at the first null. 3. How do i distinguish between null result because of null reference or name actually being null? How is it distinguished in Groovy code?

    Read the article

  • Python vs Groovy vs Ruby? (based on criteria listed in question)

    - by Prembo
    Considering the criteria listed below, which of Python, Groovy or Ruby would you use? Criteria (Importance out of 10, 10 being most important) Richness of API/libraries available (eg. maths, plotting, networking) (9) Ability to embed in desktop (java/c++) applications (8) Ease of deployment (8) Ability to interface with DLLs/Shared Libraries (7) Ability to generate GUIs (7) Community/User support (6) Portability (6) Database manipulation (3) Language/Semantics (2)

    Read the article

  • How to access controller dynamic properties within a base controller's constructor in Grails?

    - by 4h34d
    Basically, I want to be able to assign objects created within filters to members in a base controller from which every controller extends. Any possible way to do that? Here's how I tried, but haven't got to make it work. What I'm trying to achieve is to have all my controllers extend a base controller. The base controller's constructor would be used to assign values to its members, those values being pulled from the session map. Example below. File grails-app/controllers/HomeController.groovy: class HomeController extends BaseController { def index = { render username } } File grails-app/controllers/BaseController.groovy: abstract class BaseController { public String username public BaseController() { username = session.username } } When running the app, the output shown is: 2010-06-15 18:17:16,671 [main] ERROR [localhost].[/webapp] - Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass ... Caused by: java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsControllerClass ... Caused by: java.lang.reflect.InvocationTargetException ... Caused by: org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [com.my.package.controller.HomeController]! ... Caused by: groovy.lang.MissingPropertyException: No such property: session for class: com.my.package.controller.HomeController at com.my.package.controller.BaseController.<init>(BaseController.groovy:16) at com.my.package.controller.HomeController.<init>(HomeController.groovy) ... 2010-06-15 18:17:16,687 [main] ERROR core.StandardContext - Error listenerStart 2010-06-15 18:17:16,687 [main] ERROR core.StandardContext - Context [/webapp] startup failed due to previous errors And the app won't run. This is just an example as in my case I wouldn't want to assign a username to a string value, but rather a few objects pulled from the session map. The objects pulled from the session map are being set within filters. The alternative I see is being able to access the controller's instance within the filter's execution. Is that possible? Please help! Thanks a bunch!

    Read the article

  • Tab Sweep - Upgrade to Java EE 6, Groovy NetBeans, JSR310, JCache interview, OEPE, and more

    - by alexismp
    Recent Tips and News on Java, Java EE 6, GlassFish & more : • Implementing JSR 310 (New Date/Time API) in Java 8 Is Very Strongly Favored by Developers (java.net) • Upgrading To The Java EE 6 Web Profile (Roger) • NetBeans for Groovy (blogs.oracle.com) • Client Side MOXy JSON Binding Explained (Blaise) • Control CDI Containers in SE and EE (Strub) • Java EE on Google App Engine: CDI to the Rescue - Aleš Justin (jaxenter) • The Java EE 6 Example - Testing Galleria - Part 4 (Markus) • Why is OpenWebBeans so fast? (Strub) • Welcome to the new Oracle Enterprise Pack for Eclipse Blog (blogs.oracle.com) • Java Spotlight Episode 75: Greg Luck on JSR 107 Java Temporary Caching API (Spotlight Podcast) • Glassfish cluster installation and administration on top of SSH + public key (Paulo) • Jfokus 2012 on Parleys.com (Parleys) • Java Tuning in a Nutshell - Part 1 (Rupesh) • New Features in Fork/Join from Java Concurrency Master, Doug Lea (DZone) • A Java7 Grammar for VisualLangLab (Sanjay) • Glassfish version 3.1.2: Secure Admin must be enabled to access the DAS remotely (Charlee) • Oracle Announces the Certification of the Oracle Database on Oracle Linux 6 and Red Hat Enterprise Linux 6

    Read the article

  • Hidden Gems: Accelerating Oracle Data Integrator with SOA, Groovy, SDK, and XML

    - by Alex Kotopoulis
    On the last day of Oracle OpenWorld, we had a final advanced session on getting the most out of Oracle Data Integrator through the use of various advanced techniques. The primary way to improve your ODI processes is to choose the optimal knowledge modules for your load and take advantage of the optimized tools of your database, such as OracleDataPump and similar mechanisms in other databases. Knowledge modules also allow you to customize tasks, allowing you to codify best practices that are consistently applied by all integration developers. ODI SDK is another very powerful means to automate and speed up your integration development process. This allows you to automate Life Cycle Management, code comparison, repetitive code generation and change of your integration projects. The SDK is easily accessible through Java or scripting languages such as Groovy and Jython. Finally, all Oracle Data Integration products provide services that can be integrated into a larger Service Oriented Architecture. This moved data integration from an isolated environment into an agile part of a larger business process environment. All Oracle data integration products can play a part in thisracle GoldenGate can integrate into business event streams by processing JMS queues or publishing new events based on database transactions. Oracle GoldenGate can integrate into business event streams by processing JMS queues or publishing new events based on database transactions. Oracle Data Integrator allows full control of its runtime sessions through web services, so that integration jobs can become part of business processes. Oracle Data Service Integrator provides a data virtualization layer over your distributed sources, allowing unified reading and updating for heterogeneous data without replicating and moving data. Oracle Enterprise Data Quality provides data quality services to cleanse and deduplicate your records through web services.

    Read the article

  • image/jpeg returned by groovy/grails is OK on development system, but corrupt on prod system. What c

    - by ?????
    I have a groovy/grails application that needs to serve images It works fine on my dev box, the image is returned properly. Here's the start of the returned JPEG, as seen by od -cx 0000000 377 330 377 340 \0 020 J F I F \0 001 001 001 001 , d8ff e0ff 1000 464a 4649 0100 0101 2c01 but on the production box, there's some garbage in front, and the d8ff e0ff before the 1000 is missing 0000000 ? ** ** ? ** ** ? ** ** ? ** ** \0 020 J F bfef efbd bdbf bfef efbd bdbf 1000 464a 0000020 I F \0 001 001 001 \0 H \0 H \0 \0 ? ** ** ? 4649 0100 0101 4800 4800 0000 bfef efbd It's the exact same code. I just moved the .war over and run it on a different machine. (Isn't Java supposed to be write once, run everywhere?) Any ideas? An "encoding" problem? The code is sent to the response like this: response.contentType = "image/jpeg"; response.outputStream << out;

    Read the article

  • Groovy 2.0 : plus statique pour un meilleur dynamisme, Invoke Dynamic, vérification des types et compilation statiques sur la première bêta

    Groovy 2.0 : plus statique pour un meilleur dynamisme Invoke Dynamic, vérification des types et compilation statiques sur la première bêta [IMG]http://idelways.developpez.com/news/images/groovy.jpg[/IMG] L'équipe du projet Groovy surprend la communauté du langage en sortant la version 2.0 en bêta, alors que c'est la 1.9 qui était attendue. Comme c'est tendance actuellement, Groovy abandonne la numérotation des versions majeures en deuxième position (1.x), où la version 2.0 devient « mythique et semble ne jamais vouloir arriver », explique Guillaume Laforge, manager du projet. Le projet aura désormais une évolution majeure chaque année, mais cette versi...

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >