Archived
0

Sonar: [squid:S2975] Remove this "clone" implementation; use a copy constructor or copy factory instead

This commit is contained in:
2019-02-11 14:33:33 +03:00
parent 667ea373b8
commit d4a3a49b47
8 changed files with 14 additions and 27 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}
}