Updated ParticleEngineDMapImplementation.
[desert.git] / src / org / sourceforge / desert / ParticleDefaultImplementation.java
blob6d5aa10871335e0d86215448df8e425175b949db
1 /*
2 * Copyright (c) 2010 The Desert team
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
26 package org.sourceforge.desert;
28 /**
30 * @author codistmonk (creation 2010-04-17)
32 public class ParticleDefaultImplementation implements Particle {
34 private Type type;
36 private float x;
38 private float y;
40 private float speedX;
42 private float speedY;
44 public ParticleDefaultImplementation() {
45 this(Type.values()[0], 0F, 0F, 0F, 0F);
48 /**
50 * @param type
51 * <br>Should not be null
52 * @param x
53 * <br>Should not be null
54 * <br>Range: <code>]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[</code>
55 * @param y
56 * <br>Should not be null
57 * <br>Range: <code>]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[</code>
58 * @param speedX
59 * <br>Should not be null
60 * <br>Range: <code>]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[</code>
61 * @param speedY
62 * <br>Should not be null
63 * <br>Range: <code>]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[</code>
65 public ParticleDefaultImplementation(final Type type, final float x, final float y, final float speedX, final float speedY) {
66 this.type = type;
67 this.x = x;
68 this.y = y;
69 this.speedX = speedX;
70 this.speedY = speedY;
73 @Override
74 public final float getSpeedX() {
75 return speedX;
78 /**
80 * @param speedX
81 * <br>Should not be null
82 * <br>Range: <code>]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[</code>
84 public final void setSpeedX(final float speedX) {
85 this.speedX = speedX;
88 @Override
89 public final float getSpeedY() {
90 return this.speedY;
93 /**
95 * @param speedY
96 * <br>Should not be null
97 * <br>Range: <code>]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[</code>
99 public final void setSpeedY(final float speedY) {
100 this.speedY = speedY;
103 @Override
104 public final Type getType() {
105 return this.type;
110 * @param type
111 * <br>Should not be null
113 public final void setType(final Type type) {
114 this.type = type;
117 @Override
118 public final float getX() {
119 return this.x;
124 * @param x
125 * <br>Should not be null
126 * <br>Range: <code>]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[</code>
128 public final void setX(final float x) {
129 this.x = x;
132 @Override
133 public final float getY() {
134 return this.y;
139 * @param y
140 * <br>Should not be null
141 * <br>Range: <code>]float.NEGATIVE_INFINITY .. float.POSITIVE_INFINITY[</code>
143 public final void setY(final float y) {
144 this.y = y;
147 @Override
148 public String toString() {
149 return "(" + this.getType() + ", " + this.getX() + ", " + this.getY() + ", " + this.getSpeedX() + ", " + this.getSpeedY() + ")";
152 @Override
153 public final boolean equals(final Object obj) {
154 if (obj == null) {
155 return false;
157 if (!Particle.class.isAssignableFrom(obj.getClass())) {
158 return false;
160 final Particle other = (Particle) obj;
161 if (this.getType() != other.getType() && (this.getType() == null || !this.getType().equals(other.getType()))) {
162 return false;
164 if (this.getX() != other.getX()) {
165 return false;
167 if (this.getY() != other.getY()) {
168 return false;
170 if (this.getSpeedX() != other.getSpeedX()) {
171 return false;
173 if (this.getSpeedY() != other.getSpeedY()) {
174 return false;
176 return true;
179 @Override
180 public final int hashCode() {
181 int hash = 3;
183 hash = 47 * hash + (this.type != null ? this.type.hashCode() : 0);
185 return hash;