How to use Comparator to Sort List

This tutorial demonstrated how to use comparator to sort Collection, for this example the ArrayList of List.

Now, I used the java.util.Collections static utility method, Collections.sort() method to sort the List, how I sort the list? I first sort the list in alphabetically, and otherwise I am using a user-defined comparator to sort in reverse order. Here is my code:

import java.util.*;

public class SortSort {

    public static void main(String args[]) {
        List<String> name = new ArrayList<String>();
        name.add("Mohan");
        name.add("Ali");
        name.add("Hao");
        name.add("Some");
        System.out.println("Before: " + name);
        Collections.sort(name);
        System.out.println("After Sort: " + name);
        Collections.sort(name, new reverseOrder());
        System.out.println("After Reverse Sort:  " + name);
    }
}

class reverseOrder implements Comparator<String> {
    public int compare(String one, String two) {
        return two.compareTo(one);
    }
}

image

Java Set and List Simple Operation

I have made some operation on Set and List in Java, using addAll, removeAll, retainAll functionality. These functionality act like the mathematical set functions.

Now I proceed with the Java coding, you all can learn from here. Below the code will be the DOS-based output.

import java.util.*;

class Test8 {
    public static void main(String args[]) {
        Set setA = new HashSet();
        setA.add(1);
        setA.add(2);
        setA.add(3);
        setA.add(4);

        Set setB = new HashSet();
        setB.add(2);
        setB.add(4);
        setB.add(6);
        setB.add(8);

        System.out.println("Set A: " + setA);
        System.out.println("Set B: " + setB);

        Set addAllSet = new HashSet(setA);
        addAllSet.addAll(setB);
        System.out.println("Add All Operation: " + addAllSet);

        Set removeAllSet = new HashSet(setA);
        removeAllSet.removeAll(setB);
        System.out.println("Remove All Operation: " + removeAllSet);

        Set retainAllSet = new HashSet(setA);
        retainAllSet.retainAll(setB);
        System.out.println("Retain All Operation: " + retainAllSet);

        System.out.println("—————————–");

        List listA = new ArrayList();
        listA.add(1);
        listA.add(2);
        listA.add(3);
        listA.add(4);

        List listB = new ArrayList();
        listB.add(2);
        listB.add(4);
        listB.add(6);
        listB.add(8);

        System.out.println("List A: " + listA);
        System.out.println("List B: " + listB);

        List addAllList = new ArrayList(listA);
        addAllList.addAll(listB);
        System.out.println("Add All Operation: " + addAllList);

        List removeAllList = new ArrayList(listA);
        removeAllList.removeAll(listB);
        System.out.println("Remove All Operation: " + removeAllList);

        List retainAllList = new ArrayList(listA);
        retainAllList.retainAll(listB);
        System.out.println("Retain All Operation: " + retainAllList);
    }
}

image

Please note that, Set is unordered, and having unique elements, meant non-duplicate. List is ordered, and having redundant elements, meant duplicate is allowed.

六度分隔的意义

原文转贴:http://www.facebook.com/home.php#/topic.php?uid=9530063115&topic=6563

有一个数学领域的猜想,名为Six Degrees of Separation,中文翻译有以下几种: 六度分割理论,六度空间理论以及小世界理论等。 上世纪60年代,由美国哈佛大学的社会心理学家米尔格伦提出。简单来说,“六度分割”就是在这个社会里,任何两个人之间建立一种联系,最多需要六个人(包括这两个人在内),无论这两个人是否认识,生活在地球上任何偏僻的地方,他们之间只有六度分割.
这种理论貌似比较荒诞,但是细细一想,也挺有道理。这快一年来,我跑了土地局,房产局,规划局,建设局,开发办,人防,消防,公安局,白蚁防治站,气象局,设计院,图审,城管,水厂,电厂,交通局,税务局,财政局等等总共我都不记得跑了多少部门了,从几乎谁都不认识摸不到门的小姑娘到现在开着车在路上跑基本上要停下来跟朋友打招呼,我结识了一帮大龄好朋友,他们中有许多都是忘年交。这些人既好心又仗义,他们大多数为了我牺牲了自己宝贵的时间,付出了金钱,动用了自己在社会上的关系网全力的帮助我.我特别要感谢我的舅舅和他的一家人,还有陈哥哥,朱总,杨总,张叔叔还有我的好朋友赵泉和魏鹃小两口。
老杨是我见过最热心的一个人,他有一大堆光荣的头衔:什么人大代表,政协委员,青年企业家等等,他给了我不少在公司经营过程中的宝贵意见,我有什么难处只要通过老杨的引见,就能和湖北省,武汉市的高层领导人建立联系,中间肯定不需要4个人;只要认识LQC,我就能和区里边的高层领导都认识,中间不超过3人:只要找到老江,那么我就可以跟全区的中层干部任何一个人在饭局中相会,中间也不超过3个人,只要认识陈哥哥,(那是我最爱找他麻烦的一个老好人)那么全区的基层工作人员基本上都可以在我的视野范围之中, 我认识骆哥, 因此全区的黑道想找我的麻烦都可以找他出面.只要认识米晓彬或者和风,我和北京的IT愤青们,全国各大网站的编辑都能说上几句话, 而只要通过我的朋友L我和总书记甚至就只有三步之遥。
天哪,这世界真是太小了。这个六度分割理论是否真的可行呢?让我来做如下的几个测试:
1、我和比尔-盖茨建立联系
六度分割:我认识夏冰青,夏冰青曾是我妈妈的学生,后来在剑桥一直从本科读到博士毕业,后来在美国西亚图微软的总部任研发小组组长,他亲口告诉我说他常跟比尔为一个技术上面的问题,争得面红耳赤.所以,没有问题。理论成立。(3人)
2、我和胡锦涛总书记建立联系
六度分割:我认识我舅妈,我舅妈认识李贵辉,李贵辉是印泥的华侨,以前有个著名的化妆品名叫绿丹兰就是他做的.他有涛哥的手机号可以直接跟涛哥对话.因此,理论成立。(4人)
我认识林蟑螂,他说他哥哥是胡办(胡锦涛办公室)的生活秘书. 因此,理论成立.(4人)
3、我和李嘉诚建立联系
六度分割:我认识夏云,夏云是我家的亲戚,也是名记者同志,她曾采访过李嘉诚还出了本书<李嘉诚传>.因此,理论成立(3人)
4我和周星驰建立联系
六度分割:我认识杨君,杨君认识她姐姐李卉.李卉演过少林足球(那个踩香蕉皮的女孩),也曾是红极一时的星女郎,因此,理论成立(4人)
4、我和查韦斯建立联系
六度分割:我有一个北大的朋友,通过他我可以和孔庆东教授建立联系,通过孔教授我自然可以和金太阳建立联系。根据独裁者是一家的国际政治常识,我就能通过金太阳认识查月亮。因此,理论成立。(5人)
我坚信六度分割理论的真实性,所以现在有些看似复杂的问题摆在我面前,能不能解决已经不是我担心的问题了,而是在处理问题之前脑海里构思一张关系网,第一步找到谁更直接更有效的问题了。
朋友是经营人生不可或缺的资源,在现代管理中,强调高效率有一个管理层次“扁平化”的理念,薪酬也在扁平化,市场营销中也在强调渠道短化降低成本增加利润。我想这一原理也同样适用于交友吧.
通过朋友找朋友,铺上三四层个层次那样的做法,已经不太适应这个快捷变化、直白表达、利益透明的市场风格了。我正努力使六度空间,逐渐变成三度,二度,甚至是一度空间,这样过程越直接,效率越高,价值也越高

Facebook Custom Tag Flash MP3 Player

Who have been going to my forum to see the Web Programming SubForum, or even go to my script tutorial page can see how people adding the Flash MP3 Player on their page.

Now, I am announced that I have studied the Facebook Custom Tag features yesterday, and I have created my first own custom tag, which to show Flash MP3 Player on each application. Now I open it to public, that all of the Facebook Developer they can easily putting the code, to show Flash MP3 Player in their application when they need to perform something.

For who are Facebook Developer and need to implement my Flash MP3 Player can directly go to my custom tag tutorial page on Facebook. Here is the URL: http://apps.facebook.com/flashmusic/custom_tag

A Photo Strip

This is an incomplete photo strip made in Photoshop.

I not going to introduce how to do the photo strip but I will give you a link, a web site to tell you how to make the photo strip. The tutorial is very nice, and I can’t do it very well. But for my interest in the stage, I uploaded this photo as below as you can see it…

This photo strip is actually taken from the photos taken by my friend, Alvis, while I have visiting to the Mid Valley last Sunday. And the photos are under Copyleft Reserved by Alvis, so I just copy to here.

Continue reading “A Photo Strip”

Say no to IE 6 and upgrade your browser!

Save A Developer. Upgrade Your Browser.

A campaign initiated by Savethedevelopers.org and it focuses on assisting users in upgrading their Internet Explorer 6 web browser. The campaign will result in former IE 6 users having a more enjoyable experience on the web while (hopefully) creating a less stressful and complicated environment for web developers by hastening the retirement of an outdated browser.

Join The Movement

If you’d like to support the cause, you may do so by going door to door urging the inhabitants of your town to upgrade their browsers. Alternatively, you can place a call to our browser detection/upgrade recommendation script on your site to show your support:

<script src="http://www.savethedevelopers.org/say.no.to.ie.6.js"></script>

I really appreciate the campaign and I joint it! IE6 "bugs" has become a really big issue when I’m developing websites.

What do you think about the campaing?

Google wants to know which sites to search

Google is experimenting with a search feature that allows users to tailor their searches by creating a list of sites they would like to appear most in search results.

Preferred Sites will suggest frequently visited sites based on search history when it’s relevant, but users can also add and delete sites, according to the new feature’s help page:

The preferred sites feature lets you set your Google Web Search preferences so that your search results match your unique tastes and needs. Fill in the sites you rely on the most, and results from your preferred sites will show up more often when they’re relevant to your search query.

Google said that Preferred Sites could also have an impact on everyone’s searches:

If the feature goes live to everyone, people will be able to pick a list of authoritative sites and influence all search results.

Preferred Sites is an extension of Google SearchWiki, which lets people elevate, delete, add, and annotate search results. It is activated only while the user is logged in to their Google account, and users’ preferred sites and search results are private.

Steven Musil is the night news editor at CNET News. Before joining CNET News in 2000, Steven spent 10 years at various Bay Area newspapers. E-mail Steven.

Source: http://news.cnet.com/8301-17939_109-10145203-2.html

WordPress整站搬家心得(转帖)

以下文章来自:http://baibanbao.spaces.live.com/Blog/cns!6D6335E0F1D244FA!109.entry?wa=wsignin1.0&sa=26871209

 

民间说,若想一个月不肃静,搬家。Wordpress搬家这件事如果搞不好的话,会变成一件劳心劳力的大烦恼。从昨天到现在,我在12个小时之内断断续续,终于把Wordpress连同数据库一起,从一个服务器搬到了另一个虚拟主机,没有遇到江湖中盛传的乱码问题。皆因文科生阅读能力强,喜欢下力气看帖子,读文档。

先简要介绍一下技术参数。我装的WP是Wordpress2.2,两边的数据库都是MySQL4.0+,托管商提供的数据库管理界面是phpAdmin,我想大多数虚拟主机都是这样。

在搬家之前,我看了好多帖子,尝试了多种方法,都没有成功。为了节约大家时间,我就直奔主题,介绍一种最简洁有效的办法,这一办法继承了张翼轸介绍的方法,再加上自己的一点心得。

假设你有两个博客,一个a.com,一个b.com,你想把a站的全部内容连同数据库迁到b站。OK,跟我来。

1、装WP程序:首先你要确保b.com已经装上了Wordpress,数据库里有没有内容都无所谓,反正一会要被洗掉的。

2、装WP插件WP-DBManager:在a、b两个站点都装上一个Wordpress插件:WP-DBManager。注意,只有用这个插件最管用,很流行的那个数据库备份插件不好使,直接到phpAdmin倒腾,非我等菜鸟力所能及。

2.1 这里罗嗦一句,WP-DBManager安装分两步走,第一步,先把DBManager这个文件夹传到你网站的wp-content/plugins里,然后激活插件;第二步,这时用FTP登陆你的网站,看wp-content目录下,应该增加了一个子目录backup-db,把压缩包里.htaccess这个文件传到wp-content/backup-db目录里。OK。

3、备份数据库:好了,现在到a.com的管理界面,你会发现顶部的工具条里多了一项Database,这就是DBManager的功劳。点Database,出来一排菜单,点第二项"Backup DB"。 基本可以傻瓜操作,记得最后一项,GZIP Database Backup File?是问你压不压缩,默认是NO。你要选YES。要知道SQL文件压缩与不压缩大小相差四五倍。

4、管理备份的数据库:这时好奇心会驱使你看第三项菜单Manage Backup DB。你会看见,刚才备份的数据库列在一个表里,右侧是个可选的圆点小按钮。像这样:

fuxgfws.sql.gz(举例) Friday, 8th June 2007 @ 13:21 3 MB

下面什么E-mail database backup的不用去管它。注意:fuxgfws.sql.gz就是你备份下来的数据库压缩文件,它在哪儿呢?有才的你一猜就知道,在a站的wp-content/backup-db目录里。

5、FTP转数据库:FTP登陆到a.com,把wp-content/backup-db目录里的fuxgfws.sql.gz(举例)拉到本地来,然后再FTP登陆b.com,同样的把fuxgfws.sql.gz(举例)传到b站的wp-content/backup-db下。清楚吗?

6、恢复数据库:好现在进入b站的Wordpress管理界面,进入Database–>Manage Backup DB,你会看到fuxgfws.sql.gz在列表里了,点右边的圆点,选中,然后点下面四个按钮中的第二个Restore。会跳出一个警报标志,罗里罗嗦说一堆,不用管它,按确定。

7、奇迹出现了,但是……你会发现a站的内容已经顺利导入了b站,但不要高兴的太早。如果你换了域名的话,你会发现,b站所有的链接都是a站的,包括管理界面都会进入a站。这不是爱丽丝漫游奇境,原因很简单,数据库里有个重要的表内容还是a站的。没办法,我们必须用phpAdmin了。

8、根据你托管商给的登陆ID口令,找到MySQL管理按钮,最终进入phpAdmin管理界面(我的管理端是phpAdmin2.6.4,嘘,小声点,敏感词汇)。答应我,做两件事:

8.1 第一把咱们的孩子拉扯大……不胡扯了。第一,把phpAdmin的语言从默认的Chinese Simplified zh-gb2312 给我换成 Chinese Simplified zh-utf-8,达人们谆谆告诫,可以防止乱字符。听人劝,吃饱饭。

8.2 在左侧的一串辛德勒名单中找到 wp_options,点击进入,再点浏览(有时鼠标放上去才会出现"浏览"二字),不管怎么说,你要找到这个表,其中:

option_name这一列,下面一行写着 siteurl
往右 option_value这一列,下面写着一个网址,对了你会发现它就是你a站的网址,比如说:a.com

8.3 剩下的你应该会做,在这一行前面有个小钢笔的图标,那是编辑标志,点它,把a.com换成现在的b.com,保存。好了。不过距离革命成功还差一步。

9、WP管理界面修改选项。现在你发现,b.com的管理界面已经可以登陆了。进入后,找到选项,把Blog address (URL):换成b.com就行了。

蕾丝我也,下课。