Skip to main content

Posts

Showing posts from August, 2010

Comparable interface

Lists and Arrays of objects that implement Comparable interface can be sorted automatically by Collections.sort and Arrays.sort respectively. Implementation Comparable is easy. You just have to implement compareTo(Object o). It should return negative integer, zero, or a positive integer as this object is less than, equal to,or greater than the specified object. Here goes an example: public void testListSort(){ Calendar cal = Calendar.getInstance(); cal.set(2010, 10, 1); License msWindows7 = new License("Windows", "7",new Date(cal.getTimeInMillis())); cal.clear(); cal.set(2010, 11, 10); License msWindowsVista = new License("Windows", "Vista", new Date(cal.getTimeInMillis())); cal.clear(); cal.set(2010, 11, 5); License lotusNotes = new License("Notes", "1.1", new Date(cal.getTimeInMillis())); List list = new ArrayList (3); list.add(lotusNotes);

desending sort algo

... double []test = new double []{88.6,88.9,-1,25,88.6}; int size = test.length; System.out.println("*** un-sorted ***"); for (double d : test){ System.out.println(d); } // descending sort algo ************************************* int counter = 0; int indexOfMax = 0; // after each iteration of while, test[counter] should have the correct value while (counter < size){ indexOfMax = counter; // assuming that test[counter] has the max value // this loop finds the index of max value (stores in indexOfMax) from the test array starting from index counter+1 for(int i = counter+1; i < size; i++){ if (test[i]>test[indexOfMax]){ indexOfMax = i; } } // end of for loop -- now indexOfMax should have the max value // swapping double tmp = test[counter]; test[cou

relocating/switching SVN repository

My SVN repository changed recently and I was worried about associating my Java workspace with the new repository . Checking out from the new repository was always an option but of course, I would have lost my non committed changes. After googling for half an hour, I found a way to switch my SVN repository. 1. Find the current repository's URL to which your files/folders are associated. svn info 2. Switch the repo. svn switch --relocate 3. Verify the current repo's URL. svn info Hope this helps.

Useful SVN commands

svn info Print information about paths in your working copy. svn status / svn st Print the status of working copy files and directories. svn update / svn up updates the working copy. svn commit -m "message goes here" / svn ci Send changes from your working copy to the repository svn log -l 10 Prints last 10 commits in reverse-chronological order by default.