Archive

Archive for April, 2010

How to add websites to Google Custom Search Engine?

April 30th, 2010 No comments

Have you ever wondered how to add sites to Google custom search engine or CSE. Answer is to use Google Marker… a javascript which you can add to your browser tool bar or favorites.

Using the Google Marker (from the Marker documentation)
The Google Marker allows you to add and label sites in your Custom Search Engine. Please note that you must already have created or signed up to collaborate on a Custom Search Engine to use the Google Marker with a Custom Search Engine.

Once you are ready, simply add the Google Marker link below to your browser toolbar.

  • Firefox users: Drag the marker into the Bookmarks Toolbar.
  • Chrome users: Drag the marker into the Bookmarks Toolbar.
  • Internet Explorer users: Right-click on the marker, then select “Add to Favorites” > “Links.”


  • http://www.google.com/coop/cse/marker

    Share

    How to Sort Two Dimensional Data based on Multiple Parameters?

    April 26th, 2010 2 comments

    This is a follow up to my previous post How to Sort a Two Dimensional String Array using JAVA

    Here I am trying to sort an address table by Street Name, Street Number and City using java comparator. First I sort the table by Street Name (column A), then keeping street name as constant sort by Street Number (column B) and finally keeping street name and number as constant sort by City (column C)

    If you want to sort my more columns, you can easily add the rules to ORDER_BY_RULES – shown below.

    Address Table:

    Street Name Street Number City State Zip Code
    univ dr 101 Sunshine FL 33324
    break rd 102 Sunrise FL 33224
    univ dr 103 Cleveland OH 24785
    dykes rd 104 San Antonio TX 24785
    dykes rd 104 Boston MA 24785
    dykes rd 104 Orlando FL 24783
    import java.util.Arrays;
    import java.util.Comparator;
    
    public class Sort {
    
    static final Comparator<Address> ORDER_BY_STREETNAME = new Comparator<Address>() {
    	public int compare(Address a1, Address a2) {
    		return a1.streetName.compareTo(a2.streetName);
    	}
    };
    static final Comparator<Address> ORDER_BY_STREETNUMBER = new Comparator<Address>() {
    	public int compare(Address a1, Address a2) {
    		return a1.streetNumber.compareTo(a2.streetNumber);
    	}
    };
    static final Comparator<Address> ORDER_BY_CITY = new Comparator<Address>() {
    	public int compare(Address a1, Address a2) {
    		return a1.city.compareTo(a2.city);
    	}
    };
    
    static final Comparator<Address> ORDER_BY_RULES = new Comparator<Address>() {
    	public int compare(Address a1, Address a2) {
    		int i = ORDER_BY_STREETNAME.compare(a1,a2);
    		if(i == 0){
    			i = ORDER_BY_STREETNUMBER.compare(a1,a2);
    			if(i == 0){
    				i = ORDER_BY_CITY.compare(a1,a2);
    			}
    		}
    		return i;
    	}
    };
    
    public static void main(String args[]){
    	//Array with address to sort
    	Address[] addressArray = new Address[]{
    		new Address("univ dr","101", "Sunshine", "FL", "33324"),
    		new Address("break rd","102", "Sunrise", "FL", "33224"),
    		new Address("univ dr","103", "Cleveland", "OH", "24785"),
    		new Address("dykes rd","104", "San Antonio", "TX", "24785"),
    		new Address("dykes rd","104", "Boston", "MA", "24785"),
    		new Address("dykes rd","104", "Orlando", "FL", "24783"),
    	};
    	Arrays.sort(addressArray, ORDER_BY_RULES);
    	//Print the sorted array
    	for(int i=0; i<addressArray.length; i++){
    		System.out.println(addressArray[i].toString());
    	}
    	System.out.println();
    }
    }
    
    //Address Class
    class Address {
    	String streetName;
    	String streetNumber;
    	String city;
    	String state;
    	String zipCode;
    	@Override
    	public String toString() {
    		return "Address [" + streetName + " | " + streetNumber + " | " +
    			city + " | " + state + " | " + zipCode + "]";
    	}
    	public Address(String streetName, String streetNumber,
    				String city, String state, String zipCode) {
    		super();
    		this.streetName = streetName;
    		this.streetNumber = streetNumber;
    		this.city = city;
    		this.state = state;
    		this.zipCode = zipCode;
    	}
    }

    Results – sorted by street name, street number and city

    Address [break rd | 102 | Sunrise | FL | 33224]
    Address [dykes rd | 104 | Boston | MA | 24785]
    Address [dykes rd | 104 | Orlando | FL | 24783]
    Address [dykes rd | 104 | San Antonio | TX | 24785
    Address [univ dr | 101 | Sunshine | FL | 33324]
    Address [univ dr | 103 | Cleveland | OH | 24785]
    Share
    Categories: Tech Tips Tags: