If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Tuesday, September 29, 2009

Bespin, an open extensible web-based framework for code editing

I would not like to withold this promising new project from Mozilla labs.

These guys are creating an awesome platform for developer collaboration.. just take a look at following links:

https://bespin.mozilla.com/
http://labs.mozilla.com/bespin/

Geolocation supported by latest version of browsers


If you installed the latest update of your preferred browser you might see a new small blue button in google maps. This button only appears if your browser supports geolocation. This functionality basically enables the browser to ask it's "location provider" for an approximate location. This location is determined based on
"WIFI access point", "IP-address", "GPS" or a combination.

Of course I updated my browser immediately (Firefox 3.5.3) and did a test. Without GSP available to my browser, it still gives a pretty good estimate of my location (+- few 100 metres).

Thursday, September 17, 2009

Getting the most out of Enums

Below an enum I created for some project...

Shoot and give comments !!



public enum DataType{

String(
"java.lang.String",
"String",
Operator.EQUALS,
Operator.CONTAINS,
Operator.IS_EMPTY,
Operator.IS_NULL,
Operator.IN
) {
public Object newInstance(Object value) {
String object = null;
if (value == null) {
return object;
}
try {
object = java.lang.String.valueOf(value.toString());
} catch (Exception e) { }
return object;
}
},
Integer(
"java.lang.Integer",
"Integer",
Operator.EQUALS,
Operator.IS_NULL,
Operator.GT,
Operator.GTE,
Operator.LT,
Operator.LTE,
Operator.BETWEEN
) {
public Object newInstance(Object value) {
Integer object = null;
if (value == null) {
return object;
}
try {
object = java.lang.Integer.valueOf(value.toString());
} catch (Exception e) { }
return object;
}
},
Long(
"java.lang.Long",
"Long"
) {

public Object newInstance(Object value) {
Long object = null;
if (value == null) {
return object;
}
try {
object = java.lang.Long.valueOf(value.toString());
} catch (Exception e) { }
return object;
}
},
Double(
"java.lang.Double",
"Double",
Operator.EQUALS,
Operator.IS_NULL,
Operator.GT,
Operator.GTE,
Operator.LT,
Operator.LTE,
Operator.BETWEEN
) {
public Object newInstance(Object value) {
Double object = null;
if (value == null) {
return object;
}
try {
object = java.lang.Double.valueOf(value.toString());
} catch (Exception e) { }
return object;
}
},
Date(
"java.util.Date",
"Date"
) {
public Object newInstance(Object value) {
Long time = null;
Date object = null;
if (value == null) {
return object;
}
try {
time = java.lang.Long.valueOf(value.toString());
object = new Date(time);
} catch (Exception e) { }
return object;
}
},
Character(
"java.lang.Character",
"Character"
) {
public Object newInstance(Object value) {
Character object = null;
if (value == null) {
return object;
}
try {
String stringvalue = value.toString();
if (stringvalue.length() == 1 ) {
object = new Character(stringvalue.charAt(0));
}
} catch (Exception e) { }
return object;
}
},
BigDecimal(
"java.math.BigDecimal",
"BigDecimal"
) {
public Object newInstance(Object value) {
BigDecimal object = null;
if (value == null) {
return object;
}
try {
Double doubleValue = java.lang.Double.valueOf(value.toString());
object = java.math.BigDecimal.valueOf(doubleValue);
} catch (Exception e) { }
return object;
}
},
Boolean(
"java.lang.Boolean",
"Boolean"
) {
public Object newInstance(Object value) {
Boolean object = null;
if (value == null) {
return object;
}
try {
object = java.lang.Boolean.valueOf(value.toString());
} catch (Exception e) { }
return object;
}
};

private String fullName;
private String shortName;
private List validOperators;

DataType(String fullName, String shortName, Operator...operators) {
this.fullName = fullName;
this.shortName = shortName;
validOperators = new ArrayList();
for (Operator operator : operators) {
validOperators.add(operator);
}
}

public String getFullName() {
return this.fullName;
}

public String getShortName() {
return this.shortName;
}

public List getValidOperators() {
return this.validOperators;
}

public abstract Object newInstance(Object value);

public String toString() {
return this.shortName;
}

}