Thursday, March 30, 2006

List Insert Based on CompareTo

Here's some code I've had to write more than once. It inserts something into a list at a position based on the compareTo method. Consequently the element inserted must imlpement this.

public void addElement(MyElement aElement)
{
List myElementsList = this.getMyList();

// Check that the list exists
if (myElementsList == null)
{
myElementsList = new ArrayList();
}

// Check that the list is not empty
if (myElementsList.size() == 0)
{
myElementsList.add(0, aElement); // add the element at the beginning
return;
}

MyElement currentElement;

for (int index = 0 ; index < myElementsList.size() ; index++)
{
currentElement = (myElement) myElementsList.get(index);

// if the current element has the same compareTo value as the element to be added
if (currentElement.compareTo(aElement) == 0)
{
// The hearing is already in the list. Take no further action and return
return;
}
// else if the current element is before the element to be added
else if (currentElement.compareTo(aElement) < 0)
{
myElementsList.add(index, aElement);
return;
}
}
}
}

Tuesday, March 28, 2006

Can Your Own Demo

I found something great on t'internet the other day. I had been asked to do a demo of our new ystem to some users but it would have taken too long to decommission, move and recommission our dev server to be able to show them something moving on screen. Then I remembered I'd seen flash demos on the Netbeans website. I slipped on over and saw they were using Wink.

It's brilliant. You just download and go. We have a real mickey mouse one at the moment but it seems form other demos I've seen you can add "Next" buttons, commentary and subsections of the screens. All this and it can export to a .swf file which you can share!

Beautiful.