001    /** 
002     * 
003     * Copyright 2004 Protique Ltd
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     * 
017     **/
018    package org.activemq.service;
019    
020    import java.io.Serializable;
021    
022    /**
023     * Represents a message identity, either by using a unique
024     * message number, which is ordered and must not be zero or
025     * by specifying the String messageID.
026     * <p/>
027     * Typically a client accessing the MessageStore may have
028     * one or the other. Depending on which one is specified the
029     * other value may be filled in by operations on the MessageStore
030     *
031     * @version $Revision: 1.1.1.1 $
032     */
033    public class MessageIdentity implements Comparable, Serializable {
034        private static final long serialVersionUID = -5754338187296859149L;
035    
036        private String messageID;
037        private Object sequenceNumber;
038    
039        public MessageIdentity() {
040        }
041    
042        public MessageIdentity(String messageID) {
043            this.messageID = messageID;
044        }
045    
046        public MessageIdentity(String messageID, Object sequenceNumber) {
047            this.messageID = messageID;
048            this.sequenceNumber = sequenceNumber;
049        }
050    
051        public int hashCode() {
052            return messageID != null ? messageID.hashCode() ^ 0xcafebabe : -1;
053        }
054    
055        public boolean equals(Object that) {
056            return that instanceof MessageIdentity && equals((MessageIdentity) that);
057        }
058    
059        public boolean equals(MessageIdentity that) {
060            return messageID.equals(that.messageID);
061        }
062    
063        public int compareTo(Object object) {
064            if (this == object) {
065                return 0;
066            }
067            else {
068                if (object instanceof MessageIdentity) {
069                    MessageIdentity that = (MessageIdentity) object;
070                    return messageID.compareTo(that.messageID);
071                }
072                else {
073                    return -1;
074                }
075            }
076        }
077    
078        public String toString() {
079            return super.toString() + "[id=" + messageID + "; sequenceNo=" + sequenceNumber + "]";
080        }
081    
082        public String getMessageID() {
083            return messageID;
084        }
085    
086        public void setMessageID(String messageID) {
087            this.messageID = messageID;
088        }
089    
090        /**
091         * @return the sequence number which may be a number or some database specific type
092         */
093        public Object getSequenceNumber() {
094            return sequenceNumber;
095        }
096    
097        public void setSequenceNumber(Object sequenceNumber) {
098            this.sequenceNumber = sequenceNumber;
099        }
100    
101    }