epgtools.dumpepgfromts.dataextractor.KeyFields.java Source code

Java tutorial

Introduction

Here is the source code for epgtools.dumpepgfromts.dataextractor.KeyFields.java

Source

/*
 * Copyright (C) 2016 normal
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package epgtools.dumpepgfromts.dataextractor;

import static libepg.epg.section.range.SectionValueRangeChecker.TRANSPORT_STREAM_ID_RANGE;
import org.apache.commons.collections4.keyvalue.MultiKey;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
 * ??????????
 *
 * @author dosdiaopfhj
 */
public final class KeyFields {

    /**
     * ?
     */
    private final int transport_stream_id;

    /**
     * ?
     */
    private final int original_network_id;

    /**
     * 
     */
    private final int service_id;

    /**
     * @param transport_stream_id ? (16bit???
     * ????0x0000?0xffff??)
     * @param original_network_id ? (16bit???)
     * @param service_id  (16bit???)
     * @throws IllegalArgumentException
     *  ??????????
     */
    public KeyFields(int transport_stream_id, int original_network_id, int service_id)
            throws IllegalArgumentException {
        this.transport_stream_id = transport_stream_id;
        this.original_network_id = original_network_id;
        this.service_id = service_id;

        String errorFieldName = null;
        ID_CHECK: {
            if (!TRANSPORT_STREAM_ID_RANGE.contains(this.transport_stream_id)) {
                errorFieldName = "? = "
                        + Integer.toHexString(this.transport_stream_id);
                break ID_CHECK;
            }
            if (!TRANSPORT_STREAM_ID_RANGE.contains(this.original_network_id)) {
                errorFieldName = "? = "
                        + Integer.toHexString(this.original_network_id);
                break ID_CHECK;
            }
            if (!TRANSPORT_STREAM_ID_RANGE.contains(this.service_id)) {
                errorFieldName = " = " + Integer.toHexString(this.service_id);
                break ID_CHECK;
            }
        }
        if (errorFieldName != null) {
            throw new IllegalArgumentException(
                    "??????? = " + errorFieldName);
        }
    }

    public final int getTransport_stream_id() {
        return transport_stream_id;
    }

    public final int getOriginal_network_id() {
        return original_network_id;
    }

    public final int getService_id() {
        return service_id;
    }

    /**
     * ??????Map????
     *
     * @see java.util.Map
     * @return ?
     */
    public final MultiKey<Integer> getMuiltiKey() {
        return new MultiKey<>(this.getTransport_stream_id(), this.getOriginal_network_id(), this.getService_id());
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(3, 11, this);
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj, true);
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this);
    }

}