Tuesday, September 21, 2010

Install Skype under OpenSuse 11.x

If you have installed Skype and it crashes while starting you maybe have an old version of Skype. Here are steps to install Skype on Linux:

1) Delete currently installed Skype
zypper rm skype

2) Delete hidden file .skype in the user home directory.

3) Make sure you have installed libpng12-0 package. Install it by YaST if needed.

4) Grab the current Skype version from http://www.skype.com/intl/en/get-skype/on-your-computer/linux/ and install it. You can also install it directly, e.g.
rpm -Uvh http://download.skype.com/linux/skype-2.1.0.81-suse.i586.rpm

WLAN with Dell notebook and OpenSuse 11.x

Dell notebooks are normally equipped with Broadcom card for WLAN. All 802.11n Broadcom devices need to use the Broadcom STA driver. You need to accomplish the following steps to install such drivers:

1) Download current drivers from http://packman.links2linux.de/package/broadcom-wl. You need two drivers. In my case
broadcom-wl-5.60.48.36-7.pm.8.5.i586.rpm
broadcom-wl-kmp-default-5.60.48.36_k2.6.34.7_0.2-7.pm.8.5.i586.rpm

2) Open Linux terminal and go to the directory where you downloaded these drivers. Let run two commandos one after another
rpm -ivh broadcom-wl-kmp-default-5.60.48.36_k2.6.34.7_0.2-7.pm.8.5.i586.rpm
rpm -ivh broadcom-wl-5.60.48.36-7.pm.8.5.i586.rpm --force

3) Reboot your PC. If you still don't have a WLAN connection go to the YaST and configure WLAN in network devices. You should see at least your drivers.

Assists in creating consistent equals(), hashCode(), toString()

I often see many different implementations for methods equals(), hashCode() and toString(). There is a good and simple approach in Apache Commons Lang which I always use for this purpose. Classes EqualsBuilder, HashCodeBuilder and ToStringBuilder from the package org.apache.commons.lang.builder provide methods to build consistent and good equals() hashCode() and toString() methods of any class.
We can use either Java reflection or call successive append method for our purpose. Assume we have the following Java class:
public class MyClass {
    private String name;
    private int count;
    private List keys;
    ...
}
1) Use Java reflection:
@Override
public boolean equals(final Object obj)
{
    return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
public int hashCode()
{
    return HashCodeBuilder.reflectionHashCode(this);
}

@Override
public String toString()
{
    return ToStringBuilder.reflectionToString(this);
}
2) Include fields manually:
@Override
public boolean equals(final Object obj)
{
    if (obj == null) {
        return false;
    }

    if (obj == this) {
        return true;
    }

    if (obj.getClass() != getClass()) {
        return false;
    }

    MyClass mc = (MyClass) mc;

    return new EqualsBuilder().append(name, mc.name).append(count, mc.count).append(keys, mc.keys).isEquals();
}

@Override
public int hashCode()
{
    return new HashCodeBuilder(17, 37).append(name).append(count).append(keys).toHashCode();
}

@Override
public String toString()
{
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).
                               append("name", name).append("count", count).append("keys", keys).toString();
}
In the second case we have more control and can decide which fields we want to compare and which not. And don't care about data types. They can be primitive, Collection, Map or something else.