Permalink
Cannot retrieve contributors at this time
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?
HowToKB/src/kb/howtokb/clustering/basicobj/CSKCluster.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
85 lines (69 sloc)
1.89 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); | |
} | |
} |