Menu

Posts tagged with ‘java’

Learning with Open Source: Reviewing SVN commits log

kinow @ Feb 10, 2013 13:02:45

Last year I became an Apache committer, and dedicated most of my time learning the Apache way, reading different mailing lists and getting used to the things a committer is supposed to know (voting process, keeping everything in the mailing list, and so it goes) and getting used to [functor] API.

In 2013 I hope I can help in the release of [functor], since Java and functional programming are getting a lot more of attention recently, probably due to the project lambda. But I also want to start contributing with the other components from commons (like math, io, jcs) and other top level projects (hadoop, nutch, lucene).

Reviewing SVN commits log

FUNCTOR-14 was created to enhance the generators API in [functor]. I’d worked on a branch for this issue, but needed some review in order to be able to merge it with the trunk. That’s where you can see why Open Source is so awesome. Another Apache member, Matt Benson, created another branch to work on the project structure, but also to review the generator API.

Apache Software Foundation

( Read more … )

Using Apache Commons Functor functional interfaces with Java 8 lambdas

kinow @ Dec 21, 2012 15:08:14

Apache Commons Functor (hereon [functor]) is an Apache Commons component that provides a functional programming API and several patterns implemented (visitor, generator, aggregator, etc). Java 8 has several nice new features, including lambda expressions and functional interfaces. In Java 8, lambdas or lambdas expressions are closures that can be evaluated and behave like anonymous methods.

Functional interfaces are interfaces with only one method. These interfaces can be used in lambdas and save you a lot of time from writing anonymous classes or even implementing the interfaces. [functor] provides several functional interfaces (thanks to Matt Benson). It hasn’t been released yet, but there are some new examples in the project site, in the trunk of the SVN. I will use one of these examples to show how [functor] functional interfaces can be used in conjunction with Java 8 lambdas.

After the example with [functor] in Java 8, I will explain how I am running Java 8 in Eclipse (it’s kind of a gambiarra, but works well).

( Read more … )

Replacing a HashSet with a BitSet

kinow @ Oct 20, 2012 23:07:39

I always read the messages in the Apache dev mailing lists, including Apache Commons dev mailing list. And you should too. There are always interesting discussions. Sometimes you participate, other times you only watch what’s happening, but in the end you always learn something new.

A few days ago, I found an issue where it was being proposed to replace an unnecessary HashSet in ArrayUtils#removeElements() by a BitSet. Here’s how the code looked like:

HashSet<Integer> toRemove = new HashSet<Integer>();
for (Map.Entry<Character, MutableInt> e : occurrences.entrySet()) {
    Character v = e.getKey();
    int found = 0;
    for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
        found = indexOf(array, v.charValue(), found);
        if (found < 0) {
            break;
        }
        toRemove.add(found++);
    }
}
return (char[]) removeAll((Object)array, extractIndices(toRemove));

The HashSet created at line 1, in the code above, was used to store the array index of the elements that should be removed. And at line 13 there is a call to removeAll method, passing the indexes to be removed. And here’s how the new code looks like:

BitSet toRemove = new BitSet();
for (Map.Entry<Character, MutableInt> e : occurrences.entrySet()) {
    Character v = e.getKey();
    int found = 0;
    for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
        found = indexOf(array, v.charValue(), found);
        if (found < 0) {
            break;
        }
        toRemove.set(found++);
    }
}
return (char[]) removeAll(array, toRemove);

The first difference is at line 1. Instead of a HashSet, it is now using a BitSet. And at line 10, instead of adding a new element to the HashSet, now it “sets” a bit in the set (the bit at the specified position is now true). But there are important changes at line 13. The method removeAll was changed, and now the array doesn’t require a cast anymore. And the it is not necessary to cast the elements from HashSet anymore, as now the bit in the index position of the set is set to true. So the extractIndices method could be removed.

The code got simpler. But that’s not all. At Apache Software Foundation you can find a lot of talented developers - that’s why I got so excited after joining them. Besides simplifying the code, the developer responsible for these changes (sebb) also pointed out that the new code consumes less memory and is faster. Ah! And he also wrote unit tests

Invoking Testopia XML-RPC or JSON methods using Java

kinow @ Sep 09, 2012 16:08:09

Most TestLink [1] users are aware that there is an external API, maybe for the external API token being displayed in the user profile section. Today after a meeting with Peter Florijn [2], I realized that the same may not be true for Testopia [3] users.

I am quite new to Testopia, and there are many features that I haven’t used yet. But if I understand it correctly, the database is interfaced by several Perl scripts that are, by its turns, exposed as Web Service (most of them). The web services are available via a JSON and a XML-RPC API (what is very useful, TestLink supports supports only XML-RPC).

The communication between different programming languages and the external API’s is accomplished by a client API. In TestLink you have testlink-java-api [4] and testlink-api-java-client [5].

Testopia has a Java client too, available in Testopia source repository [6] and can be used to integrate your existing Java code with Testopia.

( Read more … )

Writing code to integrate Java projects to Testopia

kinow @ May 18, 2012 17:16:25

Peter Florijn and I are writing a Jenkins plug-in to integrate several test tools into Jenkins, something similar to what is done in TestLink plug-in. It’s still an idea being explored, and the whole project is subjected to changes without warning. The code is at https://github.com/kinow/testthemall.

The first tool that we are integrating is not TestLink, but Mozilla Testopia. As part of the process to integrate these tools, many Java API’s to interface the existing external APIs will be created, like it was done in TestLink with TestLink Java API.

Installing Testopia is very easy and straightforward. This was the best guide that I could find, and worked without errors at my Debian Squeeze. I only had to move the directories from /var/www to my home directory (I use my PHP Eclipse workspace as Apache home).

Testopia has a XML-RPC APi, just like TestLink, however it lacks an user friendly documentation and examples. I migrated the Java driver from Ant to Maven, for the sake of commodity. But the XML-RPC server is complaining that I have to log-in before listing the test cases of a test plan.

If you are interested in using Java and Testopia, here’s the link for the java project with Maven support: https://github.com/kinow/testopia-java-driver. I will update the project with examples, more tests and will try to clean up the code. Probably I will use either GitHub pages or a Wiki somewhere to document how to use Testopia and Java.

Stay tuned!

Cheers,