aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2019-05-27 10:32:44 +0200
committerJulien Gouesse <[email protected]>2019-05-27 10:32:44 +0200
commitb196bb08ad2a880e14bd12bc342ba579e0935dbe (patch)
treecdde0ca984965f8c22bec3b13a957ec1647c4f91
parent7cdd22da5f1388f595c2207603f80854f9d471db (diff)
Replaces Guava's enum multisets by Java EnumMap (issue #13)
-rw-r--r--ardor3d-awt/src/main/java/com/ardor3d/input/awt/AwtMouseWrapper.java17
-rw-r--r--ardor3d-core/src/main/java/com/ardor3d/input/MouseState.java35
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java17
-rw-r--r--ardor3d-swt/src/main/java/com/ardor3d/input/swt/SwtMouseWrapper.java17
4 files changed, 40 insertions, 46 deletions
diff --git a/ardor3d-awt/src/main/java/com/ardor3d/input/awt/AwtMouseWrapper.java b/ardor3d-awt/src/main/java/com/ardor3d/input/awt/AwtMouseWrapper.java
index 667a932..2cc613c 100644
--- a/ardor3d-awt/src/main/java/com/ardor3d/input/awt/AwtMouseWrapper.java
+++ b/ardor3d-awt/src/main/java/com/ardor3d/input/awt/AwtMouseWrapper.java
@@ -29,8 +29,6 @@ import com.ardor3d.input.MouseManager;
import com.ardor3d.input.MouseState;
import com.ardor3d.input.MouseWrapper;
import com.ardor3d.util.PeekingIterator;
-import com.google.common.collect.EnumMultiset;
-import com.google.common.collect.Multiset;
/**
* Mouse wrapper class for use with AWT.
@@ -49,7 +47,7 @@ public class AwtMouseWrapper implements MouseWrapper, MouseListener, MouseWheelL
protected final Frame _frame;
protected final MouseManager _manager;
- protected final Multiset<MouseButton> _clicks = EnumMultiset.create(MouseButton.class);
+ protected final EnumMap<MouseButton, Integer> _clicks = new EnumMap<>(MouseButton.class);
protected final EnumMap<MouseButton, Long> _lastClickTime = new EnumMap<>(MouseButton.class);
protected final EnumSet<MouseButton> _clickArmed = EnumSet.noneOf(MouseButton.class);
@@ -91,7 +89,7 @@ public class AwtMouseWrapper implements MouseWrapper, MouseListener, MouseWheelL
if (!_clicks.isEmpty()) {
for (final MouseButton mb : MouseButton.values()) {
if (System.currentTimeMillis() - _lastClickTime.get(mb) > MouseState.CLICK_TIME_MS) {
- _clicks.setCount(mb, 0);
+ _clicks.remove(mb);
}
}
}
@@ -101,7 +99,7 @@ public class AwtMouseWrapper implements MouseWrapper, MouseListener, MouseWheelL
public synchronized void mousePressed(final MouseEvent e) {
final MouseButton b = getButtonForEvent(e);
if (_clickArmed.contains(b)) {
- _clicks.setCount(b, 0);
+ _clicks.remove(b);
}
_clickArmed.add(b);
_lastClickTime.put(b, System.currentTimeMillis());
@@ -132,11 +130,12 @@ public class AwtMouseWrapper implements MouseWrapper, MouseListener, MouseWheelL
final MouseButton b = getButtonForEvent(e);
if (_clickArmed.contains(b)
&& (System.currentTimeMillis() - _lastClickTime.get(b) <= MouseState.CLICK_TIME_MS)) {
- _clicks.add(b); // increment count of clicks for button b.
+ _clicks.merge(b, Integer.valueOf(1), (final Integer oldValue, final Integer value) -> Integer
+ .valueOf(oldValue.intValue() + value.intValue())); // increment count of clicks for button b.
// XXX: Note the double event add... this prevents sticky click counts, but is it the best way?
- addNewState(e, buttons, EnumMultiset.create(_clicks));
+ addNewState(e, buttons, new EnumMap<>(_clicks));
} else {
- _clicks.setCount(b, 0); // clear click count for button b.
+ _clicks.remove(b); // clear click count for button b.
}
_clickArmed.remove(b);
@@ -223,7 +222,7 @@ public class AwtMouseWrapper implements MouseWrapper, MouseListener, MouseWheelL
}
private void addNewState(final MouseEvent mouseEvent, final EnumMap<MouseButton, ButtonState> enumMap,
- final Multiset<MouseButton> clicks) {
+ final EnumMap<MouseButton, Integer> clicks) {
final MouseState newState = new MouseState(mouseEvent.getX(), getArdor3DY(mouseEvent), getDX(mouseEvent),
getDY(mouseEvent),
(mouseEvent instanceof MouseWheelEvent ? ((MouseWheelEvent) mouseEvent).getWheelRotation() : 0),
diff --git a/ardor3d-core/src/main/java/com/ardor3d/input/MouseState.java b/ardor3d-core/src/main/java/com/ardor3d/input/MouseState.java
index 398810e..e6c90eb 100644
--- a/ardor3d-core/src/main/java/com/ardor3d/input/MouseState.java
+++ b/ardor3d-core/src/main/java/com/ardor3d/input/MouseState.java
@@ -16,10 +16,6 @@ import java.util.EnumSet;
import java.util.Map;
import com.ardor3d.annotation.Immutable;
-import com.google.common.collect.EnumMultiset;
-import com.google.common.collect.ImmutableMultiset;
-import com.google.common.collect.ImmutableMultiset.Builder;
-import com.google.common.collect.Multiset;
/**
* Describes the mouse state at some point in time.
@@ -35,7 +31,7 @@ public class MouseState {
private final int _dy;
private final int _dwheel;
private final Map<MouseButton, ButtonState> _buttonStates;
- private final ImmutableMultiset<MouseButton> _clickCounts;
+ private final EnumMap<MouseButton, Integer> _clickCounts;
/**
* Constructs a new MouseState instance.
@@ -56,7 +52,7 @@ public class MouseState {
* the number of times each button has been clicked
*/
public MouseState(final int x, final int y, final int dx, final int dy, final int dwheel,
- final EnumMap<MouseButton, ButtonState> buttonStates, final Multiset<MouseButton> clicks) {
+ final EnumMap<MouseButton, ButtonState> buttonStates, final EnumMap<MouseButton, Integer> clicks) {
_x = x;
_y = y;
_dx = dx;
@@ -68,10 +64,9 @@ public class MouseState {
_buttonStates = Collections.emptyMap();
}
if (clicks != null) {
- final Builder<MouseButton> builder = ImmutableMultiset.builder();
- _clickCounts = builder.addAll(clicks).build();
+ _clickCounts = new EnumMap<>(clicks);
} else {
- _clickCounts = ImmutableMultiset.of();
+ _clickCounts = new EnumMap<>(MouseButton.class);
}
}
@@ -191,25 +186,27 @@ public class MouseState {
*
* @return a defensive copy of the click counts of all the buttons at this point in time.
*/
- public Multiset<MouseButton> getClickCounts() {
+ public EnumMap<MouseButton, Integer> getClickCounts() {
if (_clickCounts.isEmpty()) {
- return EnumMultiset.create(MouseButton.class);
+ return new EnumMap<>(MouseButton.class);
} else {
- return EnumMultiset.create(_clickCounts);
+ return new EnumMap<>(_clickCounts);
}
}
- public Multiset<MouseButton> getClickCounts(final EnumMultiset<MouseButton> store) {
- final EnumMultiset<MouseButton> rVal = store;
+ public EnumMap<MouseButton, Integer> getClickCounts(final EnumMap<MouseButton, Integer> store) {
+ final EnumMap<MouseButton, Integer> rVal;
if (store == null) {
if (_clickCounts.isEmpty()) {
- return EnumMultiset.create(MouseButton.class);
+ rVal = new EnumMap<>(MouseButton.class);
} else {
- return EnumMultiset.create(_clickCounts);
+ rVal = new EnumMap<>(_clickCounts);
}
+ } else {
+ rVal = store;
+ rVal.clear();
+ rVal.putAll(_clickCounts);
}
- rVal.clear();
- rVal.addAll(_clickCounts);
return rVal;
}
@@ -235,7 +232,7 @@ public class MouseState {
* @return the click count in this frame
*/
public int getClickCount(final MouseButton button) {
- return _clickCounts.count(button);
+ return _clickCounts.getOrDefault(button, Integer.valueOf(0));
}
/**
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java
index c4e3e1a..aec76bd 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java
@@ -23,8 +23,6 @@ import com.ardor3d.input.MouseManager;
import com.ardor3d.input.MouseState;
import com.ardor3d.input.MouseWrapper;
import com.ardor3d.util.PeekingIterator;
-import com.google.common.collect.EnumMultiset;
-import com.google.common.collect.Multiset;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.MouseListener;
import com.jogamp.newt.event.NEWTEvent;
@@ -46,7 +44,7 @@ public class JoglNewtMouseWrapper implements MouseWrapper, MouseListener {
protected boolean _skipAutoRepeatEvents = false;
- protected final Multiset<MouseButton> _clicks = EnumMultiset.create(MouseButton.class);
+ protected final EnumMap<MouseButton, Integer> _clicks = new EnumMap<>(MouseButton.class);
protected final EnumMap<MouseButton, Long> _lastClickTime = new EnumMap<>(MouseButton.class);
protected final EnumSet<MouseButton> _clickArmed = EnumSet.noneOf(MouseButton.class);
@@ -81,7 +79,7 @@ public class JoglNewtMouseWrapper implements MouseWrapper, MouseListener {
if (!_clicks.isEmpty()) {
for (final MouseButton mb : MouseButton.values()) {
if (System.currentTimeMillis() - _lastClickTime.get(mb) > MouseState.CLICK_TIME_MS) {
- _clicks.setCount(mb, 0);
+ _clicks.remove(mb);
}
}
}
@@ -92,7 +90,7 @@ public class JoglNewtMouseWrapper implements MouseWrapper, MouseListener {
if (!_skipAutoRepeatEvents || !me.isAutoRepeat()) {
final MouseButton b = getButtonForEvent(me);
if (_clickArmed.contains(b)) {
- _clicks.setCount(b, 0);
+ _clicks.remove(b);
}
_clickArmed.add(b);
_lastClickTime.put(b, System.currentTimeMillis());
@@ -125,11 +123,12 @@ public class JoglNewtMouseWrapper implements MouseWrapper, MouseListener {
final MouseButton b = getButtonForEvent(me);
if (_clickArmed.contains(b)
&& (System.currentTimeMillis() - _lastClickTime.get(b) <= MouseState.CLICK_TIME_MS)) {
- _clicks.add(b); // increment count of clicks for button b.
+ _clicks.merge(b, Integer.valueOf(1), (final Integer oldValue, final Integer value) -> Integer
+ .valueOf(oldValue.intValue() + value.intValue())); // increment count of clicks for button b.
// XXX: Note the double event add... this prevents sticky click counts, but is it the best way?
- addNewState(me, buttons, EnumMultiset.create(_clicks));
+ addNewState(me, buttons, new EnumMap<>(_clicks));
} else {
- _clicks.setCount(b, 0); // clear click count for button b.
+ _clicks.remove(b); // clear click count for button b.
}
_clickArmed.remove(b);
@@ -216,7 +215,7 @@ public class JoglNewtMouseWrapper implements MouseWrapper, MouseListener {
}
private void addNewState(final MouseEvent mouseEvent, final EnumMap<MouseButton, ButtonState> enumMap,
- final Multiset<MouseButton> clicks) {
+ final EnumMap<MouseButton, Integer> clicks) {
final MouseState newState = new MouseState(mouseEvent.getX(), getArdor3DY(mouseEvent), getDX(mouseEvent),
getDY(mouseEvent),
(int) (mouseEvent.isShiftDown() ? mouseEvent.getRotation()[0] : mouseEvent.getRotation()[1]), enumMap,
diff --git a/ardor3d-swt/src/main/java/com/ardor3d/input/swt/SwtMouseWrapper.java b/ardor3d-swt/src/main/java/com/ardor3d/input/swt/SwtMouseWrapper.java
index f44f309..5b505e3 100644
--- a/ardor3d-swt/src/main/java/com/ardor3d/input/swt/SwtMouseWrapper.java
+++ b/ardor3d-swt/src/main/java/com/ardor3d/input/swt/SwtMouseWrapper.java
@@ -27,8 +27,6 @@ import com.ardor3d.input.MouseButton;
import com.ardor3d.input.MouseState;
import com.ardor3d.input.MouseWrapper;
import com.ardor3d.util.PeekingIterator;
-import com.google.common.collect.EnumMultiset;
-import com.google.common.collect.Multiset;
/**
* A mouse wrapper for use with SWT.
@@ -43,7 +41,7 @@ public class SwtMouseWrapper implements MouseWrapper, MouseListener, MouseMoveLi
@GuardedBy("this")
private MouseState _lastState = null;
- private final Multiset<MouseButton> _clicks = EnumMultiset.create(MouseButton.class);
+ private final EnumMap<MouseButton, Integer> _clicks = new EnumMap<>(MouseButton.class);
private final EnumMap<MouseButton, Long> _lastClickTime = new EnumMap<>(MouseButton.class);
private final EnumSet<MouseButton> _clickArmed = EnumSet.noneOf(MouseButton.class);
@@ -76,7 +74,7 @@ public class SwtMouseWrapper implements MouseWrapper, MouseListener, MouseMoveLi
if (!_clicks.isEmpty()) {
for (final MouseButton mb : MouseButton.values()) {
if (System.currentTimeMillis() - _lastClickTime.get(mb) > MouseState.CLICK_TIME_MS) {
- _clicks.setCount(mb, 0);
+ _clicks.remove(mb);
}
}
}
@@ -91,7 +89,7 @@ public class SwtMouseWrapper implements MouseWrapper, MouseListener, MouseMoveLi
public synchronized void mouseDown(final MouseEvent e) {
final MouseButton b = getButtonForEvent(e);
if (_clickArmed.contains(b)) {
- _clicks.setCount(b, 0);
+ _clicks.remove(b);
}
_clickArmed.add(b);
_lastClickTime.put(b, System.currentTimeMillis());
@@ -116,11 +114,12 @@ public class SwtMouseWrapper implements MouseWrapper, MouseListener, MouseMoveLi
final MouseButton b = getButtonForEvent(e);
if (_clickArmed.contains(b)
&& (System.currentTimeMillis() - _lastClickTime.get(b) <= MouseState.CLICK_TIME_MS)) {
- _clicks.add(b); // increment count of clicks for button b.
+ _clicks.merge(b, Integer.valueOf(1), (final Integer oldValue, final Integer value) -> Integer
+ .valueOf(oldValue.intValue() + value.intValue())); // increment count of clicks for button b.
// XXX: Note the double event add... this prevents sticky click counts, but is it the best way?
- addNewState(e, 0, buttons, EnumMultiset.create(_clicks));
+ addNewState(e, 0, buttons, new EnumMap<>(_clicks));
} else {
- _clicks.setCount(b, 0); // clear click count for button b.
+ _clicks.remove(b); // clear click count for button b.
}
_clickArmed.remove(b);
@@ -212,7 +211,7 @@ public class SwtMouseWrapper implements MouseWrapper, MouseListener, MouseMoveLi
}
private void addNewState(final MouseEvent mouseEvent, final int wheelDX,
- final EnumMap<MouseButton, ButtonState> buttons, final Multiset<MouseButton> clicks) {
+ final EnumMap<MouseButton, ButtonState> buttons, final EnumMap<MouseButton, Integer> clicks) {
final MouseState newState = new MouseState(mouseEvent.x, getArdor3DY(mouseEvent), getDX(mouseEvent),
getDY(mouseEvent), wheelDX, buttons, clicks);