All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.zankowski.iextrading4j.hist.api.message.administrative.IEXOperationalHaltStatusMessage Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package pl.zankowski.iextrading4j.hist.api.message.administrative;

import pl.zankowski.iextrading4j.hist.api.IEXMessageType;
import pl.zankowski.iextrading4j.hist.api.message.IEXMessage;
import pl.zankowski.iextrading4j.hist.api.message.administrative.field.IEXOperationalHaltStatus;
import pl.zankowski.iextrading4j.hist.api.util.IEXByteConverter;

import java.util.Arrays;
import java.util.Objects;

public class IEXOperationalHaltStatusMessage extends IEXMessage {

    private final IEXOperationalHaltStatus operationalHaltStatus;
    private final long timestamp;
    private final String symbol;

    private IEXOperationalHaltStatusMessage(
            final IEXMessageType messageType,
            final IEXOperationalHaltStatus operationalHaltStatus,
            final long timestamp,
            final String symbol) {
        super(messageType);
        this.operationalHaltStatus = operationalHaltStatus;
        this.timestamp = timestamp;
        this.symbol = symbol;
    }

    public static IEXMessage createIEXMessage(IEXMessageType messageType, byte[] bytes) {
        final IEXOperationalHaltStatus operationalHaltStatus = IEXOperationalHaltStatus.getOperationalHaltStatus(bytes[1]);
        final long timestamp = IEXByteConverter.convertBytesToLong(Arrays.copyOfRange(bytes, 2, 10));
        final String symbol = IEXByteConverter.convertBytesToString(Arrays.copyOfRange(bytes, 10, 18));

        return new IEXOperationalHaltStatusMessage(messageType, operationalHaltStatus, timestamp, symbol);
    }

    public IEXOperationalHaltStatus getOperationalHaltStatus() {
        return operationalHaltStatus;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public String getSymbol() {
        return symbol;
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        final IEXOperationalHaltStatusMessage that = (IEXOperationalHaltStatusMessage) o;
        return timestamp == that.timestamp &&
                operationalHaltStatus == that.operationalHaltStatus &&
                Objects.equals(symbol, that.symbol);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), operationalHaltStatus, timestamp, symbol);
    }

    @Override
    public String toString() {
        return "IEXOperationalHaltStatusMessage{" +
                "operationalHaltStatus=" + operationalHaltStatus +
                ", timestamp=" + timestamp +
                ", symbol='" + symbol + '\'' +
                "} " + super.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy