Commonclipse插件的使用

Commonclipse 是 eclipse的一个插件.它可以自动生成下面的方法:
  • toString()
  • hashcode()
  • equals(Object)
  • compareTo(Object)
项目网址:http://commonclipse.sourceforge.net/index.html
 
自动生成的这些方法是基于Apache Common Lang项目。所以有必要看一下Apache Common Lang的相关源码。
 
特别是对JavaBean与对应的Struts Form有比较大的作用.快速准确.

如何安装:
方法一:
In eclipse 3 select "Help" -> "Software updates" -> "Find and Install" -> "Search for new features to install".
Click "add update site" and insert the commonclipse update site URL: http://commonclipse.sourceforge.net
方法二:

You can download Commonclipse from the SourceForge Server(http://sourceforge.net/projects/commonclipse/files/) . The zipped file includes both binaries and sources.

Unzip the downloaded zip file in your eclipse/plugins folder.

 

使用方法:

自动生成的一些代码如下:

toString()


public String toString() {
return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE)
.appendSuper(super.toString())
.append("age", this.age)
.append("isSmoker", this.isSmoker)
.append("name", this.name)
.toString();
}

hashCode()


public int hashCode() {
return new HashCodeBuilder(357504959, 1759723435)
.appendSuper(super.hashCode())
.append(this.age)
.append(this.isSmoker)
.append(this.name)
.toHashCode();
}

equals(Object)

 public boolean equals(Object object) {
if (!(object instanceof Person)) {
return false;
}
Person rhs = (Person) object;
return new EqualsBuilder()
.appendSuper(super.equals(object))
.append(this.age, rhs.age)
.append(this.isSmoker, rhs.isSmoker)
.append(this.name, rhs.name)
.isEquals();
}
  

compareTo(Object)


public int compareTo(Object object) {
Person myClass = (Person) object;
return new CompareToBuilder()
.append(this.age, myClass.age)
.append(this.isSmoker, myClass.isSmoker)
.append(this.name, myClass.name)
.toComparison();
}

 

你可能感兴趣的:(equals,休闲,自动生成toString,Commonclipse插件)