Skip to content
Permalink
0d82ff1dc4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
85 lines (69 sloc) 1.89 KB
package kb.howtokb.clustering.basicobj;
import java.util.ArrayList;
import java.util.List;
public class CSKCluster<TClusterID, TClusterMember> {
protected TClusterID clusterKey;
public CSKCluster(TClusterID clusterKey) {
this.clusterKey = clusterKey;
this.clusterMembers = new ArrayList<>();
}
public CSKCluster(TClusterID id, List<TClusterMember> members){
this.clusterKey = id;
this.clusterMembers = members;
}
public TClusterID getClusterKey() {
return clusterKey;
}
protected List<TClusterMember> clusterMembers;
public List<TClusterMember> getClusterMembers() {
return clusterMembers;
}
public void setClusterMembers(List<TClusterMember> clusterMembers) {
this.clusterMembers = clusterMembers;
}
public CSKCluster<TClusterID, TClusterMember> addClusterMember(
TClusterMember clusterMember) {
clusterMembers.add(clusterMember);
return this;
}
public CSKCluster<TClusterID, TClusterMember> addClusterMemberSet(
List<TClusterMember> clusterMember) {
clusterMembers.addAll(clusterMember);
return this;
}
public CSKCluster<TClusterID, TClusterMember> removeMember(TClusterMember pt){
clusterMembers.remove(pt);
return this;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result =
prime * result + ((clusterKey == null) ? 0 : clusterKey.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CSKCluster<?, ?> other = (CSKCluster<?, ?>) obj;
if (clusterKey == null) {
if (other.clusterKey != null)
return false;
} else if (!clusterKey.equals(other.clusterKey))
return false;
return true;
}
@Override
public String toString() {
return "CSKCluster [clusterKey=" + clusterKey + "]";
}
public void clear(){
this.clusterMembers = new ArrayList<>();
}
}