001/**
002 *
003 * Copyright 2017 Paul Schaub
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.omemo.internal;
018
019import org.jxmpp.jid.BareJid;
020
021/**
022 * Class that combines a BareJid and a deviceId.
023 *
024 * @author Paul Schaub
025 */
026public class OmemoDevice {
027    private final BareJid jid;
028    private final int deviceId;
029
030    /**
031     * Create a new OmemoDevice.
032     *
033     * @param jid jid of the contact
034     * @param deviceId deviceId if the device.
035     */
036    public OmemoDevice(BareJid jid, int deviceId) {
037        this.jid = jid;
038        this.deviceId = deviceId;
039    }
040
041    /**
042     * Return the BareJid of the device owner.
043     *
044     * @return bareJid
045     */
046    public BareJid getJid() {
047        return this.jid;
048    }
049
050    /**
051     * Return the OMEMO device Id of the device.
052     *
053     * @return deviceId
054     */
055    public int getDeviceId() {
056        return this.deviceId;
057    }
058
059    @Override
060    public String toString() {
061        return jid.toString() + ":" + deviceId;
062    }
063
064    @Override
065    public boolean equals(Object other) {
066        return other instanceof OmemoDevice &&
067                ((OmemoDevice) other).getJid().equals(this.getJid()) &&
068                ((OmemoDevice) other).getDeviceId() == this.getDeviceId();
069    }
070
071    @Override
072    public int hashCode() {
073        Integer i;
074        i = jid.hashCode() + deviceId;
075        return i.hashCode();
076    }
077}