Monday, July 22, 2013

Lucene AppEngine growing: steps to Maven Central, GitHub and new site

Lucene AppEngine is changing; a lot of news are coming, keep yourself steady on the chair. Works are still in progress but in a few days everything should be complete.
The most important news that are coming to the Lucene AppEngine project are:
  1. Project site will move from lucene-appengine.googlecode.com to luceneappengine.googlecode.com;
  2. Official source repository will move from Mercurial to Git and from Googlecode to GitHub, but everything will be mirrored into the googlecode repository
  3. Lucene AppEngine maven artifacts will be deployed into Maven Central
  4. GroupId will change from com.googlecode.lucene.appengine into com.googlecode.luceneappengine;
  5. Version policy will change with a new policy, details below;
  6. Lucene AppEngine now works with Objectify 4


Why these choices?
  1. A new site means new policy under each and every point of view. The old site will remain untouched and sourcecode, maven repository... will still be available. That's why the official site is changed;
  2. I think that GitHub platform now is the best for an opensource project like LAE. Lucene AppEngine is about google appengine platform so the official site will still be into googlecode as mirror (simplest thanks to git);
  3. Maven Central is one of the biggest news for LAE and it simplifies the management of LAE for people using Maven or Ivy or Gradle etc... Having an artifact you need into Maven Central is a pleasure for each developer. Having Lucene AppEngine into maven central does not mean that downloads will disappear from googlecode sites, I will take care of it but only for released versions (this means that SNAPSHOTS version can be not manually downloaded from official site);
  4. GroupId is changed to be more compliant to artifacts standard;
  5. Version policy will be changed to simplify management of versions, LAE versions will be vertically splitted into two main line (one supporting Lucene 3 and the other one Lucene 4) and LAE will be no more released for each version of the Lucene project, but will be released when needed so if you want to upgrade your Lucene version you have to look at the compatibility matrix that I will write
  6. Lucene AppEngine uses Objectify 3, now Objectify 4 is nearly released as stable so there is no reason to keep version 3; With Objectify 4 LAE will be more stable, quick and ready for a production environment, my thanks go to every people developing this good framework for AppEngine environment;

What will happen to live demo site and demo source code/examples? Nothing those will go on and will continue using LAE but with the new version deployed into maven central.
Now you can also use GitHub for your contribution, source code here.
How to take a snapshot version of LAE? Simply add the repository to your pom.xml or in your settings.xml the sonatype snapshot repository:
...
    
        sonatype.oss.snapshots
        Sonatype OSS Snapshot Repository
        http://oss.sonatype.org/content/repositories/snapshots
        false
        true
    
...


A new LAE is coming; Stay tuned!


Friday, July 19, 2013

Java: Maps with enums as keys

Life is hard and world is big, but sometimes when we see another person where we don't expected him to be, we say "how little the world is" (at least this happens in Italy).
I think that world is really little at least for another reason :-p

Which one?! Simple!
A lot of people use HashMap (or other map implementations) filled with enum keys instead of using EnumMap.

Java standard SDK provides java.util.EnumMap specifically to manage maps with enums as keys, this map is size optimized and potentially quicker than HashMap counterpart. Furthermore an EnumMap mantains the natural order of Enum.

That's all, so lets try to change your code from
public class EnumMapMain {
    
    enum Tires {
        SOFT,
        MEDIUM,
        HARD
    }
    
    public static void main(String[] args) {
        Map tiresToDescription = new HashMap();
        tiresToDescription.put(Tires.HARD, "Worst grip of all tires but with a greate durability");
        tiresToDescription.put(Tires.MEDIUM, "Medium grip and medium durability");
        tiresToDescription.put(Tires.SOFT, "A lot of grip but usefull only for few laps");
        
        StringBuilder buildDescription = new StringBuilder("Tires Types:");
        for (Tires tire : Tires.values()) {
            buildDescription.append("\n\t").append(tire).append("\t-->\t").append(tiresToDescription.get(tire));
        }
        System.out.println(buildDescription.toString());
    }
}
to
public class EnumMapMain {
    
    enum Tires {
        SOFT,
        MEDIUM,
        HARD
    }
    
    public static void main(String[] args) {
        Map tiresToDescription = new EnumMap(Tires.class);
        tiresToDescription.put(Tires.HARD, "Worst grip of all tires but with a greate durability");
        tiresToDescription.put(Tires.MEDIUM, "Medium grip and medium durability");
        tiresToDescription.put(Tires.SOFT, "A lot of grip but usefull only for few laps");
        
        StringBuilder buildDescription = new StringBuilder("Tires Types:");
        for (Tires tire : Tires.values()) {
            buildDescription.append("\n\t").append(tire).append("\t-->\t").append(tiresToDescription.get(tire));
        }
        System.out.println(buildDescription.toString());
    }
}

It's simple and unpainful! It brings some memory and performance improvements to your code ;-)

Related posts: