Small changes, deferred BusAccess assignment to Bus nodes
This commit is contained in:
+1
-1
@@ -18,6 +18,6 @@ import java.lang.annotation.Target;
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(value = { ElementType.METHOD })
|
||||
public @interface DefaultImpl {
|
||||
public @interface Stub {
|
||||
//
|
||||
}
|
||||
@@ -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<Object> 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.<br>
|
||||
* 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<br>
|
||||
* Deinitialize the node (subsystem)<br>
|
||||
* (called during destruction)
|
||||
*/
|
||||
@DefaultImpl
|
||||
@Stub
|
||||
protected void deinit()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user