Point3D.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.util;
  20. import java.io.Serializable;
  21. import java.util.concurrent.atomic.AtomicInteger;
  22. import com.l2jserver.gameserver.model.Location;
  23. import com.l2jserver.gameserver.model.interfaces.IPositionable;
  24. /**
  25. * @author Unknown, UnAfraid
  26. */
  27. public class Point3D implements Serializable, IPositionable
  28. {
  29. private static final long serialVersionUID = 4638345252031872576L;
  30. private final AtomicInteger _x = new AtomicInteger();
  31. private final AtomicInteger _y = new AtomicInteger();
  32. private final AtomicInteger _z = new AtomicInteger();
  33. public Point3D(int x, int y, int z)
  34. {
  35. _x.set(x);
  36. _y.set(y);
  37. _z.set(z);
  38. }
  39. public boolean equals(int x, int y, int z)
  40. {
  41. return (getX() == x) && (getY() == y) && (getZ() == z);
  42. }
  43. @Override
  44. public int getX()
  45. {
  46. return _x.get();
  47. }
  48. public void setX(int x)
  49. {
  50. _x.set(x);
  51. }
  52. @Override
  53. public int getY()
  54. {
  55. return _y.get();
  56. }
  57. public void setY(int y)
  58. {
  59. _y.set(y);
  60. }
  61. @Override
  62. public int getZ()
  63. {
  64. return _z.get();
  65. }
  66. public void setZ(int z)
  67. {
  68. _z.set(z);
  69. }
  70. public void setXYZ(int x, int y, int z)
  71. {
  72. _x.set(x);
  73. _y.set(y);
  74. _z.set(z);
  75. }
  76. @Override
  77. public Location getLocation()
  78. {
  79. return new Location(getX(), getY(), getZ());
  80. }
  81. @Override
  82. public String toString()
  83. {
  84. return "(" + _x + ", " + _y + ", " + _z + ")";
  85. }
  86. @Override
  87. public int hashCode()
  88. {
  89. return getX() ^ getY() ^ getZ();
  90. }
  91. @Override
  92. public boolean equals(Object o)
  93. {
  94. if (this == o)
  95. {
  96. return true;
  97. }
  98. if (o instanceof Point3D)
  99. {
  100. final Point3D point3D = (Point3D) o;
  101. return (point3D.getX() == getX()) && (point3D.getY() == getY()) && (point3D.getZ() == getZ());
  102. }
  103. return false;
  104. }
  105. }