Java tutorial
/* * 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 channellistmaker.dataextractor; import java.util.Objects; import org.apache.commons.collections4.keyvalue.MultiKey; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.apache.commons.lang.math.IntRange; /** * EPGDump?XML???????????(??ID)???????? * * @author dosdiaopfhj */ public final class KeyFields { /** * ??id */ private final String channelId; /** * ??? */ private static final IntRange ID_RANGE = new IntRange(0, 0xffff); /** * ? */ private final int transportStreamId; /** * ? */ private final int originalNetworkId; /** * */ private final int serviceId; /** * @param channelId ??ID * @param transportStreamId ? * @param originalNetworkId ? * @param serviceId * @throws IllegalArgumentException ??ID??????????ID??????16???2???????? */ public KeyFields(String channelId, int transportStreamId, int originalNetworkId, int serviceId) throws IllegalArgumentException { this.channelId = channelId; this.transportStreamId = transportStreamId; this.originalNetworkId = originalNetworkId; this.serviceId = serviceId; if (this.channelId == null || "".equals(this.channelId)) { throw new IllegalArgumentException("??ID????"); } String errorFieldName = null; ID_CHECK: { if (!ID_RANGE.containsInteger(this.transportStreamId)) { errorFieldName = "?"; break ID_CHECK; } if (!ID_RANGE.containsInteger(this.originalNetworkId)) { errorFieldName = "?"; break ID_CHECK; } if (!ID_RANGE.containsInteger(this.serviceId)) { errorFieldName = ""; break ID_CHECK; } } if (errorFieldName != null) { throw new IllegalArgumentException( "0x00xffff??????? = " + errorFieldName); } } /** * @return ??ID */ public final synchronized String getChannelId() { return channelId; } /** * @return ? */ public final synchronized int getTransportStreamId() { return transportStreamId; } /** * @return ? */ public final synchronized int getOriginalNetworkId() { return originalNetworkId; } /** * @return */ public final synchronized int getServiceId() { return serviceId; } /** * ??????Map???? * @see java.util.Map * @return ? */ public final synchronized MultiKey<Integer> getMuiltiKey() { return new MultiKey<>(this.getTransportStreamId(), this.getOriginalNetworkId(), this.getServiceId()); } @Override public int hashCode() { int hash = 3; hash = 11 * hash + Objects.hashCode(this.channelId); hash = 11 * hash + this.transportStreamId; hash = 11 * hash + this.originalNetworkId; hash = 11 * hash + this.serviceId; return hash; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final KeyFields other = (KeyFields) obj; if (this.transportStreamId != other.transportStreamId) { return false; } if (this.originalNetworkId != other.originalNetworkId) { return false; } if (this.serviceId != other.serviceId) { return false; } if (!Objects.equals(this.channelId, other.channelId)) { return false; } return true; } @Override public String toString() { return ReflectionToStringBuilder.toString(this); } }