Sonar: [squid:S2975] Remove this "clone" implementation; use a copy constructor or copy factory instead
This commit is contained in:
@@ -10,7 +10,7 @@ import mc.core.world.block.BlockLocation;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class EntityLocation implements Cloneable {
|
||||
public class EntityLocation {
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
|
||||
@@ -50,13 +50,7 @@ public class EntityLocation implements Cloneable {
|
||||
return new BlockLocation(getBlockX(), getBlockY(), getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityLocation clone() {
|
||||
try {
|
||||
return (EntityLocation) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
log.error("", e);
|
||||
return ZERO();
|
||||
}
|
||||
public EntityLocation copy() {
|
||||
return new EntityLocation(x, y, z, yaw, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class BlockLocation implements Cloneable {
|
||||
public class BlockLocation {
|
||||
private int x, y, z;
|
||||
|
||||
public static BlockLocation ZERO() {
|
||||
@@ -22,13 +22,7 @@ public class BlockLocation implements Cloneable {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockLocation clone() {
|
||||
try {
|
||||
return (BlockLocation) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
log.error("", e);
|
||||
return ZERO();
|
||||
}
|
||||
public BlockLocation copy() {
|
||||
return new BlockLocation(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class EntityLocationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void clone_() {
|
||||
void copy() {
|
||||
EntityLocation locOrig = new EntityLocation(x, y, z, yaw, pitch);
|
||||
EntityLocation locClone = locOrig.clone();
|
||||
EntityLocation locClone = locOrig.copy();
|
||||
assertEquals(locOrig, locClone);
|
||||
assertNotSame(locOrig, locClone);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class ImmutableEntityLocationTest {
|
||||
@Test
|
||||
void clone_() {
|
||||
EntityLocation locOrig = new ImmutableEntityLocation(1d, 2d, 3d, 4f, 5f);
|
||||
EntityLocation locClone = locOrig.clone();
|
||||
EntityLocation locClone = locOrig.copy();
|
||||
|
||||
assertEquals(locOrig, locClone);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ class BlockLocationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void clone_() {
|
||||
void copy() {
|
||||
BlockLocation locOrig = new BlockLocation(x, y, z);
|
||||
BlockLocation locClone = locOrig.clone();
|
||||
BlockLocation locClone = locOrig.copy();
|
||||
assertEquals(locOrig, locClone);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user