Skip to content

Commit

Permalink
Make MagicKey completely immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
anistor authored and Mircea Markus committed May 30, 2013
1 parent d42cc0f commit 6bb8002
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions core/src/test/java/org/infinispan/distribution/MagicKey.java
Expand Up @@ -44,12 +44,17 @@ public class MagicKey implements Serializable {
* The serialVersionUID
*/
private static final long serialVersionUID = -835275755945753954L;
String name = null;
int hashcode;
int segment;
String address;

public MagicKey(Cache<?, ?> primaryOwner) {
/**
* The name is used only for easier debugging and may be null. It is not part of equals()/hashCode().
*/
private final String name;
private final int hashcode;
private final int segment;
private final String address;

public MagicKey(String name, Cache<?, ?> primaryOwner) {
this.name = name;
address = addressOf(primaryOwner).toString();
Random r = new Random();
Object dummy;
Expand All @@ -65,7 +70,8 @@ public MagicKey(Cache<?, ?> primaryOwner) {
segment = primaryOwner.getAdvancedCache().getDistributionManager().getReadConsistentHash().getSegment(this);
}

public MagicKey(Cache<?, ?> primaryOwner, Cache<?, ?>... backupOwners) {
public MagicKey(String name, Cache<?, ?> primaryOwner, Cache<?, ?>... backupOwners) {
this.name = name;
address = addressOf(primaryOwner).toString();
Random r = new Random();
Object dummy;
Expand All @@ -87,14 +93,12 @@ public MagicKey(Cache<?, ?> primaryOwner, Cache<?, ?>... backupOwners) {
segment = primaryOwner.getAdvancedCache().getDistributionManager().getReadConsistentHash().getSegment(this);
}

public MagicKey(String name, Cache<?, ?> primaryOwner) {
this(primaryOwner);
this.name = name;
public MagicKey(Cache<?, ?> primaryOwner) {
this(null, primaryOwner);
}

public MagicKey(String name, Cache<?, ?> primaryOwner, Cache<?, ?>... backupOwners) {
this(primaryOwner, backupOwners);
this.name = name;
public MagicKey(Cache<?, ?> primaryOwner, Cache<?, ?>... backupOwners) {
this(null, primaryOwner, backupOwners);
}

@Override
Expand All @@ -109,10 +113,7 @@ public boolean equals (Object o) {

MagicKey magicKey = (MagicKey) o;

if (hashcode != magicKey.hashcode) return false;
if (address != null ? !address.equals(magicKey.address) : magicKey.address != null) return false;

return true;
return hashcode == magicKey.hashcode && address.equals(magicKey.address);
}

@Override
Expand Down

0 comments on commit 6bb8002

Please sign in to comment.