diff --git a/src/mightypork/utils/annotations/DefaultImpl.java b/src/mightypork/utils/annotations/Stub.java similarity index 94% rename from src/mightypork/utils/annotations/DefaultImpl.java rename to src/mightypork/utils/annotations/Stub.java index c5e574c..6e9d7a2 100644 --- a/src/mightypork/utils/annotations/DefaultImpl.java +++ b/src/mightypork/utils/annotations/Stub.java @@ -18,6 +18,6 @@ import java.lang.annotation.Target; @Documented @Retention(RetentionPolicy.SOURCE) @Target(value = { ElementType.METHOD }) -public @interface DefaultImpl { +public @interface Stub { // } diff --git a/src/mightypork/utils/eventbus/clients/BusNode.java b/src/mightypork/utils/eventbus/clients/BusNode.java index 02884a7..44b7bdf 100644 --- a/src/mightypork/utils/eventbus/clients/BusNode.java +++ b/src/mightypork/utils/eventbus/clients/BusNode.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.LinkedHashSet; import java.util.Set; +import mightypork.utils.annotations.Stub; import mightypork.utils.eventbus.BusAccess; import mightypork.utils.eventbus.EventBus; @@ -17,7 +18,7 @@ import mightypork.utils.eventbus.EventBus; */ public abstract class BusNode implements BusAccess, ClientHub { - private final BusAccess busAccess; + private BusAccess busAccess; private final Set clients = new LinkedHashSet<>(); private boolean listening = true; @@ -27,9 +28,43 @@ public abstract class BusNode implements BusAccess, ClientHub { /** * @param busAccess access to bus */ - public BusNode(BusAccess busAccess) + public BusNode(BusAccess busAccess) { + setBusAccess(busAccess); + } + + + /** + * Create without a bus access. Bus access should be set using the + * setBusAccess() method. + */ + public BusNode() { + } + + + /** + * Handler called when bus access first provides a valid bus instance.
+ * The node may now eg. subscribe to the bus. + */ + @Stub + public void onBusReady() + { + // do stuff + } + + + /** + * Assign a bus access. If the buss access provides a buss, the onBusReady() + * method will be called. + * + * @param busAccess the assigned bus access + */ + public final void setBusAccess(BusAccess busAccess) { this.busAccess = busAccess; + + if (getEventBus() != null) { + onBusReady(); + } } @@ -109,6 +144,7 @@ public abstract class BusNode implements BusAccess, ClientHub { @Override public EventBus getEventBus() { + if(busAccess==null) return null; return busAccess.getEventBus(); } diff --git a/src/mightypork/utils/eventbus/clients/RootBusNode.java b/src/mightypork/utils/eventbus/clients/RootBusNode.java index 39849e2..bc11f6c 100644 --- a/src/mightypork/utils/eventbus/clients/RootBusNode.java +++ b/src/mightypork/utils/eventbus/clients/RootBusNode.java @@ -1,7 +1,7 @@ package mightypork.utils.eventbus.clients; -import mightypork.utils.annotations.DefaultImpl; +import mightypork.utils.annotations.Stub; import mightypork.utils.eventbus.BusAccess; import mightypork.utils.interfaces.Destroyable; @@ -14,12 +14,25 @@ import mightypork.utils.interfaces.Destroyable; public abstract class RootBusNode extends BusNode implements Destroyable { /** + * Create with a bus access. + * * @param busAccess access to bus */ - public RootBusNode(BusAccess busAccess) - { + public RootBusNode(BusAccess busAccess) { super(busAccess); - + } + + + /** + * Create without a bus access. It should be assigned later. + */ + public RootBusNode() { + } + + + @Override + public void onBusReady() + { getEventBus().subscribe(this); } @@ -29,15 +42,17 @@ public abstract class RootBusNode extends BusNode implements Destroyable { { deinit(); - getEventBus().unsubscribe(this); + if (getEventBus() != null) { + getEventBus().unsubscribe(this); + } } /** - * Deinitialize the subsystem
+ * Deinitialize the node (subsystem)
* (called during destruction) */ - @DefaultImpl + @Stub protected void deinit() { } diff --git a/src/mightypork/utils/math/animation/Animator.java b/src/mightypork/utils/math/animation/Animator.java index fe4e6f6..66921ee 100644 --- a/src/mightypork/utils/math/animation/Animator.java +++ b/src/mightypork/utils/math/animation/Animator.java @@ -1,7 +1,7 @@ package mightypork.utils.math.animation; -import mightypork.utils.annotations.DefaultImpl; +import mightypork.utils.annotations.Stub; import mightypork.utils.interfaces.Pauseable; import mightypork.utils.interfaces.Updateable; import mightypork.utils.math.Calc; @@ -120,7 +120,7 @@ public abstract class Animator implements NumBound, Updateable, Pauseable { } - @DefaultImpl + @Stub protected abstract void nextCycle(NumAnimated anim); diff --git a/src/mightypork/utils/math/color/Color.java b/src/mightypork/utils/math/color/Color.java index 5529e8a..c848904 100644 --- a/src/mightypork/utils/math/color/Color.java +++ b/src/mightypork/utils/math/color/Color.java @@ -244,4 +244,37 @@ public abstract class Color { { return new ColorAlphaAdjuster(this, multiplier); } + + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(b()); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(g()); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(r()); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(a()); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + + @Override + public boolean equals(Object obj) + { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof Color)) return false; + Color other = (Color) obj; + if (Double.doubleToLongBits(b()) != Double.doubleToLongBits(other.b())) return false; + if (Double.doubleToLongBits(g()) != Double.doubleToLongBits(other.g())) return false; + if (Double.doubleToLongBits(r()) != Double.doubleToLongBits(other.r())) return false; + if (Double.doubleToLongBits(a()) != Double.doubleToLongBits(other.a())) return false; + return true; + } }