Archive for January, 2013

sublime text 3 beta released

Posted: 30 January 2013 in Uncategorized

Apparently, it’s out there. go check it out. I will as soon as I get a moment. Still working from netbeans mostly, but using Kate more and more.



Iterating over map entries

Posted: 29 January 2013 in Uncategorized

Map<String,String> map = new HashMap<String,String>();
for (Entry<String,String> entry : map.entrySet()){
String key = entry.getKey();
String value= entry.getValue();

Posted: 28 January 2013 in Uncategorized

I get annoyed having to import apache commons everytime I want to do a simple join when all I need is a simeple method that does this:

private String join(String[] array, String separator){
StringBuilder toReturn=new StringBuilder("");
for (String element : array) {
if (!"".equals(toReturn.toString())){
return toReturn.toString();

Here’s a quick example on how to do a regular expression matching in scala for a DCR

scala> val regexString="templatedata/category/type/data/(.*?)/(.*)"

regexString: java.lang.String = templatedata/category/type/data/(.*?)/(.*)

scala> val regex=regexString.r
regex: scala.util.matching.Regex = templatedata/category/type/data/(.*?)/(.*)

scala> val regex(language,file)=”templatedata/category/type/data/en_gb/mydcr”

language: String = en_gb
file: String = mydcr

scala> println(language)

scala> println(file)

If the file does not match the pattern, this happens:

scala> val regex(language,file)=”templatedata/category/type/data/en_gb”
scala.MatchError: templatedata/category/type/data/en_gb (of class java.lang.String)
at .<init>(<console>:11)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(

In order to avoid the exception, a quick check that it does match is in order:

scala> “templatedata/category/type/data/en_gb”.matches(regex.pattern.toString)
res4: Boolean = false

scala> “templatedata/category/type/data/en_gb/mydcr”.matches(regex.pattern.toString)
res5: Boolean = true