org.bidib.wizard.localhost.NodeSubscriptionData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bidibwizard-localhost Show documentation
Show all versions of bidibwizard-localhost Show documentation
jBiDiB BiDiB Wizard localhost POM
package org.bidib.wizard.localhost;
import java.util.Arrays;
import java.util.function.Predicate;
import org.bidib.jbidibc.messages.enums.TargetModeEnum;
import org.bidib.jbidibc.messages.utils.ByteUtils;
import org.bidib.jbidibc.messages.utils.NodeUtils;
public final class NodeSubscriptionData implements Predicate {
private final byte[] subscriberAddress;
private final Long subscriberUniqueId;
private final TargetModeEnum targetMode;
private final Integer subscription;
public NodeSubscriptionData(final byte[] subscriberAddress, final TargetModeEnum targetMode, final Long subscriberUniqueId, Integer subscription) {
this.subscriberAddress = subscriberAddress;
this.targetMode = targetMode;
this.subscriberUniqueId = subscriberUniqueId;
this.subscription = subscription;
}
/**
* @return the subscriber node address
*/
public byte[] getSubscriberAddress() {
return subscriberAddress;
}
/**
* @return the uniqueId of the subscriber node
*/
public Long getSubscriberUniqueId() {
return subscriberUniqueId;
}
/**
* @return the targetMode
*/
public TargetModeEnum getTargetMode() {
return targetMode;
}
/**
* @return the subscription
*/
public Integer getSubscription() {
return subscription;
}
@Override
public boolean test(byte[] address) {
switch (targetMode) {
case BIDIB_TARGET_MODE_TOP:
case BIDIB_TARGET_MODE_ALL:
return this.subscriberAddress.equals(address);
case BIDIB_TARGET_MODE_ACCESSORY:
case BIDIB_TARGET_MODE_BOOSTER:
case BIDIB_TARGET_MODE_DCCGEN:
case BIDIB_TARGET_MODE_SWITCH:
// return NodeUtils.hasAccessoryFunctions(uniqueId);
return true;
case BIDIB_TARGET_MODE_UID:
default:
break;
}
return false;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(subscriberAddress);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
NodeSubscriptionData other = (NodeSubscriptionData) obj;
return Arrays.equals(subscriberAddress, other.subscriberAddress);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("AddressNodeData, address: ");
sb.append(NodeUtils.formatAddressLong(subscriberAddress));
sb.append(", uniqueId: ").append(ByteUtils.formatHexUniqueId(subscriberUniqueId));
return sb.toString();
}
}