Thursday, September 3, 2009

Nifty little Java trick...

In Java, there are many times when you have to deal with collections.  The code that is required in order to build a collection can be pretty cumbersome and usually follows the following pattern:

List strList = new ArrayList;
strList.add("1");
strList.add("2");
strList.add("3");

This code above can easily be changed to one line of code as such:
List strList = Arrays.asList("1", "2", "3");

I have found this little trick especially useful when writing unit tests.

If you plan on using this test in production level code, then you should be aware that creating a list in this fashion, does not allow for editing the list later. Instead, you should wrap the newly formed list in a constructor like so:
List strList = new ArrayList(Arrays.asList("1", "2", "3"));

Enjoy...

Friday, August 21, 2009

Grand Rapids BarCamp 2009


Grand Rapids Barcamp 2009 starts tonight!!!

Unfortunately, this is going to be the first BarCamp that I will not be attending.  I was really looking forward to going, but I cannot work it into the schedule.  I hope that everyone has a great time tonight and tomorrow....

Wednesday, July 15, 2009

Congratulations Google!!!!

Finally after 5 years....Gmail is finally out of Beta......

Now I can finally start using Gmail....hehehehehe

Do you think that people really waited for it to get out of beta before they created a Gmail account?

Wednesday, January 21, 2009

Eclipse Templates - Iterating Over a Map

Here is another code template. This one, I cannot take the credit for, but I have added it to my toolbox of great Eclipse Templates. It will give you the ability to iterate over a Map using the Map.Entry. Enjoy:

for (Iterator<Map.Entry<${type},${type2}>> it = ${variableName:var(java.util.Map)}.entrySet().iterator(); it.hasNext();) {  
    Map.Entry<${type},${type2}> entry = it.next();  
       ${type} key = entry.getKey();  
       ${type2} value = entry.getValue();  
       // do something with the key and the value  
}

Monday, January 19, 2009

Eclipse Templates - Jakarta Commons ToString, HashCode, Equals

Hey everyone,

I just wanted to take the time to share with you a code template that I created that has been very helpful in a project that I am currently working on. This template will give you the ability to create the toString(), equals(), hashCode() methods using the Jakarta Commons library. Enjoy:

 
${:import(org.apache.commons.lang.builder.EqualsBuilder,org.apache.commons.lang.builder.HashCodeBuilder,org.apache.commons.lang.builder.ReflectionToStringBuilder)}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

Saturday, January 17, 2009

Code Retreat - Hope I can make it.

Okay, okay, okay. I admit it. I am a huge geek. Because of that, this announcement sounds too cool to pass up. Let's see if I will be able to attend or not:

Greetings!

Are you a programmer who is serious about improving your craft? Do you love coding with others who feel the same way? Do you spend too much time toiling in thankless corporate legacy-code saltmines? Do you remember the joy of programming?

If so, please contact me. We are putting together a group of attendees for the first CodeRetreat, a week from Saturday in Ann Arbor, MI:

http://coderetreat.ning.com/

You need not be agile, and you need not be a Master-level programmer, to attend. You do need to be passionate about craft, open-minded, with a good attitude, a sense of humor, and a laptop.

We'll likely work in Eclipse and RubyMine.

We'll do everything in pairs or tuples.

We'll supply free food.

We'll code 80% of the time, and discuss 20% of the time.

Then, at the end of the day, we'll go out for beers.

It will be a blast.

If you know anyone else who might have fun and fit in at CodeRetreat #1, please send them our way as well.

Wednesday, December 24, 2008

Merry Christmas...

Merry Christmas everyone....

God Bless...