Skip to main content

Posts

Showing posts with the label groovy

Insertion Sort Algorithm in Java and Python

I've started to study more about algorithms. I think that it will be an excellent challenge and great experience. I found this course in MIT Open CourseWare website :  " Introduction to Algorithms (SMA 5503) " , and I'm studying from this resource and also I've bought the related book to this course. Well, I'm going to post entries related to algorithms in Java, Groovy and Python language (my new lovers :) ). For Java coding I'm going to create an interface to be implemented for all my algorithm classes. package melg.algorithms.sorting; public interface ISorting { long[] makeSorting(long[] array, boolean debug); String getStats(); } Also I'll use this tool class, in order to be used for debugging purpose: package melg.algorithms.sorting; public class SortUtilAlgorithm { /** * Prints in the console the items of the array object * * @param array * the array object. */ public static void showArray(long[] array) ...

My first serious Groovy class ..... decompiling java classes with closures

After I read the chapter 6 "closures" of the book Groovy and Grails Recipe, and I decided to use the power of closures of Groovy for resource (files) with other problem that I had, decompile in one step every class of jar library. Well, the purpose of this class is call an external java decompiler (jad) from a Groovy class and execute the command into directory where the jar file was decompressed. And by using the power of closures executes recursively into this directory until find the classes. Well, no more words, here the class package demo class Executor { // directory where the library(jar) was decompressed def path /** * Execute the decompilation of the classes into the directory defined in the path * @return */ def decompileClasses(){ def directory = new File(path) //make use of closures defined in the Object class directory.eachFileRecurse { def name = it.absolutePath //if the current resource hasn't a .class extension continues with...