Lost in the learning cloud
October 9, 2008 Leave a comment
My current software microcosm to survive the economic downturn
Ask Forgiveness. Not permission.
October 9, 2008 Leave a comment
My current software microcosm to survive the economic downturn
October 5, 2008 Leave a comment
Price in Decimal digits is difficult to pay if your currency does not have low-value coins in circulation. So decimal digits might have to be rounded to the nearest value so that a figure like 0.56 can be paid. java.Math has MathContext and RoundingMode to round decimal digits.
So there is a precision that we specify. In the following code the precision is ‘1’ which means that .5625 is rounded to .6. We have rounded to 1 digit and the precision is lost but we ensure that the digits are either 0.5 or 0.6 depending on which is the nearest.
BigDecimal tax = new BigDecimal( 0.5625, new MathContext( 1, RoundingMode.HALF_UP));
Output : 0.6
BigDecimal tax2 = new BigDecimal( 0.5325, new MathContext( 1, RoundingMode.HALF_UP));
Output : 0.5
BigDecimal tax2 = new BigDecimal( 0.5525, new MathContext( 1, RoundingMode.HALF_UP));
Output : 0.6 ( 0.55 is equidistant from 0.5 and 0.6. So it is rounded up to 0.6 )
September 25, 2008 2 Comments
I wrote an Aspect to advise a particular constant-specific method.
What is a constant-specific method ?
The J2SE 5 documentation explains it.
“You can declare the method abstract in the enum type and override it with a concrete method in each constant. Such methods are known as constant-specific methods.”
There is an example here.
The enum is
package com.test.generics;
import java.util.Collection;
import java.util.List;
import java.util.Set;
public enum TestEnum {
Value1{
public <T> List<T> getValue(){ return null; }
public <T> List<T> getSameValue(){ return null; }
},
Value2{
public <T> Set <T>getValue(){ return null; }
public <T> List<T> getSameValue(){ return null; }
};
abstract <T> Collection<T> getValue();
abstract <T> Collection<T> getSameValue();
public static void main(String[] args) {
System.out.println( Value1.getSameValue() );
System.out.println( Value2.getSameValue() );
}
}
package com.test;
import java.util.List;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import com.test.generics.TestEnum;
@Aspect()
public class EnumAspect {
/*
Matches a particular method of all enum values
*/
@Pointcut(
"execution(List<T> getValue())" )
public void testPointcut(){};
@Before("testPointcut()")
public void test() {
System.out.println( "Generics aspect" );
}
/*
Matches a method of a particular enum values
*/
@Pointcut(
"execution(List<T> getSameValue()) && target(testEnum) && if()")
public static boolean testPointcut1( TestEnum testEnum ){
return testEnum == TestEnum.Value2;
}
@Before("testPointcut1(testEnum)")
public void test1( TestEnum testEnum ) {
System.out.println( "Generics aspect [" + testEnum.ordinal() + "]" );
}
}
The if() pointcut expression with an empty body is used and the testPointcut1 method tests for the value of the enum. There does not seem to be a JoinPoint matching pattern to pick out certain enum values automatically. It looks like a pattern would be useful.
Update : Raised an enhancement request.
Update : 26 Oct 2020
One of the contributors who has commented here pointed out that this aspect works. I am not sure if this would have worked 12 years back when I raised the request. At that time I thought it was a missing feature.
@Aspect
public class EnumAspect {
@Pointcut("execution(java.util.Collection+ getValue()) && target(testEnum) && if()")
public static boolean testPointcut1(TestEnum testEnum) {
return testEnum == TestEnum.Value1;
}
@Before("testPointcut1(testEnum)")
public void test1(JoinPoint joinPoint, TestEnum testEnum) {
System.out.println(joinPoint + " -> " + testEnum);
}
@Pointcut("execution(java.util.Collection+ getValue()) && target(testEnum) && if()")
public static boolean testPointcut2(TestEnum testEnum) {
return testEnum == TestEnum.Value2;
}
@Before("testPointcut2(testEnum)")
public void test2(JoinPoint joinPoint, TestEnum testEnum) {
System.out.println(joinPoint + " -> " + testEnum);
}
}
September 19, 2008 Leave a comment
I spent a few months on an agile project but did not understand the meaning of User Story Points until I read “Hours vs. Story Points”
September 3, 2008 Leave a comment
Like many other programmers I wish I had started learning Ruby when it was created, all the more so for the demand for broad programming skills now. I started using NetBeans 6.1 which made JRuby programming easier. I started to look at some example code written in other languages and write equivalent Ruby code. If you have good programming experience ( Updated : Hope it is not the Kruger-Dunning effect :-)then you can start with fairly complex code when learning a new language.
The example is JavaScript event code that can be mixed-in with other code. Actually I came across many powerful features of JavaScript when I programmed using RhinoScript recently.
I hope to update the code but as of now I have the skeleton below. I wouldn’t be able to explain everything because this is my first serious piece of Ruby code. I will try to use this “mixin” code along with other code.
event_mixin_module.rb
module EventMixinModule
$listeners
EventManager = { "notify" => proc {
puts "notify"
if ( nil == defined?($listeners) )
puts "No listeners registered"
end
puts $listeners
},
"listen" => proc {
|listen|
puts "listen"
$listeners = listen || [];
}
}
puts EventManager["listen"].call( "listener" )
#puts EventManager["notify"].call
end
domain_object.rb
require "event_mixin_module"
class DomainObject
include EventMixinModule
def initialize
puts "DomainObject"
end
def setvalue
puts "setvalue"
EventManager["notify"].call
end
end
domain_object_test.rb
require "domain_object"
class DomainObjectTest
def initialize
end
domainobject = DomainObject.new
domainobject.setvalue
end
August 18, 2008 Leave a comment
We take the Model-View-Controller idea as granted. Sometimes we do not even understand the true idea behind this pattern. Recently I was trawling the net looking for original reading material after I was disappointed with my previous job. I came across this original paper on MVC written by the inventor, Trygve Reenskaug. It is interesting to note that many of the ideas in Software engineering originated several decades back( 1978 in this case )
It is easier to download a framework and prototype an example but it is far more difficult to understand the underpinnings of solid design. It is sad that our offshore business forces us to neglect design principles and take the easier route.
July 20, 2008 Leave a comment
James Gosling’s blog has a link to an essay written by Ivan Sutherland. It is about courage that technologists need and is surely a souce of inspiration. I personally liked it because some of us in the offshore software business need courage to stay afloat in an industry that does not value software design or innovation or research as much as it values money and software exports.
This essay has this introduction to the author.
”
In this paper, his spirit and joy are revealed:
I, for one, am and will always remain a practicing technologist. When denied my
minimum daily adult dose of technology, I get grouchy. I believe that technology
is fun, especially when computers are involved, a sort of grand game or puzzle
with ever so neat parts to fit together. I have turned down several lucrative administrative
jobs because they would deny me that fun. If the technology you do isn’t
fun for you, you may wish to seek other employment. Without the fun, none of us
would go on.
”
May 24, 2008 Leave a comment
I found this RIA benchmarking very cool. I was looking for a paging AJAX pattern. Is the last option, ‘Flex paged’ a paging pattern ? Have to investigate.
October 21, 2007 Leave a comment
This is the WebSphere Portal script that we use to check if a particular page has the proper theme or not.
There is also a script to apply a theme to a page. We use XMLAccess to apply the theme but I think a JACL script can also do that.
Check what theme has been applied to a particular Portal page using JACL :
sh wpscript.sh -user portaluser -password portalpassword
WASX7209I: Connected to process "WebSphere_Portal" on node Node1 using SOAP
connector; The type of process is: ManagedProcess
WASX7029I: For help, enter: "$Help help"
wsadmin>$Portal login portaluser portalpassword
logged in as "uid=uid,cn=users,dc=company,dc=com"
wsadmin>$Content find page uniquename "wps.My Portal" select
6_F0QPNQO200SAD02178PJP91042
wsadmin>$Content get 6_F0QPNQO200SAD02178PJP91042 themename
AppliedThemeName
So AppliedThemeName is the theme applied to wps.My Portal
September 30, 2007 Leave a comment
I have managed to make AspectJ LTW work in WebSphere Portal with the help of GlassBox 2.0. Installation of the GlassBox Inspector was easy
Generic JVM arguments are
-Xbootclasspath/p:C:\IBM\glassbox\java14Adapter.jar -Xbootclasspath/a:C:\IBM\glassbox\createJavaAdapter.jar;
C:\IBM\glassbox\aspectj14Adapter.jar;
C:\IBM\glassbox\aspectjweaver.jar ${WPS_JVM_ARGUMENTS_EXT} -Daspectwerkz.classloader.preprocessor=
org.aspectj.ext.ltw13.ClassPreProcessorAdapter
-Ddb2j.system.home=${WPS_HOME}/cloudscape -Xp128k,64k -Xk40000
Classpath is
C:\IBM\glassbox\glassboxMonitor.jar;
C:\eclipse\workspace\FacesPortletTracker\
com\faces\tracker\jars\portlettracker.jar
portlettracker.jar contains my aspect class and aop.xml
My aspect looks like this
import javax.portlet.PortletException;
import com.facesportlet.tracker.FacesPortletTracker;
public aspect FacesGenericPortletAspect {
pointcut portletTracker() :
execution (* com.facesportlet.tracker.FacesPortletTracker.*(..)
throws PortletException );
before(): portletTracker(){
System.out.println( "Faces Portlet tracked");
}
}
GlassBox expects the aop.xml to be like this.
<aspectj> <weaver options="-showWeaveInfo -verbose -debug"> <include within="com.facesportlet.tracker.FacesPortletTracker"/> </weaver> <aspects> <aspect name="com.faces.tracker.FacesGenericPortletAspect"/> </aspects> </aspectj>