Archive for March, 2006

Spot to be available in May

Small Programmable Object Technology (SPOT) is part of the J2ME family and aims to allow developers to build programs for wireless sensors. Sun are releasing a developer kit which will consist of two wireless sensors, a base station and the JavaBeans development software all for $499.

The aim is to allow researchers and budding hobbyists to experiment with the kit and see what type of systems it can create. Not sure if I am that interested in that area but I’m sure there are plenty of people that will be interested. I’m look forward to see what type of applications will be developed.

No Comments

Nice web 2.0 site

I was looking at Woophy earlier. It allows people to display photos from around the world. Users can look at their local area and see photo’s that people have taken.

Have a look at the pictures in Dublin and you can see a picture that I took at the Pope’s Cross in the Phoenix Park.

No Comments

DOJO widgets and a bit of Reiki!

I was having a look at DOJO. There are some fantastic widgets available. My favorite one that I have seen so far is the Fisheye widget. Have a look at the menu at the top of the page. As you hover over each icon, it zooms in. There are some great tools in this toolkit for developing more interactive websites. I’m looking forward to using some of the widgets.

I was at a wedding fair at the weekend and there was a stand offering a 20 minute Reiki session so I said I would give it ago. My Fiancee had recommended it to me a long time ago and I thought this was a good time to give it ago. The session consisted of me sitting it a chair while the Reiki Therapist placed her hands on different pressure points. It was a really good experience and apparently I am very susceptible to the energy flows!
I think I might give it a full session some time.

I met up with a few ex colleagues from Openet Telecom on Friday for a few drinks. It turned out to be a great night, I was surprised how many turned up considering the weather that night. I am going to try to plan some more nights out as there was a few that were not able to make it Friday.
Thank you to everyone that did make it.

No Comments

Ordering a list of Objects

This Java tip relates to functionality that has been around for quite a while but a lot of people are still not aware of it.

There are many occasions when you may need to order a list of data objects. Luckily the Java Collections Framework provides utilites to allow objects to be easily ordered.

The Comparable interface declares one interface:
public int compareTo(Object o);

The data object that you wish to compare must implement this interface. This method should return either -1, 0, or 1.
When the two objects are compared, the compareTo() method is called, passing the object that you wish to compare it to.

If the object is greater a 1 is returned, -1 will indicated that it is less and 0 will indicate that they are equal. In the ComparablePerson class below we have implemented the compareTo method. We will persume that all getter and setter methods are created.

public class ComparablePerson implements Comparable
{
private int age;
private String firstName = "";
private String secondName = "";

public ComparablePerson(String firstName, String secondName, int age)
{
this.firstName = firstName;
this.secondName = secondName;
this.age = age;
}

public int compareTo(Object o)
{
int result = -1;
if (o instanceof ComparablePerson)
{
ComparablePerson compareObj = (ComparablePerson) o;
// Compare by Age
result = new Integer(this.getAge()).compareTo(new Integer(
compareObj.getAge()));
if (result == 0)
{
result = this.getSecondName().compareTo(
compareObj.getSecondName());
if (result == 0)
{
result = this.getFirstName().compareTo(
compareObj.getFirstName());
}
}
}
return result;
}
}
....

In the compareTo method the we first check to see that the object that we wish to compare a ComparablePerson object. If it is not then we cannot compare the properties.

We first compare based on the age. There is no point writing a method to compare two int values as this is already implemented in the Integer compareTo method.

At this stage if the the objects are still equal we continue to compare based on the secondName property. We use the compareTo method of the String class to perform this check.

Finally if they are still equal we should check the firstName property.

This object can now be compared to another ComparablePerson object.
The Collections API provides methods that will sort or reverse a list of compareable objects. The CompareTest class will create a list of ComparablePerson objects and then sort the list.

public class CompareTest
{
public static void main(String[] args)
{
ComparablePerson john = new ComparablePerson("John", "Doe", 31);
ComparablePerson paul = new ComparablePerson("Paul", "Doe", 31);
ComparablePerson stephen = new ComparablePerson("Stephen", "Downey", 27);
ArrayList peopleList = new ArrayList();
peopleList.add(john);
peopleList.add(paul);
peopleList.add(stephen);
System.out.println(peopleList);
Collections.sort(peopleList);
System.out.println(peopleList);
Collections.reverse(peopleList);
System.out.println(peopleList);
}
}
...

The output is as follows:

[John Doe 31, Paul Doe 31, Stephen Downey 27]
[Stephen Downey 27, John Doe 31, Paul Doe 31]
[Paul Doe 31, John Doe 31, Stephen Downey 27]

No Comments